public double find(BinaryNode<Integer> root) {
    if (root == null) {
      throw new IllegalArgumentException("You can't pass a null binary tree to this method.");
    }

    List<BinaryNode<Integer>> sortedElements = binaryTreeInOrder.getIterative(root);
    double median = 0;
    if (sortedElements.size() % 2 == 0) {
      median = (sortedElements.get(sortedElements.size() / 2).getData() + sortedElements.get(
          sortedElements.size() / 2 - 1).getData()) / 2;
    } else {
      median = sortedElements.get(sortedElements.size() / 2).getData();
    }
    return median;
  }
Iterative algorithm used to find the median of an AVL. This algorithm is based on a property
of every AVL tree, you can get a sorted collection containing the elements of this tree using
an in order traversal. Using this property we can get a sorted collection of nodes and then
find the median. The complexity order of this algorithm is O(N) in time and space terms where
N
is the number of nodes in the tree.
src/main/java/com/github/pedrovgs/problem36/AvlTreeMedian.java