GATE Computer ScienceVery hardGATE CS (PYQ pattern)
A BST is built by inserting 50, 30, 70, 20, 40, 60, 80 in some order into an initially empty tree. The final tree is the perfectly balanced 3-level tree. How many of the 7! insertion orders produce exactly this tree?
- A. 160
- B. 210
- C. 720
- D. 80
Correct answer: D. 80
The root must come first. After that, the left subtree's 3 keys and the right subtree's 3 keys can interleave in C(6,3) = 20 ways, and in each subtree the middle key must precede its children (2 ways each): 20 * 2 * 2 = 80.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Insert 45, 25, 65, 15, 35, 55, 75, 10, 20, 30, 40, 50, 60 into an empty BST. Then delete 25, 45 and 65 in that order, replacing a node…
- A full binary tree (every node has 0 or 2 children) has preorder 1 2 4 5 8 9 3 6 10 11 7 and postorder 4 8 9 5 2 10 11 6 7 3 1. What are…
- Binary trees (unlabelled, left and right children distinguished) with exactly 6 nodes: how many have height exactly 3 (a single node has…
- Height is counted in edges (a single node has height 0). What is the maximum possible height of an AVL tree with 50 nodes, and what is the…
- How many distinct binary trees (left and right children are distinguished) on nodes 1..5 have preorder 1 2 3 4 5 and postorder 5 4 3 2 1?
- Among all binary trees (left and right children distinguished) with 6 nodes whose preorder traversal is 1 2 3 4 5 6, how many have an…