GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Bound operations by BST chain height

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

How these are solved

Exhibit a degenerate n-node BST and count the full search path before insertion/deletion to establish worst-case linear cost. 2015 asks both operations;

1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 35, GATE 2015: What are worst-case insertion and deletion costs in a binary search tree with n keys? A Θ(log n),Θ(log n); B Θ(n),Θ(n); C Θ(n),Θ(log n); D Θ(log n),Θ(n).
Tap to enlarge
Your answer
Answer & solution

Official answer: B

BST operations take O(h) time in terms of tree height h. Without a balancing guarantee, sorted insertion can create a chain with height n−1. Insertion may search to its bottom, and deletion of a specified key may likewise require a full-height search, with successor/predecessor work also bounded by height. Logarithmic guarantees require a balanced structure, which is not stated.

Solution: An unbalanced BST can be a chain of n nodes. Finding an insertion position or locating a node for deletion can then traverse Θ(n) nodes, so both worst-case costs are linear, B.

Original paper, page 13 · Answer key

1 mark · MCQ
Report issue

Worst-case unbalanced BST insertion

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