GATE / CS ARCHIVE

GATE CSE 2013 / QUESTION 7

Worst-case unbalanced BST insertion

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

GATE 2013, Q7 1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 7, GATE 2013: Give the tightest listed worst-case upper bound for inserting into an ordinary n-node binary search tree: A O(1), B O(log n), C O(n), D O(n log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

In an ordinary unbalanced binary search tree, increasing insertions can create a chain of n nodes. Finding the next insertion position then takes a linear search down that chain. Worst-case insertion is O(n), C, not the logarithmic bound of balanced trees.

Insertion follows the search path until it reaches a missing child, then attaches the new node. Its cost is proportional to tree height. A balanced tree has logarithmic height, but no balance requirement is given. Inserting increasing keys creates a right-child chain; a later larger key must inspect all n existing nodes. Thus linear time is possible and O(n) is the tightest listed worst-case bound.

Original paper, page 2 · Answer key