DevTools Logo

Algorithm Arena & Data Structure Visualizer

About this tool

The Algorithm Arena turns complexity theory into something you can watch. Eight sorting algorithms — QuickSort in both Lomuto and Hoare flavors, MergeSort, HeapSort, RadixSort, InsertionSort, BubbleSort and a deliberately bounded BogoSort — run on one seeded input while every comparison, swap and write is recorded, so you can play, pause, scrub and single-step the exact execution. Race mode puts two or four algorithms side by side on identical data: the lanes finish with different op counts, and the trophy goes to the fewest operations.

The pathfinding lab pairs six classics — BFS, DFS, Dijkstra, A* with Manhattan or Euclidean heuristics, and Greedy Best-First — with three seeded perfect-maze generators (Recursive Backtracker, randomized Kruskal, randomized Prim). Watch the frontier ripple out, see exactly where DFS wastes effort compared to A*, and read the final path cost and visited-cell count for each run.

The data-structure panel records full snapshots at every operation, so BST inserts, AVL rebalancing rotations, Red-Black recolorings, B-Tree node splits, heap sift-downs and trie prefixes can be replayed forward and backward with the active node highlighted and each step explained in plain language.

Every algorithm ships with a line-highlighted reference implementation in JavaScript, Python, Go and C++ — the line currently executing lights up as the engine steps — plus a Big-O table you can export as Markdown, and the whole catalog as JSON. Sound can be enabled so compared values play as pitch (sonification) through the same audio engine that powers the synth tools.

All traces are computed locally in a Web Worker (with an inline fallback): nothing is uploaded, and a 64-element race replays smoothly because the heavy recording happened off the main thread.

How to use this tool

  1. Pick your arena

    Choose the Sorting Arena, Pathfinding or Data Structures tab — each is a self-contained lab with its own controls.

  2. Race algorithms

    In sorting, toggle Single / Race 2 / Race 4, pick any combination of algorithms, set the size and seed, and press play. The lane with the fewest ops wins.

  3. Walk a maze

    In pathfinding, choose the algorithm and maze generator, regenerate for a new layout, then step or scrub through frontier, visits and the final path.

  4. Replay tree operations

    Enter keys (or words for a trie), press Run operations, and step through inserts, rotations and recolorings with the tree redrawn at every step.

  5. Read code and complexity

    The highlighted source panel follows execution line by line in JavaScript, Python, Go or C++, and the complexity table summarizes best/average/worst/space for every algorithm.

Use cases

Interview prep with receipts

Explain a rotation or a partition scheme while stepping the engine — the op log and highlighted code line back up every claim.

Choosing between algorithms with data, not vibes

Race your real shortlist on the size class you ship (8 vs 64 elements flips the InsertionSort vs MergeSort answer) and read the op counts.

Teaching CS fundamentals

Sonification plus lane races make the O(n log n) vs O(n²) gap something students feel rather than memorize.

Generating teaching material

Export the complexity table as Markdown for course notes, or the four-language catalog JSON for exercises and graders.

Common mistakes

Mistake:Reading op count as wall-clock time

Fix:Ops are engine steps, not seconds — compare algorithms within a language and a size class, not across them; real runtimes depend on memory layout and constants.

Mistake:Treating race winners as universal

Fix:The champion depends on input: re-run with a new seed and different sizes before concluding anything — QuickSort and InsertionSort swap places at small n.

Mistake:Expecting DFS to find the shortest path

Fix:Only BFS, Dijkstra and A* (with an admissible heuristic) guarantee optimality on these grids; DFS finds a path, not the path.

Mistake:Confusing the Euclidean A* variant as 'better'

Fix:Straight-line distance underestimates grid distance, so it stays optimal but usually expands more cells — compare the visited counts.

Frequently asked questions

How does the race mode decide the winner?

All lanes run on the exact same seeded input, and each algorithm records every comparison, swap and write as an operation. The trophy goes to the fewest total operations, shown per lane alongside comparison/swap/write counts. Operations measure engine work, not wall-clock milliseconds — constants differ per language and machine, but op counts make the asymptotic story visible.

Why does QuickSort lose to MergeSort on sorted input?

The Lomuto partition takes the last element as its pivot. On already-sorted (or reverse-sorted) data every split is maximally unbalanced (0 / n−1), which degrades QuickSort to O(n²). MergeSort always splits in half, so its O(n log n) holds regardless of input. The Hoare variant and randomized pivots mitigate this — race all three to see it.

Which pathfinding algorithm should I use?

On unweighted grids: BFS is the simple optimal answer. Dijkstra generalizes it to weighted edges. A* with a Manhattan heuristic is optimal on 4-neighbour grids and usually visits far fewer cells; the Euclidean variant stays admissible but expands more. Greedy Best-First is fastest but not optimal, and DFS only promises a path, not the shortest one.

What does the sonification actually play?

Each comparison maps the compared value to pitch (low values low, high values high) through the shared Web Audio engine — the same one the synth tools use. Listening to a sort run gives you a feel for its access pattern: BubbleSort's sweeps sound like rising arpeggios, QuickSort's partitioning jumps between registers. Audio needs a click to start (browser autoplay policy) and can be toggled off any time.

Are the trees real implementations?

Yes — AVL uses height bookkeeping with LL/RR/LR/RL rotations, Red-Black follows the CLRS insert fixup (recoloring and rotations, with invariant checks enforced by the test suite: black root, no red-red edges, uniform black height), the B-Tree is order 4 (2-3-4) with median promotion on overflow, and heaps sift down from the classic Floyd build. Duplicates are ignored for search trees, as in most textbook treatments.

Can I trust the code snippets when porting?

The JavaScript, Python, Go and C++ snippets are line-aligned reference implementations that mirror the traced engine — the highlight follows the same statement in every language. They favor clarity over micro-optimization (e.g. recursive quicksort, not iterative with explicit stacks), so treat them as the canonical version to verify against, not as a tuned production library.

Is the BogoSort real?

It shuffles until sorted, exactly as advertised — but bounded to 40 shuffles so it can never run away. When it gives up, the trace says so. It exists because watching it 'work' is the fastest way to appreciate why O(n·n!) is a joke, not a strategy.

Does anything leave my browser?

No. Traces are computed in a Web Worker on your device (with an inline fallback where Workers are unavailable), mazes are seeded locally, and the only persistence is your own inputs in localStorage. There is no backend call in any tab.

References & standards