GATE | GATE CS 2012 | Question 5

The worst case running time to search for an element in a balanced in a binary search tree with n2^n elements is

(A) \Theta(n log n)

(B) \Theta (n2^n) 

(C) \Theta (n) 

(D) \Theta (log n)  

(A) A
(B) B
(C) C
(D) D


Answer: (C)

Explanation:

-> The search time in a binary search tree depends on the form of the tree, that is on the order in which its nodes were inserted. A pathological case: The n nodes were inserted by increasing order of the keys, yielding something like a linear list (but with a worse space consumption), with O(n) search time(in the case of skew tree).



-> A balanced tree is a tree where every leaf is “not more than a certain distance” away from the root than any other leaf.So in balanced tree, the height of the tree is balanced to make distance between root and leafs nodes a low as possible. In a balanced tree, the height of tree is log2(n).

-> So , if a Balanced Binary Search Tree contains n2n elements then Time complexity to search an item:

Time Complexity = log(n2n) = log (n) + log(2n)
= log (n) +n = O(n)

So Answer is C.

See https://www.geeksforgeeks.org/data-structures-and-algorithms-set-28/

This solution is contributed by Nirmal Bharadwaj

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.