How is LinkedList's add(int, E) of O(1) complexity?

前端 未结 4 507
[愿得一人]
[愿得一人] 2020-12-29 20:54

From the linked-list tag wiki excerpt:

A linked list is a data structure in which the elements contain references to the next (and optionally the pr

4条回答
  •  感情败类
    2020-12-29 21:43

    The wiki page you quote says:

    O(1) insert and removal at any position

    Then you ask:

    I was surprised to read this – how can the list insert at a random index

    Herein lies the confusion: the terms position and index are not being used to mean the same thing. The wiki talks about an iterator or a pointer, not about an index.

提交回复
热议问题