Notes / tag / stacks-queues

#stacks-queues

7 notes

# Data Structures Algorithms

All Data Structures Algorithms notes →

1 — Stack

LIFO fundamentals: push/pop/peek in O(1), why list.append()/list.pop() are the right end and list.pop(0) isn't, the call stack as a literal stack, and worked bracket-matching and iterative-DFS examples.

data-structures-algorithms stacks-queues book
Jul 27, 2026

2 — Queue

FIFO fundamentals: enqueue/dequeue, why list.pop(0) is a silent O(n) trap, collections.deque as the fix, the two-stack amortized-O(1) implementation, and BFS as the queue's signature use case.

data-structures-algorithms stacks-queues book
Jul 27, 2026

3 — Circular Queue

Fixed-capacity ring-buffer queue that reuses freed slots without shifting elements — modulo-arithmetic wraparound over a plain array, and the full-vs-empty ambiguity every implementation has to resolve.

data-structures-algorithms stacks-queues book
Jul 27, 2026

4 — Deque

Deque as the shared generalization behind stack and queue: O(1) push/pop at both ends via collections.deque's fixed-size-block internals (not a list, not a per-element linked list), worked rotate/maxlen/extendleft examples, and the O(n) random-access trade-off a list doesn't have to make.

data-structures-algorithms stacks-queues book
Jul 27, 2026

5 — Monotonic Stack

A stack that enforces increasing or decreasing order at push time, solving next-greater-element, daily-temperatures, and largest-rectangle-style problems in O(n).

data-structures-algorithms stacks-queues book
Jul 27, 2026

6 — Monotonic Queue

Sliding window maximum in O(n): a deque of indices kept decreasing by value, trimmed from the back for domination and from the front for window expiry — the second eviction rule a monotonic stack structurally can't support.

data-structures-algorithms stacks-queues book
Jul 27, 2026

7 — Expression Evaluation

Infix vs. postfix vs. prefix notation, evaluating postfix/RPN with a single stack, the two-stack method for direct infix evaluation with operator precedence and parentheses, a full Basic-Calculator implementation, and shunting-yard as an alternative infix-to-postfix conversion strategy.

data-structures-algorithms stacks-queues book
Jul 27, 2026