*@all to median of BST time O(n) space O(1) (modified code of nitin to
get median)


medianBST*(node, n)
  int x = 0;
  *while* hasleftchild(node) *do*
    node = node.left
  *do*

    x++;
    if (x == n/2) return node->val;
    *if* (hasrightchild(node)) *then*
      node = node.right
      *while* hasleftchild(node) *do*
        node = node.left
    *else*

      *while* node.parent ≠ *null* *and* node == node.parent.right *do*
        node = node.parent
      node = node.parent
  *while* node ≠ *null*


@dheeraj u

U  can get the number of elements by just traversing the who tree by above
method

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to