Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
Keys 87, 36, 57, 23, 95, 88, 77 inserted in this order build a BST. How many of the 7! orderings of these same 7 keys, inserted into an empty BST, produce exactly the same tree?
- A. 15
- B. 45
- C. 3
- D. 90
Correct answer: B. 45
A node must come before every key in its subtree, but its two subtrees may interleave freely: count = C(n−1, |left|) × count(left) × count(right) = 45, which also equals n!/∏(subtree sizes).
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
- DFS runs on the directed graph with adjacency lists A: EF; B: A; C: A; D: AE; E: BCF; F: G; G: B, starting at A, scanning lists in the…
- A B-tree has minimum degree t = 4 (every non-root node has between 3 and 7 keys) and height 3 (a root-only tree has height 0). What are…
- In how many different ways can 'abcdabcd' be split into a sequence of words from the dictionary {a, ab, abc, bcd, cd, d, abcd} (every…
- Six sorted files have 14, 31, 34, 35, 36, 58 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- An undirected connected graph has edges A–D, A–G, B–E, C–E, C–G, D–H, D–I, F–I, G–H. How many articulation points (cut vertices) and how…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: C→D (1), A→F (8), F→C (3), D→A…