Data Structures & AlgorithmsHardGATE CS · Product-company placement
Keys 54, 17, 39, 66, 11, 36, 83, 51, 94, 10, 76 are inserted in that order into an empty BST. Then 39 is deleted and after that 83 is deleted; a node with two children is replaced by its inorder SUCCESSOR (the successor node is then removed from the right subtree). What is the preorder traversal of the final tree?
- A. 54, 17, 11, 10, 36, 51, 66, 76, 94
- B. 54, 17, 11, 10, 36, 51, 66, 94, 76
- C. 54, 17, 11, 10, 51, 36, 66, 94, 76
- D. 54, 17, 11, 10, 51, 36, 66, 76, 94
Correct answer: C. 54, 17, 11, 10, 51, 36, 66, 94, 76
Each deletion of a two-child node copies the smallest key of its right subtree into it and removes that key below, giving preorder 54, 17, 11, 10, 51, 36, 66, 94, 76. Using the predecessor, or rebuilding the tree from the remaining keys in insertion order, gives a different shape.
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
- Prim's algorithm starts at E on the weighted undirected graph A–C (13), A–D (1), A–G (11), B–D (16), B–G (6), C–D (14), C–E (18), C–F…
- Keys 53, 59, 94, 71, 34, 76, 82, 15, 62, 24 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- With 2 identical eggs and at most 6 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- How many subsets of {1, 3, 4, 5, 8, 10, 13} have sum exactly 20?
- Five matrices have dimensions 12×5 , 5×12 , 12×10 , 10×3 , 3×5. What is the minimum number of scalar multiplications needed to compute…
- A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 8, 10, 13, 21, 22, 25, 28. What is…