Open In App
Related Articles

GATE | GATE CS 2012 | Question 5

Improve Article
Save Article
Like Article

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)


-> 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

Level Up Your GATE Prep!
Embark on a transformative journey towards GATE success by choosing Data Science & AI as your second paper choice with our specialized course. If you find yourself lost in the vast landscape of the GATE syllabus, our program is the compass you need.

Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads