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

前端 未结 4 517
[愿得一人]
[愿得一人] 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:37

    This is because the article that you are reading considered "getting to that index" as a separate operation. The article assumes that you are already at the index you wish to perform add(int, E).

    To conclude:

    Insert or Remove operation = O(1)

    Finding node at nth index = O(n)

提交回复
热议问题