AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: Ashish — May 7, 2008
    -4 votes
      + -

    isn’t it same problem as finding the kth largest element in a given list whereby we make a BST with every node keeping count of # of lements in its left subtree.

  2. Submitted By: J1gs4w — June 1, 2008
    +0 votes
      + -

    Find the no. of elements on the left side.
    If it is n-1 the root is the median.
    If it is more than n-1, then it has already been found in the left subtree.
    Else it should be in the right subtree.

    initialize med to -1 and call as
    findMed(root, n/2, &med); //assume n is known

    int findMed(node*root, int n, int* med)
    {
    if(!root || nleft, n, med);
    if(m>=n)
    {
    return INF; //found
    }

    if(m==n-1)
    {
    *med=*root;
    return INF;
    }

    p=findMed(root->right, n-m-1, med);
    if(p+m+1>=n) return INF; //found
    }

    regards,
    J1gs4w

  3. Submitted By: Sunny arora — June 7, 2008
    +5 votes
      + -

    I think first we need to find the number of elements in the BST by any traversal technique.then using the inoder traversal go to nth/2 ele,ent that will be the median

  4. Submitted By: Jibitesh — September 30, 2008
    +1 votes
      + -

    The answer by jigsaw wont work for unbalanced BST

  5. Submitted By: Michael Peng — October 7, 2008
    +12 votes
      + -

    Execute two InOrder traversal, the first one runs as the double speed the second one. It means the first one visits two nodes while the second one visits one nodes.

    So when the first one finish traverse, the second one point the mid value!

  6. Submitted By: yuyu — October 8, 2008
    +0 votes
      + -

    Start two inorder traverse, one to the left, one to the right, at the same pace, until they meet.

  7. Submitted By: cindy — November 20, 2008
    -1 votes
      + -

    the solution by yuyu does not seem to work. how can they ever meet if one is on left and one is on right??

  8. Submitted By: adi — April 9, 2009
    +1 votes
      + -

    I suppose yuyu meant traversal in a descending order.. (Right-Node-Left).

  9. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.