Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
How many of the 7! insertion orders of the keys 1–7 produce the perfectly balanced BST with root 4, children 2 and 6, and leaves 1, 3, 5, 7?
- A. 16
- B. 1
- C. 80
- D. 48
Correct answer: C. 80
4 must come first. The 6 remaining keys split into {1, 2, 3} and {5, 6, 7}; their relative interleaving can be anything: C(6, 3) = 20. Within each side, the subtree root (2 or 6) must come first and its two children in either order: 2 × 2. Total 20 × 4 = 80.
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
- A binary tree has inorder 9 5 1 7 2 12 8 4 3 11 and postorder 9 1 2 12 7 5 3 11 4 8. What is its preorder?
- Keys 1, 2, 3, 4, 5, 6, 7 are inserted in that order into an empty AVL tree. How many rotations (counting a double rotation as one…
- What is the maximum possible height of an AVL tree with 20 nodes (a single node has height 0)?
- 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…