Algorithm - the time complexity of deletion in a unsorted array

后端 未结 4 1085
庸人自扰
庸人自扰 2021-01-01 03:29

Suppose there is a unsorted array A, and it contains an element x (x is the pointer of the element), and every element has a satellite variable k. So, we can get the followi

4条回答
  •  借酒劲吻你
    2021-01-01 04:35

    Yes, that's right. Also, if it's an array, deleting alone will take O(n) time because after you delete the element, you'll need to shift all the elements to the right of that element one place to the left. So, even if you know x (for example, you will only delete the first element), it will take O(n) time.

提交回复
热议问题