1.

What is the maximum height of an AVL tree with p nodes?(a) p(b) log(p)(c) log(p)/2(d) ^p⁄2Origin of the question is AVL Tree topic in chapter Binary Trees of Data Structures & Algorithms IThis question was posed to me in an interview.

Answer»

Right option is (B) log(P)

Easy explanation - Consider height of TREE to be ‘he’, then number of nodes which TOTALS to p can be WRITTEN in terms of height as N(he)=N(he-1)+1+N(he-2). since N(he) which is p can be written in terms of height as the beside recurrence relation which on solving gives N(he)= O(logp) as worst case height.



Discussion

No Comment Found

Related InterviewSolutions