DSAVisualiseData Structures & Algorithms Studio
Chapter 02 · linked-list, stack

Lists & Stacks

Sequential node-based and array-backed linear structures provide O(1) operations at designated boundaries. Stacks enforce Last-In First-Out (LIFO) discipline; queues enforce First-In First-Out (FIFO); circular lists link tail to head for perpetual rotation; segmented lists balance contiguous cache locality with O(1) segment expansion.

Key Invariants & Rules

  • Stack top is always the most recently pushed element.
  • Paired-queue stacks transfer N-1 elements to expose the newest item as the last-polled element.
  • Circular linked list tail pointer links back to the sentinel head, preserving O(1) append and rotate.
  • Functional lists share tail structure across persistent versions without mutating existing nodes.
  • Segmented list cursor advances across segment boundaries without inventing intermediate operations.

Must-Know Algorithms

LIFO StackO(1) push/pop

Foundational structure for recursion emulation, expression evaluation, and undo buffers.

Two-Queue StackO(N) push or pop, O(1) peek

Demonstrates adapter discipline and cost transference between queue operations.

Persistent Functional ListO(1) cons, structural sharing

Immutability guarantee enabling safe concurrency and instant version history.

Learning Path (6 Lessons)

Self-Check & Concept Review

1. How does an array-backed stack handle growth when capacity is reached?

Standard dynamic array stacks double their backing buffer, guaranteeing an amortized O(1) push time.

2. In a circular singly linked list with a sentinel head node, what does `sentinel.next == sentinel` indicate?

An empty circular list with a sentinel points to itself, avoiding special null-pointer checks on edge operations.

3. When implementing a LIFO stack using two FIFO queues, what is the cost of either push or pop?

Because queues are FIFO, reversing access order requires draining all prior elements into a secondary queue to isolate the newest item.

4. What is the key property of persistent functional lists (cons, head, tail)?

Structural sharing lets new list versions point to existing tails as immutable shared references in O(1) time.

5. What causes a ConcurrentModificationException during list iterator traversal?

Iterators maintain expected modification counts (nOp); structural changes bypass the iterator and cause immediate fail-fast termination.