Playground

Pick a structure or algorithm, give it your own input (operations, values or a tree) and step through what it does, forwards and backwards. Inputs are structured and validated: the playground runs trusted simulations, never your code.

Arrays and dynamic arrays

  • Dynamic array

    Append, insert and remove with capacity, resizing and copies.

    append amortized O(1); insert/remove O(n)

  • Fixed-capacity array

    Get, set, insert and delete in a buffer that never grows; size vs capacity and address = base + i·size.

    get/set O(1); insert/delete O(n − i)

  • Matrix traversal

    Row-major vs column-major order with the address mapping, stride per visit and jagged rows.

    Θ(rows · cols)

Stack / queue / deque

  • Stack

    Push, pop and peek on the end of a dynamic array, including underflow.

    push/pop amortized O(1)

  • Queue (ring buffer)

    Enqueue and dequeue in a fixed array with head, tail and wraparound.

    enqueue/dequeue O(1)

Linked lists

  • Singly linked list

    Prepend, append, find, remove and in-place reversal with stable node identities.

    prepend/append O(1); find/remove O(n)

Hash tables

  • Hash table

    Buckets, collisions, chaining, load factor and rehashing (conceptual model).

    put/get/remove expected O(1)

  • Hash table (open addressing)

    Linear, quadratic and double-hashing probes, tombstones on delete, resize at load 0.5.

    expected O(1) with a good hash and bounded load; O(n) worst

Searching

  • Binary search

    low, mid and high on a sorted array; any match or first occurrence.

    O(log n)

  • Linear search

    Scan left to right until the first match, counting comparisons and bounds checks.

    O(n)

  • Binary search on the answer

    Find the smallest capacity that passes a monotonic feasibility check.

    O(n log S)

  • Jump, exponential and interpolation search

    Three ways to search sorted data, each returning the first occurrence.

    jump O(√n); exponential O(log i); interpolation O(log log n) expected on uniform keys

Sorting

  • Bubble sort

    Neighbour comparisons and swaps with the early exit; stable.

    O(n²) worst, O(n) sorted

  • Insertion sort

    Lift a key, shift larger elements right, drop it into the gap; stable.

    O(n²) worst, O(n) sorted

  • Merge sort

    Split, merge through one buffer, with the call stack shown.

    Θ(n log n)

  • Selection sort

    Find the minimum of the unsorted part and swap it into place; not stable.

    Θ(n²) comparisons, at most n − 1 swaps

  • Quicksort

    Lomuto partition around the middle element, with the recursion stack shown.

    O(n log n) expected, O(n²) worst

  • Heap sort

    Build a max-heap, then move the root to the sorted tail n − 1 times.

    O(n log n), O(1) extra

  • Quickselect

    Partition around the middle element and keep only the side that holds index k.

    O(n) expected, O(n²) worst

Trees

  • Tree traversal

    Preorder, inorder, postorder (call stack) and level order (queue).

    Θ(n)

  • Binary search tree

    Insert, search and delete (all three cases) while the ordering invariant holds.

    O(h): O(log n) balanced, O(n) degenerate

  • AVL tree

    Insert into a self-balancing BST with LL, RR, LR and RL rotations and balance factors.

    O(log n) search and insert

Heaps

  • Binary heap

    An array-backed min-heap: push with sift-up, pop with sift-down, heapify.

    push/pop O(log n); heapify O(n)

Tries

  • Trie

    Insert, search, prefix queries and delete with pruning over a–z.

    O(L) per operation

Graphs

  • BFS and DFS

    Breadth-first levels with a queue and depth-first discovery and finish order on a small graph.

    O(V + E)

  • Topological sort

    Kahn's algorithm with in-degrees, a source queue and cycle detection.

    O(V + E)

  • Dijkstra's shortest paths

    A binary-heap priority queue with lazy deletion, distances and path reconstruction.

    O((V + E) log V)

  • Kruskal's minimum spanning tree

    Sort edges by weight and keep each one unless union-find says it would close a cycle.

    O(E log E)

Union find

  • Union-find

    Union by rank and path compression on a forest and its parent array.

    near-constant amortized (inverse Ackermann)

Recursion / backtracking

  • Recursion and the call stack

    Frames push and pop for integer power, linear and by squaring, with a stack limit.

    O(e) vs O(log e) calls

  • Backtracking

    Subsets and permutations as choose, explore, unchoose on a decision tree.

    O(n · 2ⁿ) subsets, O(n · n!) permutations

Dynamic programming

  • Fibonacci: recursion to DP

    Naive recursion, memoization and a table side by side, with call counts.

    Θ(φⁿ) naive, O(n) memo or table

  • 0/1 knapsack

    Fill the 2D table cell by cell, then trace back the chosen items.

    O(nW) time and space (pseudo-polynomial)

Patterns (two pointers, windows, prefix sums)

  • Two pointers

    Pair sum from both ends of a sorted array, and in-place dedupe with read and write pointers.

    O(n)

  • Sliding window

    Fixed-size window sums and the longest window with sum at most a limit.

    O(n)

  • Prefix sums and difference arrays

    Constant-time range sums after a linear build; range updates with a difference array.

    build O(n), query O(1)

Greedy

Strings

  • String matching: naive and KMP

    Find every occurrence; KMP builds the prefix table, then scans without moving back.

    naive O(n·m) worst; KMP O(n + m)

  • UTF-8 and UTF-16 encoding

    Code points become 1–4 UTF-8 bytes and 1–2 UTF-16 units, including surrogate pairs.

    O(n) in code points

Bits / math

  • Bit operations

    Masks, x & (x − 1) tricks, Kernighan popcount, two's complement and shifts on 8, 16 or 32 bits.

    O(1) per operation; popcount O(set bits)

  • Euclid's GCD

    (a, b) ← (b, a mod b) until b = 0, then lcm = a / gcd · b.

    O(log min(a, b))

  • Sieve of Eratosthenes

    Cross out multiples from p² for each prime p ≤ √n.

    O(n log log n) time, O(n) space

Planned visualizer families

Not built yet; listed so the catalog is honest about what exists.