Data Structures & AlgorithmsHardProduct-company MCQ pattern
Keys 50, 30, 70, 20, 40, 60, 80, 65 are inserted into an empty BST, then 50 is deleted by replacing it with its inorder SUCCESSOR. What is the preorder traversal afterwards?
- A. 65 30 20 40 70 60 80
- B. 60 30 20 40 70 65 80
- C. 40 30 20 70 60 65 80
- D. 60 30 20 40 70 80 65
Correct answer: B. 60 30 20 40 70 65 80
The successor of 50 is the leftmost key of its right subtree, 60. 60 moves to the root and its right child 65 takes its place under 70. Preorder: 60 30 20 40 70 65 80. Using the predecessor (40) would give the second option.
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
- How many of the 7! insertion orders of the keys 1–7 produce the perfectly balanced BST with root 4, children 2 and 6, and leaves 1, 3, 5, 7?
- A binary tree has inorder 9 5 1 7 2 12 8 4 3 11 and postorder 9 1 2 12 7 5 3 11 4 8. What is its preorder?
- Keys 1, 2, 3, 4, 5, 6, 7 are inserted in that order into an empty AVL tree. How many rotations (counting a double rotation as one…
- What is the maximum possible height of an AVL tree with 20 nodes (a single node has height 0)?
- The words car, cart, care, cat, dog are inserted into an empty trie (one node per character, shared prefixes share nodes). How many nodes…
- How many calls in total (including the first) does C(5, 2) make? c int C(int n, int k) { if (k == 0 || k == n) return 1; return C(n - 1, k…