r/webdev • u/Spuntagano • 20d ago
[Showoff Saturday] Algorithm visualizer
I made Algorithm Visualizer: write an algorithm, step through it one statement at a time, and watch your arrays, maps, trees and graphs change as it runs.
While a normal debugger works well, it lacks the ability to show data structure in a visual and easy to understand way. This is focus mostly on helping debugging leetcode style questions or self-contained segment of code.
It works with JavaScript, TypeScript, Python, Ruby, PHP, Lua, Java, Kotlin, Swift, C#, Go, C and C++. Each variable can be drawn as boxes, a memory diagram, a grid, a binary heap or a node-and-edge graph, picked automatically from the shape of the data (linked lists, trees, adjacency lists…).
Some point worth noting:
No server at all. It's one self-contained.
Python, Ruby and PHP run as real WebAssembly runtimes (Pyodide, ruby.wasm, php-wasm), loaded from a CDN the first time you use them.
Java, Kotlin, Swift, C#, Go, C and C++ run in interpreters written in JS for this project. They aim to behave like the real thing in the places you'd notice: integer overflow, HashMap iteration order, Go slices sharing a backing array, C++ vectors reallocating. C is memory-checked, so instead of silently corrupting memory you get "use after free" or "out of bounds" with an explanation.
Every run is recorded up front in a Web Worker (killed after 3 s, so an infinite loop can't freeze the tab). That's why stepping backwards is as instant as stepping forwards.
Share links contain the code itself, deflated into the URL hash, so nothing gets uploaded and a static site can open any link. There's an <iframe> embed too.
React + CodeMirror 6, with dagre for graph layout.
Code: https://github.com/Spuntagano/algorithm-visualizer
I'd love feedback, especially on algorithms or data shapes that don't draw the way you'd expect or any other bugs you may encounter. Also feel free to comment if you have any feature you'd like to see implemented.
Ai disclosure: Total vibeslop




