GATE CSE
First time here? Checkout the FAQ!
x
0 votes
390 views
Suppose we do not have a parent pointer in the nodes of a search tree, only left-child and right-child. Which of the following operations can be computed in time $O(\log n)$ for a balanced search tree?

1- find, insert, delete, but not min, max, pred, succ
2- find, insert, delete, min, max, but not pred, succ
3- find, insert, delete, pred, succ but not min, max
4- All of find, insert, delete, min, max, pred, succ
asked in Algorithms by Veteran (47k points)   | 390 views

3 Answers

+4 votes
Best answer
Balanced search tree so height is O(logn) having n elements.

min and max is easy to find...

For min just start with root and traverse left until u don't get null ... When u get null that is min element..O(logn)

Same for max traverse Right until you get null that is max element.O(logn)

Insert , delete and find too take O(log).

Now for predecessor : suppose key is given then jump to the left child of key and find the descendent right node that is predecessor of given key..which takes O(logn)

Successor : jump to the right child and find left descendent of it that is successor of given key. Which also takes O(log) time.

So ans should be D.
answered by Veteran (22.7k points)  
selected by
If you are talking about predecessor and successor in the sequence of resulting inorder traversal, then answer is OK :) :).
but how " Suppose we do not have a parent pointer in the nodes " maintaining?
By default, a child doesn't have pointer to parent. So, its simple Balanced BST. confirm me?
0 votes
Say tree is Binary search tree. Here we donot have parent pointer. So, to find a node we have to do by level order traversal.  Binary search tree can be visited in O(log N) time when we visit a node from root to leaf. But in level order traversal we have to visit all nodes So, it will take O(N) time.

Now, in worst case ,if the tree is skewed tree and for min, max we take O(N) and O(1) time . To find predecessor , successor also takes O(N) time
answered by Veteran (53.8k points)  
questions ask about the balanced search tree.
0 votes
Ans:D
answered by (13 points)  
answer should be (D)


Top Users May 2017
  1. akash.dinkar12

    3338 Points

  2. pawan kumarln

    2108 Points

  3. Bikram

    1922 Points

  4. sh!va

    1682 Points

  5. Arjun

    1614 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1208 Points

  8. Angkit

    1056 Points

  9. LeenSharma

    1018 Points

  10. Arnab Bhadra

    812 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    1008 Points

  2. pawan kumarln

    734 Points

  3. Arnab Bhadra

    726 Points

  4. Arjun

    342 Points

  5. bharti

    328 Points


22,893 questions
29,196 answers
65,302 comments
27,695 users