step 0 / 7
if (found) break;
complexity: O(n²)
recurse(n-1)
while (unsolved) {
return eureka;
sort(chaos);

ALGOHA

where algorithms have their aha moment

let input = shuffle(data);

The Problem

What pattern hides in the noise? Every unsorted dataset contains a secret order, waiting to be revealed by the right sequence of comparisons and swaps. The question is not whether order exists, but how quickly we can find it.

for (i = 0; i < n; i++) compare(a[i], a[i+1]);

The Search

Watch the sort unfold frame by frame. Each comparison narrows the chaos. Each swap brings order one step closer. Scroll through the execution trace and witness computation made visible.

step 1
step 2
step 3
step 4
step 5
sorted
if (n <= 1) return; split(left, right);

The Recursion

Divide and conquer. Every complex problem splits into simpler versions of itself, branching like a tree until each leaf is trivially solvable. Then the solutions flow upward, merging at every fork, until the whole tree resolves into a single answer at the root.

asymptotic_bound = Theta(n * log(n));
O(n log n)

The beauty of complexity theory is its ability to compress infinite possibility into a single expression. Three characters tell you everything about the algorithm's soul: how it breathes under pressure, how it scales with ambition, whether it will survive the weight of the world's data.

assert(isSorted(result)); // verified

The Solution

Order emerges. Every element finds its place. The chaos that seemed impenetrable reveals itself as a sequence that was merely waiting to be discovered.

0 comparisons
return eureka;

eureka

algoha.com