Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Keys are inserted in the order 88 50 42 89 48 68 into an empty binary search tree. Then the key 88 (which has two children) is deleted by replacing it with its INORDER SUCCESSOR, and the successor node is removed from the right subtree. What is the preorder traversal (root, left, right) of the tree afterwards? Give the keys separated by spaces.
- A. 89 50 42 48 68 89
- B. 89 50 42 48 68
- C. 68 50 42 48 89
- D. 88 50 42 48 68 89
Correct answer: B. 89 50 42 48 68
The successor (smallest key of the right subtree) replaces 88, so the preorder becomes 89 50 42 48 68. Using the predecessor instead gives a different shape, and forgetting to remove the successor node leaves a duplicate.
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 tree with distinct letters has preorder DEFACB and inorder FAECDB. What is its postorder traversal (left, right, root), written…
- Dictionary D = {ada, ats, emd, lsc, pcd, pmd, pmo, pno, pnr, rbs, sbp, ssr} (all words have 3 letters). Starting from the word 'ptd', a…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Array A = [29, 1, 24, 26, 13, 6, 8] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: A→D (7); C→E (0); D→B (2); F→A (2); C→D (5)…
- Keys are inserted in the order 56 88 11 17 79 25 68 into an empty binary search tree. Then the key 56 (which has two children) is deleted…