Sorting algorithm visualiser
Watch bubble, insertion, merge, quick and heap sort move bars on screen, with speed control and comparison counts.
Intermediateā± 8ā12 hoursšŖ 7 stepsJavaScriptHTML Canvas or React
What you'll learn
- āHow each sort really works
- āGenerators/async for step-by-step animation
- āTime complexity in practice
What you'll build
- āRandom array of 20ā200 bars
- āFive algorithms
- āSpeed slider, pause and step
- āCounts comparisons and swaps
Step-by-step guide
- 1
Draw bars
Render an array as divs or canvas rectangles; height = value.
- 2
Write sorts as generators
function* bubble(a) { ... yield {type: "compare", i, j} ... yield {type: "swap", i, j} } so the UI can play one step at a time.
- 3
Animation loop
Pull the next step every N ms (from the speed slider), colour compared bars yellow and swapped bars red.
- 4
Merge and quick sort
For merge sort yield "overwrite" steps (index, value); for quick sort show the pivot in a different colour.
- 5
Controls
Buttons: new array, start, pause, step; disable inputs while running.
- 6
Stats
Count comparisons and swaps; show them next to the expected O(n²) or O(n log n).
- 7
Deploy
Host it free on GitHub Pages or Netlify and put the link in your resume.
š Make it stand out
- +Side-by-side race between two algorithms
- +Sound for each comparison
- +Add counting sort and radix sort