Data Structures & AlgorithmsHardProduct-company MCQ pattern
How many different max-heaps (as arrays) can be formed from 5 distinct keys?
- A. 8
- B. 16
- C. 6
- D. 120
Correct answer: A. 8
The largest key is the root. The left subtree has 3 nodes (indices 1, 3, 4), the right has 1. Choose which 3 of the remaining 4 keys go left: C(4, 3) = 4; the left sub-heap's root is forced and its 2 children can be ordered 2 ways: 4 × 2 = 8 (brute force over 120 arrays agrees).
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
- Keys 50, 30, 70, 20, 40, 60, 80, 65 are inserted into an empty BST, then 50 is deleted by replacing it with its inorder SUCCESSOR. What is…
- 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 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…