What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
What are the worst-case complexities of insertion and deletion of a key in a binary search tree? Correct Answer θ (n) for both insertion and deletion
Concepts:
Minimum height of the tree is when all the levels of the binary search tree (BST) are completely filled.
Maximum height of the BST is the worst case when nodes are in skewed manner.
Formula:
Minimum height of the BST with n nodes is ⌈log2 (n + 1)⌉ - 1
The maximum height of the BST with n nodes is n - 1.
BST with a maximum height:
[ alt="zza05" src="//storage.googleapis.com/tb-img/production/17/03/zza05.JPG">
Insertion:
Traverser the BST to the maximum height
Worst-case time complexity of Insertion = θ (n - 1) ≡ θ (n)
Deletion:
Traverser the BST to the maximum height
Worst-case time complexity of = θ (n - 1) ≡ θ (n)