Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Distinct keys [26, 13, 5, 17, 19, 4] are inserted, in the order given by the sequence [19, 13, 4, 5, 17, 26], into an empty binary search tree. How many of the permutations of these same keys, when inserted in that order into an empty BST, produce exactly the same tree (same keys in the same positions)?
- A. 720
- B. 132
- C. 120
- D. 15
Correct answer: D. 15
Every order giving the same tree must start with the root and follow the same nesting, and there are exactly 15 of them. The total n! or the count matching only the shape are different quantities.
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
- Undirected simple graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–F (1), B–D (1), B–E (1), D–E (1), E–F (1) (weights…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–D (4), A–E (4), B–C (4), B–D (1), B–E (3), D–E (2)…
- Tree with vertices 0 to 9, root 0, edges 0–1, 0–2, 2–3, 1–4, 3–5, 4–6, 5–7, 4–8, 8–9 (parent–child). Vertex weights (vertex:weight) 0:18…
- Keys [19, 23, 15, 12, 48, 41] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right, left–right…
- A binary tree with distinct letters has preorder FECBDGA and inorder CDGBEAF. What is its postorder traversal (left, right, root), written…
- Directed weighted graph on vertices A, B, C, D with edges D→C (-4); A→B (-1); D→B (6); C→B (2); A→D (-2); D→A (5); C→A (-2); B→A (6)…