Skip to content
Official PYQ · 2015

GATE CS 2015 Set 1 Q23 — Binary Search Trees

Explain with AI

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

Choose one option
View worked solution

Answer: B

In a standard Binary Search Tree (BST) of nn nodes, the time complexity of search, insertion, and deletion operations is directly proportional to the height hh of the tree.

In the worst-case scenario, the BST is highly unbalanced (skewed), where each node has at most one child (resembling a singly linked list). In this case, the height of the tree is h=Θ(n)h = \Theta(n).

  • Insertion: To insert a new key, we must traverse from the root to find the appropriate empty spot. In a skewed tree, this traversal can go all the way to the deepest leaf, taking Θ(n)\Theta(n) steps.
  • Deletion: To delete a key, we first locate the node (which takes up to Θ(n)\Theta(n) steps). If the node has two children, we must also find its inorder successor or predecessor, which can take another traversal. Thus, the overall worst-case complexity remains Θ(n)\Theta(n).

Therefore, the worst-case complexities for both insertion and deletion are Θ(n)\Theta(n), making Option B the correct choice.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Search Trees questions