GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 35

GATE CSE 2015 Set 1 Q35

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q35 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