GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For a BST built from distinct keys (deletion of a node with two children uses its inorder successor), consider: I. Inserting a new key and then deleting that same key always restores the original tree exactly. II. Deleting x and then y always gives the same tree as deleting y and then x. III. Inserting the keys in the tree's preorder sequence into an empty BST rebuilds the same tree. IV. Inserting the keys in the reverse of the tree's postorder sequence into an empty BST rebuilds the same tree. Which statements are true?
- A. I and III only
- B. I, III and IV only
- C. I, II and III only
- D. II and IV only
Correct answer: B. I, III and IV only
I: a new key is inserted as a leaf, and removing that leaf restores the tree. II fails: with the successor rule the order of two deletions can change which node is copied up (checked by brute force). III: preorder visits every parent before its descendants, so insertion rebuilds the same shape. IV: the reverse of postorder still lists every node before all of its descendants (root, then right part, then left part), so the same BST is rebuilt; only the order of insertion between independent subtrees changes.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A directed graph has adjacency lists (visited in the order listed): A: B, C; B: D, E; C: E, F; D: G; E: D, H; F: H, B; G: none; H: G, A…
- A DAG on vertices 1..7 has edges 1->2, 1->3, 2->4, 3->4, 3->5, 4->6, 5->6, 7->5. How many distinct topological orderings does it have?
- Union-find on elements 1..12 (initially separate) uses union by size (the root of the larger set becomes the parent; on a tie the root of…
- A 3-ary max-heap with 100 elements is stored in a 0-indexed array (the children of i are 3i + 1, 3i + 2, 3i + 3). How many leaves does it…
- Build-heap (bottom-up, max-heap) is run on [3, 9, 2, 1, 4, 5, 8, 7, 6, 10, 12, 11]. In each sift-down step the larger of the element and…
- A dynamic array starts with capacity 4. When an append finds it full, it allocates capacity c + c / 2 (integer division), copies every…