GATE Computer ScienceVery hardGATE CSE · UGC NET
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 7)?
- A. 128
- B. 64
- C. 256
- D. 56
Correct answer: A. 128
Each key after the first must be the minimum or the maximum of the keys not yet inserted: 2^7 = 128.
More Algorithms questions
- 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…
- A hash table of size 11 uses double hashing with h1(k) = k mod 11 and h2(k) = 7 − (k mod 7), probing slot (h1 + i·h2) mod 11 for i = 0, 1…