GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Keys 50, 30, 70, 20, 40, 60, 80 are inserted in this order into an empty binary search tree. How many of the 7! insertion orders of these keys produce exactly the same tree?
- A. 48
- B. 80
- C. 120
- D. 720
Correct answer: B. 80
The root 50 must come first. The left subtree {30, 20, 40} needs 30 before 20 and 40: 2 valid orders; the right subtree likewise 2. Interleaving the 3 left keys and 3 right keys: C(6, 3) = 20. Total 20·2·2 = 80 (brute force over all permutations agrees).
More Algorithms questions
- Floyd's cycle-finding is applied to the sequence x₀ = 2, x{i+1} = (xi² + 1) mod 55. How many distinct values does the sequence take?
- Bellman–Ford is run from A on the directed graph A→B 4, A→C 2, C→B 1, B→D 5, C→D 8, D→E 3, C→E 10, E→F −2, D→F 6. In each pass the edges…
- Assume P ≠ NP. Which of the following problems have a polynomial-time algorithm? I. 2-SAT. II. 3-colourability of a graph. III. Maximum…
- A polynomial-time many-one reduction from problem A to problem B is given (A ≤ₚ B). Which statements must be true? I. If B ∈ P then A ∈ P…
- Median-of-medians selection with groups of 7 satisfies T(n) ≤ T(n/7) + T(5n/7) + cn (ignore floors). Guessing T(n) ≤ an, what is the…
- Consider T(n) = 2T(n/2) + n/log₂²n for powers of 2, T(1) = 1. Which is the tight asymptotic bound?