Question 23

Computer Awareness Trees Easy

In a binary search tree, the worst case time complexity of inserting and deleting a key is:

(A) \( O(lg n) \) for insertion and \(O(lg n)\) for deletion
(B) \( O(n) \) for insertion and \( O(lg n) \) for deletion
(C) \( O(n) \) for insertion and \( O(n) \) for deletion
(D) \( O(lg n) \) for insertion and \( O(n) \) for deletion
View Dynamic Solution & Explanation
Correct Solution: Option C

Step-by-step Solution:

Solution:

For a Binary Search Tree (BST), time complexities depend on the height \(h\) of the tree. - In the worst case (when the BST is completely unbalanced, e.g. degenerates into a linked list), the height \(h = n\). - Most basic BST operations (search, insertion, deletion) take time proportional to the height, i.e. \(O(h)\).

Insertion: We search from the root to the correct leaf position and insert — cost \(O(h)\). In worst case \(h = n\) ⇒ insertion \(\;=\; O(n)\).

Deletion: We locate the node (cost \(O(h)\)) and may need to find its in-order successor/predecessor (again up to \(O(h)\)) and adjust pointers — overall \(O(h)\). In worst case \(h = n\) ⇒ deletion \(\;=\; O(n)\).

✅ Correct Answer: (C) \(O(n)\) for insertion and \(O(n)\) for deletion