GATE Computer ScienceVery hardGATE CSE
Keys 1..7 are inserted into an initially empty BST (no balancing) in some order. For how many of the 7! insertion orders does the resulting tree have height 2 (a perfect tree)?
- A. 160
- B. 40
- C. 70
- D. 80
Correct answer: D. 80
The first key must be 4; then 2 must precede 1 and 3, and 6 must precede 5 and 7: 6!/(3·3) = 80.
More Algorithms questions
- Keys 1..8 are inserted into an empty BST in each of the 8! possible orders. In how many orders is the resulting tree a single path (height…
- For X = "ABCBDAB" and Y = "BDCABA", how many DISTINCT strings are longest common subsequences of X and Y?
- An undirected weighted graph on vertices 0..6 has edges, written (u, v, weight): (0,1,2), (0,2,2), (1,2,2), (1,3,3), (2,3,3), (3,4,1)…
- A directed graph has edges S→A (4), S→B (2), B→A (−3), A→C (2), B→D (3), D→C (−5). Dijkstra's algorithm is run from S: each extracted…
- Lomuto partition (pivot = last element, i starts at −1, for each j with A[j] ≤ pivot do i++ and swap A[i], A[j]; finally swap A[i+1] with…
- A max-heap is built from the array [3, 9, 2, 1, 4, 5, 8, 7, 6, 10] using the bottom-up procedure (sift-down from index ⌊n/2⌋−1 to 0…