Question
What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2015 answer key
Solution
Analyze the worst-case shape of a Binary Search Tree and the resulting search, insertion, and deletion times.
In an arbitrary (unbalanced) Binary Search Tree containing elements:
- If keys are inserted in sorted (or reverse sorted) order, the BST degenerates into a linear chain (skewed tree) of depth .
- Insertion: Finding the insertion position requires traversing down the skewed tree to the leaf position, taking comparisons in the worst case.
- Deletion: Locating the node to delete and its in-order predecessor/successor requires traversing the path of length , also taking time in the worst case.
Thus, both insertion and deletion have a worst-case time complexity of (option B).
B
Assuming an AVL or self-balancing binary search tree where operations are , rather than an ordinary BST.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 1
- Question
- 33 of 65, printed as CS Q.23
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.