GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 14(b)

Delete the BST root

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2001 paper

GATE 2001, Q14(b) Descriptive
Report issue

Binary Search & Balanced Trees

Question 14(b), GATE 2001: Delete key 15 from the BST built by insertion order 15,32,20,9,3,25,12,1.
Question 14(b), GATE 2001: Delete key 15 from the BST built by insertion order 15,32,20,9,3,25,12,1.
Question 14(b), GATE 2001: Delete key 15 from the BST built by insertion order 15,32,20,9,3,25,12,1.
Tap to enlarge
Answer & solution

Answer: Successor replacement yields root 20; predecessor replacement yields root 12. (no official key was published)

Choose inorder-successor replacement: the least key in the right subtree of 15 is 20. Copy 20 into the root and remove the old 20 node, reconnecting its right child 25 as the left child of 32.

        20
       /  \
      9    32
     / \   /
    3  12 25
   /
  1

Accessible description: root 20 has children 9 and 32; 9 has children 3 and 12; 3 has left child 1; 32 has left child 25. Alternatively, inorder-predecessor replacement uses 12 as root and removes the old leaf 12. That result is 12(9(3(1,∅),∅),32(20(∅,25),∅)). Both are valid because the question does not prescribe which replacement policy to use.

Original paper, page 9