60.4k views
1 vote
Binary Search Tree (vanilla BST) containing N keys: CONTAINS has worst-case time complexity of...

a. O(1)
b. O(log N)
c. O(N)
d. O(N²)

1 Answer

6 votes

Final answer:

The worst-case time complexity of the CONTAINS operation in a vanilla Binary Search Tree containing N keys is O(N), which happens when the tree is unbalanced.

Step-by-step explanation:

The worst-case time complexity of the CONTAINS operation in a Binary Search Tree (vanilla BST) containing N keys is O(N). This situation occurs when the tree becomes unbalanced and takes the form of a linear chain (degenerates to a linked list), with each key having only one child. In such a case, the search operation would have to traverse from the root node to the deepest node, leading to a time complexity that is linear with respect to the number of nodes in the tree.

User Joe Half Face
by
9.3k points