Open In App

GATE | GATE CS 2012 | Question 5

Like Article
Like
Save Article
Save
Share
Report issue
Report
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

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads