GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Use minimum AVL size recurrence

3 questions solved the same way, newest first. Back to Data Structures

How these are solved

Use N(h)=1+N(h-1)+N(h-2) with explicit edge/node height base cases; evaluate minimum nodes or invert for maximum permitted height. Derivation, numeric evaluation and inverse question are distinct tasks.

2 marks · MCQ
Report issue

Maximum AVL height with seven nodes

Binary Search & Balanced Trees

Question 37, GATE 2009: Maximum edge-height of an AVL tree with 7 nodes, with singleton height 0? A 2; B 3; C 4; D 5.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

The minimum-node recurrence for edge height h is N(h)=1+N(h−1)+N(h−2), with N(−1)=0, N(0)=1. Hence N(1)=2, N(2)=4, N(3)=7, N(4)=12. Seven nodes attain height 3 but cannot reach 4, so B.

To make an AVL tree as tall as possible with few nodes, give its two subtrees heights h−1 and h−2. Thus the minimum nodes at height h obey N(h)=1+N(h−1)+N(h−2). Starting with empty height−1 and singleton 0 gives 0, 1, 2, 4, 7, 12. Seven nodes suffice exactly for height 3, but any height 4 tree needs at least 12. This proves both attainability and impossibility, so B.

Original paper, page 9

Descriptive
Report issue

Minimum AVL recurrence

Binary Search & Balanced Trees

Question 21(a), GATE 1998: Derive the minimum number N(h) of nodes in an AVL tree of height h. State the height convention.
Question 21(a), GATE 1998: Derive the minimum number N(h) of nodes in an AVL tree of height h. State the height convention.
Tap to enlarge
Answer & solution

Answer: N(h)=1+N(h−1)+N(h−2); edge-height bases N(−1)=0,N(0)=1. (no official key was published)

Take height to count edges on a longest root-to-leaf path; an empty tree has height −1 and a leaf height 0. A tree of height h must have at least one child subtree of height h−1. AVL balance permits the other to be no shorter than h−2. To minimize nodes, choose exactly those two heights and make both subtrees themselves minimum-size AVL trees. Counting the root gives N(h)=1+N(h−1)+N(h−2), with N(−1)=0,N(0)=1.

This is both a lower bound and attainable: recursively attach extremal subtrees of heights h−1 and h−2 to a root. The height difference is one, so the construction is AVL. Writing M(h)=N(h)+1 gives M(h)=M(h−1)+M(h−2), and the bases imply N(h)=Fh+3−1 when F0=0,F1=1.

If height instead counts levels, the empty tree is height 0 and a leaf height 1, so the same recurrence has bases N(0)=0,N(1)=1 and formula Fh+2−1. The recurrence is structural; the indexing convention must not be mixed between parts.

Original paper, page 8

Descriptive
Report issue

Minimum AVL height eight

Binary Search & Balanced Trees

Question 21(b), GATE 1998: Find the smallest AVL tree size for height 8.
Question 21(b), GATE 1998: Find the smallest AVL tree size for height 8.
Tap to enlarge
Answer & solution

Answer: 88 nodes for edge height; 54 for level height. (no official key was published)

Using the edge-height convention from part (a), start N(−1)=0,N(0)=1 and apply N(h)=1+N(h−1)+N(h−2). The values at heights 1 through 8 are 2,4,7,12,20,33,54,88. Thus the smallest tree at edge height 8 has 88 nodes. Equivalently, F11−1=89−1=88.

If the source's unstated height convention counts levels, the same physical tree's level height is one larger. A level-height-8 minimum tree therefore has edge height 7 and 54 nodes. This is not a disagreement in AVL structure, only an indexing ambiguity. Specify the convention rather than asserting both numbers describe the same notion of height. The printed empty '(c)' after this question contains no task text and is not invented as another solution item.

Original paper, page 8