Skip to content
Official PYQ · 2013

GATE CS 2013 Q7 — Binary Search Trees

Explain with AI

Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of nn nodes?

Choose one option
View worked solution

Answer: C

To find the tightest upper bound for inserting an object into a Binary Search Tree (BST) of nn nodes, we must consider the worst-case scenario.

In a Binary Search Tree, the insertion operation involves traversing from the root down to a leaf position where the new node can be placed. The time complexity of this operation is proportional to the height of the tree, hh:

Time Complexity=O(h)\text{Time Complexity} = O(h)

Depending on the structure of the BST, the height hh varies:

  • Best/Average Case (Balanced Tree): The height of the tree is h=Θ(log⁡n)h = \Theta(\log n), leading to an insertion time of O(log⁡n)O(\log n).
  • Worst Case (Skewed Tree): If the elements are inserted in sorted order (e.g., 1,2,3,…,n1, 2, 3, \dots, n), the tree degenerates into a linear chain (a skewed tree). In this case, the height of the tree is h=Θ(n)h = \Theta(n).

Since the question asks for the upper bound (which must cover the worst-case scenario) for a standard, un-balanced BST, the tightest upper bound is O(n)O(n).

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

Published
Report a correction
Keep exploringMore Binary Search Trees questions