Skip to main content
🧩 Algorithm Projects

What you're building

A sortingSteps(arr, algorithm) function that returns every intermediate state of a sorting algorithm, not just the final result. This is the data layer behind any sorting visualiser (like visualgo.net).

Supported algorithms: "bubble", "selection", "insertion".

sortingSteps([3,1,2], "bubble");
// [
//   [3,1,2],  // initial
//   [1,3,2],  // after swap
//   [1,2,3],  // after swap
//   [1,2,3],  // (final pass, no swaps)
// ]

Requirements

  • Accept arr (array of numbers) and algorithm (string: "bubble", "selection", or "insertion").
  • Return an array of snapshots — each snapshot is a copy of the array at that moment.
  • The first snapshot is always the original array.
  • The last snapshot is always the fully sorted array.
  • Do not mutate the input array.
  • Intermediate snapshots: record the array state after each swap or insertion.

Stretch goals

  • Add "merge" and "quick" sort with their split/merge snapshots.
  • Include metadata with each step: which indices were compared/swapped.
  • Build a React component that replays the steps with a slider.

What this proves

This project shows you can implement classic sorting algorithms and think about algorithm state — not just the output. It's a visualiser backend: a real, deployable tool. It also proves you understand the mechanics of O(n²) sorts well enough to instrument them.

⚡ 50 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
first step is original, last step is sorted
input array is not mutated
selection sort produces sorted output
insertion sort produces sorted output

Run your code to check these.