In Java, why is insertion or deletion in a Linked List a constant time operation? Isn't it misleading?

前端 未结 4 1216
盖世英雄少女心
盖世英雄少女心 2021-01-04 09:43

Insertion or deletion of an element at a specific point of a list, assuming that we have a pointer to the node already, is a constant-time operation. - from

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 10:32

    You said it yourself: "assuming we have a pointer to the node already". That avoids the traversal you identify as the cause of the linear time.

    Admittedly, the Wikipedia text is a bit ambiguous, since there are two nodes involved: the one being inserted, and the one in the list where to insert it.

提交回复
热议问题