Data Structures & AlgorithmsHardProduct-company MCQ pattern
What is the maximum possible height of an AVL tree with 20 nodes (a single node has height 0)?
- A. 6
- B. 5
- C. 19
- D. 4
Correct answer: B. 5
The fewest nodes for height h are N(h) = N(h − 1) + N(h − 2) + 1: 1, 2, 4, 7, 12, 20, 33. Since N(5) = 20 ≤ 20 < N(6) = 33, the maximum height is 5. ⌊log₂ 20⌋ = 4 is the minimum height, not the maximum.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- The words car, cart, care, cat, dog are inserted into an empty trie (one node per character, shared prefixes share nodes). How many nodes…
- How many calls in total (including the first) does C(5, 2) make? c int C(int n, int k) { if (k == 0 || k == n) return 1; return C(n - 1, k…
- For n = 6, how many disk moves does this Tower of Hanoi function count, and how many calls of hanoi are made in total? c int hanoi(int n…
- A robot moves only right or down on a 3 × 4 grid of cells (3 rows, 4 columns) from the top-left cell to the bottom-right cell. The cell in…
- What is the length of the longest palindromic SUBSEQUENCE of CHARACTER?
- Coins of 1, 5, 6 and 8 are available in unlimited supply. For amount 11, how many coins does the 'largest coin first' greedy method use…