Linked Lists

Linked Lists are a linear data structures consisting of nodes, each containing a value and a reference to the next node.

Unlike arrays, linked lists allow an efficient insertion and deletion. However, we cannot access elements by index, so we need to traverse the entire list to do so.

Operations

Let's check the complexity of linked lists' common operations:

OperationTime ComplexitySpace Complexity
Size
Get i-th
Set i-th
Copy
Append
Pop first
Pop last
Pop i-th
Delete value
Iterate
Search

Types

There are two kinds of Linked Lists:

  1. Singly Linked Lists.
  2. Doubly Linked Lists.

collections.deque

The deque module can also simulate a Linked List. You can find more information in the Queue paragraph.