GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Construct BST by ordered insertion

5 questions solved the same way, newest first. Back to Data Structures

How these are solved

Insert each key by root-to-null comparisons without rotations; read the resulting root-subtree sizes, complete shape, height, deepest key or named depth. Requested outputs differ, so only a procedure group.

1 mark · NAT
Report issue

Binary Search & Balanced Trees

Question 35, GATE 2025: Insert 10,−4,15,30,20,5,60,19 in that order into an initially empty ordinary binary search tree, with no balancing rotations. How many edges are on the path from node 19 to the root?
Tap to enlarge
Answer & solution

Official answer: 4

Step through it (10 steps)

Insert by comparing each new key with the nodes on its search path. The first key 10 becomes the root. −4 is its left child and 15 its right child. Next 30 becomes the right child of 15; 20 becomes the left child of 30. The key 5 goes right of −4, and 60 goes right of 30.

For 19, compare with 10: go right. Compare with 15: go right. Compare with 30: go left. Compare with 20: go left and insert there. Thus its root path is 10→15→30→20→19.

There are five nodes on that path but four edges, so the requested distance is 4. This is its depth when the root has depth zero. The left branch containing −4 and 5, and the right branch containing 60, do not contribute to this path. Answer: 4.

Original paper, page 26 · Answer key

1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 27, GATE 2015: Insert 71,65,84,69,67,83, in that order, into an initially empty binary search tree. Which element is at the lowest (deepest) level? (A) 65; (B) 67; (C) 69; (D) 83.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Step through it (8 steps)

1. Insertion gives root71, left65, right84; 69 is 65’s right child, 67 is 69’s left child, 83 is 84’s left child.

2. The deepest node is 67 at depth 3, B.

Original paper, page 62 · Answer key

1 mark · MCQ
Report issue

Height after binary-search-tree insertions

Binary Search & Balanced Trees

Question 4, GATE 2004: Insert 10,1,3,5,15,12,16, in that order, into an empty binary search tree. What is its height, defined as the maximum edge distance from root to a leaf?
Options:
(A) 2
(B) 3
(C) 4
(D) 6
Question 4, GATE 2004: Insert 10,1,3,5,15,12,16, in that order, into an empty binary search tree. What is its height, defined as the maximum edge distance from root to a leaf?
Options:
(A) 2
(B) 3
(C) 4
(D) 6
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step through it (9 steps)

1. Inserting10,1,3,5 produces the chain 10→1→3→5 on the left side. The remaining 15,12,16 form a right subtree rooted 15 with two children.

2. The deepest leaf 5 is three edges from 10, so the stated edge-distance height is 3, B.

3. Teaching check: The complete parent-child structure is 10:(left 1,right 15), 1:(right 3), 3:(right 5), 15:(left 12,right 16). The deepest path has four vertices but three edges. Distinguishing edge height from node count eliminates the off-by-one distractor.

Original paper, page 1

Descriptive
Report issue

Build a binary search tree

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

2 marks · MCQ
Report issue

Sizes of root subtrees after BST insertion

Binary Search & Balanced Trees

Question 2.14, GATE 1996: Insert 50,15,62,5,20,58,91,3,8,37,60,24 into an empty BST. Count nodes in the left and right subtrees of the root.
Tap to enlarge
Your answer
Answer & solution

Answer: B: 7 and 4 (no official key was published)

Step through it (14 steps)

The first key 50 remains the root in ordinary unbalanced BST insertion. Every later key below 50 belongs somewhere in its left subtree: 15,5,20,3,8,37,24, totaling seven. Every key above 50 belongs in its right subtree: 62,58,91,60, totaling four. Internal insertion paths affect shape but not which side of the root contains each key. The root itself is excluded from both counts, and 7+4+1=12 checks the total number of inserted keys.

Original paper, page 5