Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
Keys 90, 94, 89, 30, 62, 17, 99, 53 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into an empty BST, produce exactly the same tree?
- A. 21
- B. 63
- C. 3
- D. 126
Correct answer: B. 63
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) = 63, 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
- A binary search tree holds exactly the keys 13, 19, 20, 36, 71, 73, 94, 99. Which ONE of the following sequences can be its PREORDER…
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 44?
- A rooted tree has these parent→child edges: 56→8, 64→56, 64→24, 64→45, 24→59, 45→41, 8→2. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 74→13, 74→24, 84→62, 13→75, 13→66, 24→84. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 72→45, 31→27, 98→31, 27→38, 31→72, 98→71. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 74→62, 21→36, 65→79, 62→71, 36→78, 65→76, 71→99, 74→65, 74→21. A depth-first search starts at…