GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 19

Inorder traversal of inserted keys

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

GATE 2003, Q19 1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 19, GATE 2003: Insert 7,5,1,8,3,6,0,9,4,2, in this order, into an initially empty binary search tree using ordinary numerical order. What is its inorder traversal? A. 7,5,1,0,3,2,4,6,8,9; B. 0,2,4,3,1,6,5,9,8,7; C. 0,1,2,3,4,5,6,7,8,9; D. 9,8,6,4,2,3,0,1,5,7.
Question 19, GATE 2003: Insert 7,5,1,8,3,6,0,9,4,2, in this order, into an initially empty binary search tree using ordinary numerical order. What is its inorder traversal? A. 7,5,1,0,3,2,4,6,8,9; B. 0,2,4,3,1,6,5,9,8,7; C. 0,1,2,3,4,5,6,7,8,9; D. 9,8,6,4,2,3,0,1,5,7.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (23 steps)

1. At each node, all left-subtree keys are smaller and all right-subtree keys larger. Inorder recursively visits left subtree, root, right subtree, so this invariant sorts the output. The insertion order determines tree shape but cannot change this ordering property.

2. An inorder traversal of a BST visits its distinct keys in increasing order, independently of insertion order. The given keys are exactly 0 through 9, so the sequence is 0,1,2,3,4,5,6,7,8,9, C.

Original paper, page 2