Big O(h) vs. Big O(logn) in trees

后端 未结 2 1009
梦如初夏
梦如初夏 2021-01-12 14:18

I have a question on time complex in trees operations.
It\'s said that (Data Structures, Horowitz et al) time complexity for insertion, deletion, search, finding mins-ma

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-12 14:52

    O(h) means complexity linear dependent on tree height. If tree is balanced this asymptotic becomes O(logn) (n - number of elements). But it is not true for all trees. Imagine very unbalanced binary tree where each node has only left child, this tree become similar to list and number of elements in that tree equal to height of tree. Complexity for described operation will be O(n) instead of O(logn)

提交回复
热议问题