title: printing largest n values in binary search tree
body: <p>I am trying to create a method to print out the largest n values in a binary search tree. I was considering altering a reverse order print method to achieve this.</p>
  
  <p>reverse order print method:</p>
  
  <pre><code>public static void reverseOrderPrint(TreeNode node) {
      if (node == null) return;
      reverseOrderPrint(node.right);
      System.out.println(node.data);
      reverseOrderPrint(node.right);
  }
  </code></pre>
  
  <p>I wanted to modify the method above to something like this to achieve my goals</p>
  
  <pre><code>// print BST reverse Order
  public static void reverseOrder(TreeNode node, int n) {
      if (sizeOfBinaryTree(node) &lt; n) {
          System.out.print("n is bigger than tree");
          return;
      }
      if (node == null) return;
      reverseOrder(node.right);
      System.out.print(node.data);
      reverseOrder(node.left);
  }
  </code></pre>
  
  <p>I have considered storing the reverse order elements in an array and then returning the first n values but this would have a performance of O(n) and require extra memory. How can I perform the same task recursively without requiring extra memory? Also is this possible to complete this problem in O(log n)? or does it have to be O(n)? </p>