Discussion
Assuming that the height of a tree with a single node is 0, the maximum height of any AVL-tree with 7 nodes is
Answer: C
The maximum height is 3.
The tallest AVL tree with a given number of nodes is the sparsest one, in which the two subtrees of every node differ in height by exactly one. The minimum number of nodes \(N(h)\) in an AVL tree of height \(h\) is
\[ \begin{aligned} N(h) &= N(h-1) + N(h-2) + 1 \\ N(0) = 1,\ N(1) &= 2,\ N(2) = 4 \\ N(3) &= 7,\ N(4) = 12 \end{aligned} \]
A height of 4 needs at least 12 nodes, so 7 nodes can reach height 3 but not 4. Heights 4 and 5 are impossible with 7 nodes, and 2 is not the maximum.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development