+1 vote
in Data Structures & Algorithms I by (110k points)
What is the maximum height of an AVL tree with p nodes?

(a) p

(b) log(p)

(c) log(p)/2

(d) ^p⁄2

Origin of the question is AVL Tree topic in chapter Binary Trees of Data Structures & Algorithms I

This question was posed to me in an interview.

1 Answer

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

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.