+1 vote
in Data Structures & Algorithms I by (110k points)
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 I

I have been asked this question at a job interview.

1 Answer

+1 vote
by (672k points)
selected by
Best 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).

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.