GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 14(a)

Build a binary search tree

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

GATE 2001, Q14(a) Descriptive
Report issue

Binary Search & Balanced Trees

Question 14(a), GATE 2001: Insert 15,32,20,9,3,25,12,1 into an initially empty BST.
Question 14(a), GATE 2001: Insert 15,32,20,9,3,25,12,1 into an initially empty BST.
Tap to enlarge
Answer & solution

Answer: Root 15; left subtree 9(3(1,∅),12); right subtree 32(20(∅,25),∅). (no official key was published)

Step through it (19 steps)

Use the rule smaller keys go left and larger keys go right. Insert 15 as root; 32 right of 15; 20 left of 32; 9 left of 15; 3 left of 9; 25 right of 20; 12 right of 9; 1 left of 3.

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

Accessible description: root 15 has children 9 and 32. Node 9 has children 3 and 12; node 3 has left child 1. Node 32 has left child 20, whose right child is 25. All other links are null. Inorder traversal 1,3,9,12,15,20,25,32 verifies the ordering.

Original paper, page 9