Why is deleting in a single linked list O(1)?

后端 未结 8 2512
悲哀的现实
悲哀的现实 2020-12-25 14:50

I do not quiet understand why deleting at the end of a single linked list goes in O(1) time, as the wikipedia article says.

A single linked list consists out of node

8条回答
  •  渐次进展
    2020-12-25 15:29

    O(1) simply means "constant cost". It does not mean 1 operation. It means "at most C" operations with C being fixed regardless of other parameters changing (such as list size). In fact, in the sometimes confusing world of big-Oh: O(1) == O(22).

    By contrast deleting the whole list has O(n) cost, because the cost changes with the size (n) of the list.

提交回复
热议问题