Skip to main content

Linear Data Structures

Linear structures organize elements in a sequence, but their representations and permitted operations differ.

Comparison

StructureIndexed accessInsert/remove at endInsert/remove at known interior positionMain trade-off
Dynamic arrayO(1)O(1)amortized O(1)O(1)O(n)O(n) shiftslocality and random access
Singly linked listO(n)O(n)O(1)O(1) with tail for insert; tail removal O(n)O(n)O(1)O(1) after predecessor is knownindirection and node overhead
Doubly linked listO(n)O(n)O(1)O(1) with endpointsO(1)O(1) after node is knownextra link per node
Stacknot part of contractpush/pop at topnot allowed by interfaceLIFO discipline
Queuenot part of contractenqueue/dequeue at opposite endsnot allowed by interfaceFIFO discipline

Finding an interior node or position is separate from modifying it. Saying “linked-list insertion is O(1)O(1)” silently assumes the relevant node or predecessor is already available.

Selection rules

  • Prefer a dynamic array for general-purpose sequences and iteration-heavy work.
  • Prefer linked nodes when stable node identity and local splicing dominate.
  • Expose a stack or queue when restricted access communicates an algorithmic invariant better than a general list.
  • Use a circular buffer for a bounded queue with predictable storage.

In Python, list is a dynamic array of object references; collections.deque supports efficient operations at both ends.

Source