Question
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 nodes?
Official answer and solution
- Official answer
- C
- From
- Official GATE 2013 answer key
Solution
Consider the worst-case shape of a binary search tree to find the tightest upper bound on insertion time.
In a binary search tree (BST) of nodes:
- To insert a new object, the algorithm compares keys starting at the root and descends down to an empty leaf position.
- The time complexity of insertion is proportional to the height of the BST.
- In the worst case (for example, when keys are inserted in strictly ascending or descending sorted order), the BST degenerates into a linear chain (skewed tree) of height .
- In this worst-case configuration, insertion takes time.
Therefore, the tightest upper bound representing the insertion time in a general (unbalanced) BST of nodes is .
Option (C)
Assuming the tree is balanced and stating , which only applies to self-balancing BSTs like AVL or Red-Black trees.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2013 Computer Science and Information Technology (CS)
- Question
- 7 of 65, printed as CS Q.7
- 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.