GATE Computer ScienceHardGATE CS (PYQ pattern)
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 having two children by its inorder successor. What is the preorder traversal of the resulting tree?
- A. 50 30 15 10 20 35 40 75 55 60
- B. 15 10 35 20 30 55 40 50 75 60
- C. 40 20 15 10 35 30 60 55 50 75
- D. 60 55 75 40 35 20 10 15 30 50
Correct answer: A. 50 30 15 10 20 35 40 75 55 60
Deleting 25 pulls up 30, deleting 45 pulls up 50, deleting 65 pulls up 75. Using the predecessor, or rebuilding from the remaining keys, gives different shapes.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- A complete binary tree (every level full except possibly the last, which is filled from the left) has exactly 300 leaves. Which node…