Tech-Interview-Cheat-Sheet icon indicating copy to clipboard operation
Tech-Interview-Cheat-Sheet copied to clipboard

The time complexity of Binary Search Tree is not precise.

Open lucaspk opened this issue 5 years ago • 1 comments

The Time Complexity for Binary Search Tree (BST) basic operations (Insert, Remove and Search) is not O(log n) if the BST is unbalanced (is O(logn) only when we are talking about Balanced BST such as AVL and Red-Black). The correct time complexity would be O(h) where h is the height of the BST. It is h because the BST may become skewed as the following image.

image

lucaspk avatar Jul 22 '20 19:07 lucaspk

Well I'II look into this and get back to you

DhruvDoshi avatar Aug 27 '20 11:08 DhruvDoshi