Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

All notable changes to Algo Lab (Algorithm Visualizer).

## [2026-08-22] — v6 Sorting Core

### Added
- **Four new sorting algorithms**: Comb Sort, Gnome Sort, Cycle Sort (provably minimal
writes — great for the writes metric), and a simplified TimSort (insertion-sorted
minruns + merge passes with the already-ordered shortcut)
- **`sorting-core.js`** — every sorting algorithm now lives in one dependency-free
module as a pure step generator (works in the browser as `SortCore` and in Node via
`require`). The page, the tests, and the profiler all consume the same op stream.
- **Complexity Profiler** — one click benchmarks all 14 algorithms at
n = 16, 32, 64, 128, 256, 512 on the current dataset shape, draws a log-log chart,
and reports each algorithm's measured growth exponent next to its theoretical class
- **47 sorting unit tests** (`node --test tests/sorting.test.js`): correctness on every
dataset shape and edge case, stability proofs via tagged keys, cycle sort's ≤ n write
bound and zero-writes-on-sorted property, exact bubble counts on reversed input, and
exponent-estimator checks that separate the quadratic sorts from the linearithmic ones

### Changed
- `SortRunner` no longer hardcodes algorithm logic — it animates the `SortCore`
operation stream (compare / swap / write / touch / counts / mark ops), which keeps
metrics, narration, heatmap, sound, and step mode identical across all algorithms
- Tournament, race mode, and quiz automatically include the four new algorithms
- Service worker cache bumped to v6 and now precaches `sorting-core.js`

## [2026-08-20] — v5 Path Lab

### Added
Expand Down
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ An interactive teaching lab built with pure HTML, CSS, and vanilla JavaScript

Two labs share the same chrome, theme, and sound toggle:

- **Sort Lab** (`index.html`) — 10 sorting algorithms
- **Sort Lab** (`index.html`) — 14 sorting algorithms + empirical complexity profiler
- **Path Lab** (`pathfinding.html`) — 6 pathfinding algorithms + maze generators

![Algorithms](https://img.shields.io/badge/sort-10-blue) ![Pathfinding](https://img.shields.io/badge/path-6-indigo) ![PWA](https://img.shields.io/badge/PWA-offline-purple)
![Algorithms](https://img.shields.io/badge/sort-14-blue) ![Pathfinding](https://img.shields.io/badge/path-6-indigo) ![PWA](https://img.shields.io/badge/PWA-offline-purple)

## Running

Expand All @@ -28,12 +28,16 @@ macOS: `open index.html` · Linux: `xdg-open index.html`
Pathfinding algorithms and maze generators are covered by Node’s built-in test runner (no packages to install):

```bash
node --test tests/pathfinding.test.js
node --test tests/sorting.test.js tests/pathfinding.test.js
```

Sorting coverage includes correctness on every dataset shape, stability proofs for the
stable algorithms (via tagged keys), cycle sort's ≤ n write bound, and sanity checks on
the complexity profiler's exponent estimator.

## Sort Lab

### Algorithms (10)
### Algorithms (14)

| Algorithm | Best | Average | Worst | Stable | In-place | Memory |
|-----------|------|---------|-------|--------|----------|--------|
Expand All @@ -47,6 +51,13 @@ node --test tests/pathfinding.test.js
| Radix | O(nk) | O(nk) | O(nk) | Yes | No | O(n + k) |
| Counting | O(n + k) | O(n + k) | O(n + k) | Yes | No | O(k) |
| Cocktail Shaker | O(n) | O(n²) | O(n²) | Yes | Yes | O(1) |
| Comb | O(n log n) | O(n²/2ᵖ) | O(n²) | No | Yes | O(1) |
| Gnome | O(n) | O(n²) | O(n²) | Yes | Yes | O(1) |
| Cycle | O(n²) | O(n²) | O(n²) | No | Yes | O(1) |
| TimSort (simplified) | O(n) | O(n log n) | O(n log n) | Yes | No | O(n) |

All fourteen are implemented once, as pure step generators in `sorting-core.js` —
the page animates the operation stream, tests and the profiler consume it headlessly.

### Dataset generators

Expand All @@ -62,7 +73,10 @@ Random · Sorted · Nearly Sorted · Reversed · Few Unique · Sawtooth · Custo
- Presentation Mode
- Access heatmap + operations sparkline
- Algorithm recommender
- Benchmark tournament (all 10) with comparison matrix
- Benchmark tournament (all 14) with comparison matrix
- **Complexity Profiler** — measures total operations at n = 16…512, plots every
algorithm on a log-log chart, and fits the empirical growth exponent (the slope)
so you can watch bubble sort measure ≈ n² while counting sort measures ≈ n¹
- Learning cards (trivia + use cases)
- Run history (last 8, `localStorage` key `sortLabHistory`)
- Share URL, CSV export, copy summary
Expand Down Expand Up @@ -124,9 +138,11 @@ algorithm-visualiser/
├── index.html # Sort Lab
├── pathfinding.html # Path Lab
├── style.css # Shared theme + path grid
├── script.js # Sort Lab app
├── script.js # Sort Lab app (rendering, metrics, chrome)
├── sorting-core.js # Sorting step generators + profiler (browser + Node)
├── pathfinding.js # Path Lab UI
├── pathfinding-core.js # Search + mazes (browser + Node)
├── tests/sorting.test.js
├── tests/pathfinding.test.js
├── sw.js # Service worker
├── manifest.json # PWA manifest
Expand All @@ -135,7 +151,7 @@ algorithm-visualiser/
└── README.md
```

`pathfinding-core.js` exports `PathCore` in the browser and `module.exports` in Node.
`sorting-core.js` and `pathfinding-core.js` export `SortCore` / `PathCore` in the browser and `module.exports` in Node.

## License

Expand Down
20 changes: 19 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ <h2 class="panel-title">Controls</h2>
<option value="radix">Radix Sort</option>
<option value="counting">Counting Sort</option>
<option value="cocktail">Cocktail Shaker Sort</option>
<option value="comb">Comb Sort</option>
<option value="gnome">Gnome Sort</option>
<option value="cycle">Cycle Sort</option>
<option value="tim">TimSort (simplified)</option>
</select>
</div>

Expand All @@ -73,6 +77,10 @@ <h2 class="panel-title">Controls</h2>
<option value="radix">Radix Sort</option>
<option value="counting">Counting Sort</option>
<option value="cocktail">Cocktail Shaker Sort</option>
<option value="comb">Comb Sort</option>
<option value="gnome">Gnome Sort</option>
<option value="cycle">Cycle Sort</option>
<option value="tim">TimSort (simplified)</option>
</select>
</div>

Expand Down Expand Up @@ -137,7 +145,8 @@ <h2 class="panel-title">Controls</h2>
<button id="resetBtn" class="btn btn-secondary" title="Shortcut: R">Reset</button>
</div>

<button id="tournamentBtn" type="button" class="btn btn-accent btn-full" title="Run all 10 algorithms on current data">🏆 Benchmark Tournament</button>
<button id="tournamentBtn" type="button" class="btn btn-accent btn-full" title="Run all 14 algorithms on current data">🏆 Benchmark Tournament</button>
<button id="profilerBtn" type="button" class="btn btn-accent btn-full" title="Measure operation growth across input sizes">📈 Complexity Profiler</button>

<p class="shortcut-hint">Space pause · S start · G generate · R reset · Esc exit present</p>
</section>
Expand Down Expand Up @@ -178,6 +187,14 @@ <h2 class="panel-title">Tournament Leaderboard</h2>
<div id="leaderboard" class="leaderboard-wrap"></div>
</section>

<section class="panel" id="profilerPanel" hidden>
<h2 class="panel-title">Complexity Profiler</h2>
<p class="panel-sub">Empirical operation growth — log-log, slope &asymp; exponent</p>
<canvas id="profilerChart" class="profiler-chart" width="640" height="320" aria-label="Log-log chart of operations versus input size for every algorithm"></canvas>
<p id="profilerStatus" class="profiler-status" aria-live="polite"></p>
<div id="profilerTable" class="matrix-wrap"></div>
</section>

<section class="panel" id="comparisonPanel" hidden>
<h2 class="panel-title">Comparison Matrix</h2>
<p class="panel-sub">Theoretical vs actual performance (last tournament)</p>
Expand Down Expand Up @@ -264,6 +281,7 @@ <h3>Race</h3>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<div id="a11yAnnouncer" class="sr-only" aria-live="assertive" aria-atomic="true"></div>

<script src="sorting-core.js"></script>
<script src="script.js"></script>
</body>
</html>
Loading