Data Structures & AlgorithmsHardProduct-company MCQ pattern
What is the minimum number of nodes in an AVL tree of height 4 (a single node has height 0)?
- A. 31
- B. 7
- C. 12
- D. 15
Correct answer: C. 12
N(h) = N(h − 1) + N(h − 2) + 1 with N(0) = 1, N(1) = 2: N(2) = 4, N(3) = 7, N(4) = 12. 31 is the maximum (a perfect tree), and 7 is N(3).
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
- How many different spanning trees does the complete graph K₄ have?
- How many times in total is fib called (including the first call) when fib(6) is evaluated? c int fib(int n) { if (n <= 1) return n; return…
- What does fun(3) print? c void fun(int n) { if (n > 0) { fun(n - 1); printf("%d ", n); fun(n - 1); } }
- What are the time complexities of versions P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2) + n; } int Q(int n) { if…
- What is the time complexity of solve(n)? python def solve(n): if n <= 0: return for i in range(n): pass # O(1) work solve(n - 1)
- How many of these statements are correct? (i) Dijkstra's algorithm with a binary heap runs in O((V + E) log V). (ii) Bellman–Ford runs in…