1.

What is the average case time complexity for finding the height of the binary tree?(a) h = O(loglogn)(b) h = O(nlogn)(c) h = O(n)(d) h = O(log n)My question is based upon Binary Tree Properties topic in chapter Binary Trees of Data Structures & Algorithms II have been asked this question at a job interview.

Answer» RIGHT answer is (d) H = O(log n)

The explanation is: The nodes are EITHER a part of left sub tree or the right sub tree, so we don’t have to traverse all the nodes, this MEANS the complexity is lesser than n, in the average case, assuming the nodes are SPREAD evenly, the time complexity becomes O(logn).


Discussion

No Comment Found

Related InterviewSolutions