GATE Computer ScienceHardGATE CS (PYQ pattern)
Height is counted in edges (a single node has height 0). What is the maximum possible height of an AVL tree with 50 nodes, and what is the minimum number of nodes in an AVL tree of height 7 whose root has balance factor 0?
- A. 7 and 67
- B. 6 and 54
- C. 5 and 67
- D. 6 and 67
Correct answer: D. 6 and 67
The sparsest AVL trees satisfy N(h) = N(h-1) + N(h-2) + 1 with N(0) = 1, N(1) = 2: 1, 2, 4, 7, 12, 20, 33, 54, ... N(6) = 33 <= 50 < N(7) = 54, so the height is at most 6. A root with balance 0 and height 7 needs two subtrees of height 6, each with at least 33 nodes: 33 + 33 + 1 = 67, more than the 54 of the sparsest height-7 tree.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many distinct binary trees (left and right children are distinguished) on nodes 1..5 have preorder 1 2 3 4 5 and postorder 5 4 3 2 1?
- Among all binary trees (left and right children distinguished) with 6 nodes whose preorder traversal is 1 2 3 4 5 6, how many have an…
- A complete binary tree (every level full except possibly the last, which is filled from the left) has exactly 300 leaves. Which node…
- A rooted tree has 6 nodes with 2 children, 5 nodes with 3 children and 4 nodes with 4 children; every other node is a leaf. How many nodes…
- How many structurally different binary search trees can be built on the keys 1..7 such that the height is at most 3 (a single node has…
- Among all 429 structurally different binary search trees on the keys 1 to 7, in how many is key 3 a leaf?