Binary search vs binary search tree

后端 未结 4 1608
我寻月下人不归
我寻月下人不归 2021-01-31 03:16

What is the benefit of a binary search tree over a sorted array with binary search? Just with mathematical analysis I do not see a difference, so I assume there must be a diffe

4条回答
  •  半阙折子戏
    2021-01-31 04:01

    Your analysis is wrong, both insertion and deletion is O(n) for a sorted array, because you have to physically move the data to make space for the insertion or compress it to cover up the deleted item.

    Oh and the worst case for completely unbalanced binary search trees is O(n), not O(logn).

提交回复
热议问题