Question

What are the worst-case complexities of insertion and deletion of a key in a binary search tree?

Choose one option
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 nn elements:

  • If keys are inserted in sorted (or reverse sorted) order, the BST degenerates into a linear chain (skewed tree) of depth nn.
  • Insertion: Finding the insertion position requires traversing down the skewed tree to the leaf position, taking Θ(n)\Theta(n) comparisons in the worst case.
  • Deletion: Locating the node to delete and its in-order predecessor/successor requires traversing the path of length nn, also taking Θ(n)\Theta(n) time in the worst case.

Thus, both insertion and deletion have a worst-case time complexity of Θ(n)\Theta(n) (option B).

Final answer

B

Common trap

Assuming an AVL or self-balancing binary search tree where operations are Θ(log⁡n)\Theta(\log n), 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.