The worst case running time to search for an element in a balanced in a binary search tree with n2^n elements is
(A) (B) (C) (D)
-> 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.
This solution is contributed by Nirmal Bharadwaj
Quiz of this Question