GATE Computer ScienceVery hardGATE CSE · NIELIT
Keys 1–7 are inserted into an empty BST in the order 4, 2, 6, 1, 3, 5, 7, giving a perfectly balanced tree. How many of the 5040 insertion orders of 1–7 produce exactly this same tree?
- A. 64
- B. 80
- C. 40
- D. 120
Correct answer: B. 80
The root must be first and the two subtrees' insertions interleave arbitrarily: C(6,3) × 2 × 2 = 80.
More Algorithms questions
- The KMP prefix (failure) function π[i] is the length of the longest proper prefix of P[0..i] that is also a suffix of it. For P =…
- Rabin–Karp searches for the digit pattern 26 in the text 3141592653589793, treating each 2-digit window as a decimal number reduced modulo…
- Jobs given as (start, finish, profit): (1,4,5), (3,5,1), (0,6,8), (4,7,4), (3,9,6), (5,9,3), (6,10,2), (8,11,4). A job may start exactly…
- A graph on vertices 0–5 has edges (0,1,1), (1,2,1), (0,2,1), (2,3,2), (1,3,2), (3,4,3), (2,4,3), (4,5,1). How many distinct minimum…
- How many inversions (pairs i<j with A[i]>A[j]) does the array [7, 3, 9, 1, 5, 8, 2] contain?
- Characters with frequencies 5, 9, 12, 13, 16, 45 are Huffman-coded. What is the total number of bits needed to encode the whole text (sum…