Algorithm Laboratory
Eighteen interactive topic workspaces, one replayable idea: generate algorithm states once, then keep the visualization, explanation, and code on the same step.
| Role | Visualization engine, learning interactions, and frontend implementation |
| Stack | React, TypeScript, Next.js, Zustand, SVG/CSS, React Flow, and Dagre |
| Scope | Eighteen topic workspaces, algorithm-frame generators, playback controls, pseudocode, and a sorting-factory demonstration |
| Product context | The visualizer is part of Learnly, the LMS platform; it is not a separate backend service |
| Live workspace | Open Algorithm Laboratory |
| Source | github.com/avesh-pathak/opensource-lms |
Overview
An algorithm can be correct and still be difficult to understand. A student sees the input and the answer but misses the decisions in between: which pointer moved, which comparison eliminated a region, or why a recursive call returned.
Algorithm Laboratory makes those intermediate states inspectable. It spans arrays, sorting, strings, linked lists, stacks, queues, hashing, recursion, trees, heaps, tries, graphs, greedy methods, dynamic programming, backtracking, bit manipulation, sliding windows, and two pointers.
The central engineering decision is to separate computing an algorithm from playing its explanation. A generator produces a sequence of states. The interface displays one state at a time. Pausing or stepping backward changes the frame index, not the algorithm's execution history.
The learning problem
An animation that simply runs from beginning to end is a presentation. A learning tool needs interruption: replay the comparison, inspect the variables, and move backward without losing context.
Three constraints shaped the implementation:
- One step must mean the same thing everywhere. The highlighted values, explanation, comparison count, and active code line should describe the same event.
- Structures need different canvases. A queue, a tree, and a bit mask cannot all be explained by bars moving horizontally.
- Small examples should expose decisions. These are teaching inputs, not throughput benchmarks. A visible pointer change is more useful than processing a million elements.
My contributions
The work connects algorithm implementation to the learning interface: frame generation, category stores, step controls, explanations, code-line metadata, and structure-specific canvases. It also includes the separate sorting-factory scene on Learnly's landing page.
The important distinction is scope: 18 topic workspaces does not mean every option in every selector has equal implementation depth. The gallery records all topic routes, while the architecture discussion below is grounded in implemented examples such as search, bubble sort, graph traversal, Fibonacci DP, and subsets.
Engine architecture
The shared frame shape carries the sequence, primary and secondary highlights, visited indices, named pointers, explanation, active pseudocode line, variables, comparison count, and phase. Optional fields represent active ranges, sorted regions, swapped values, graph nodes and edges, or grids.
Not every category forces its data into exactly the same interface. Backtracking, for example, has a compact frame containing discovered subsets and the current path. The reusable boundary is a sequence plus a cursor, with a canvas that understands its own frame type.
Snapshot the state, not its mutable reference
Bubble sort is a useful example. The generator clones the input, emits an initial state, then emits comparison, pre-swap, post-swap, and pass-completion states. It finishes with the sorted sequence and can exit early after a pass with no swaps.
Every stored array is copied. If all frames pointed at the same working array, a later swap would rewrite the past; stepping backward would show the final answer rather than the earlier state.
frames.push({
array: [...array],
highlights: [j, j + 1],
pointers: { j, 'j+1': j + 1 },
explanation: `Comparing indices ${j} and ${j + 1}`,
activeLine: 3,
comparisons,
// Other frame fields omitted here for clarity.
})
Random input generation belongs outside this computation. Given the same explicit input, a generator can produce the same trace regardless of playback speed.
Playback and rendering
The category store owns the input, generated frames, cursor, play state, and speed. Next and previous move within the frame sequence; reset returns to the beginning and pauses. Playback uses a timer whose cadence changes with the speed multiplier, rather than rerunning the algorithm at a faster rate.
The array and sorting canvases express indices and comparisons directly. Linked structures use nodes and edges; graph and tree views can use layout helpers and React Flow. DP emphasizes table or sequence values, bit manipulation uses binary cells, and sliding-window/two-pointer views make boundaries explicit.
The desktop workspace pairs a primary canvas with explanation and code panels. On smaller screens those panels stack. The public screenshots show the actual UI, including the differences between category controls; they are not mocked illustrations of unimplemented screens.
Screenshot atlas
All 18 topic workspaces are documented below. These are real browser captures of representative states, not an assertion that every algorithm choice in the catalogue is complete. Each image opens a larger local copy; the page does not embed live remote applications or run a browser for each visitor.


















The sorting factory
The landing-page factory is a separate rendering of bubble sort, not the canvas used by every topic. Numbered blocks move between fixed stations, a scanner compares adjacent values, and grippers swap the pair only when the generated event requires it.
Its events include COMPARING, NO_SWAP, SWAPPING, ELEMENT_SETTLED, PASS_COMPLETED, and SORT_COMPLETED. Each carries the resulting values, block layout, current pair, comparisons, swaps, pass, and settled suffix.
Stable identity matters here. layout[i] identifies the block standing at array index i; swapping two equal-looking values must still move the correct objects. Keeping identity separate from value lets the renderer animate persistent blocks instead of replacing DOM elements whenever the order changes.
This factory makes a useful first impression, while the full laboratory prioritizes explicit code, variables, and topic-specific structures.
Trade-offs and next steps
| Decision | What it enables | Cost or boundary |
|---|---|---|
| Precomputed frames | Replay, backward stepping, and reproducible traces | Memory grows with input size and emitted steps |
| Category-specific stores | Natural inputs for different structures | Shared controls need adapters for slightly different store APIs |
| Explanation and active line in each frame | A shared source for the visual and textual story | Metadata must be maintained alongside pseudocode changes |
| Small teaching inputs | Legible decisions and manageable traces | Not a substitute for algorithm benchmarking |
| Broad topic catalogue | Exploration across 18 areas | Some selector options still need generators or deeper examples |
The next quality gate is a systematic generator contract: input immutability, independent snapshots, expected terminal result, valid code-line references, and bounded frame counts. Some modules already express these properties directly; the repository does not justify claiming a comprehensive automated test suite for every topic.
The result is a learning interface where the algorithm owns the facts and the player owns time. The same input can be examined slowly, quickly, forward, or backward without asking the animation layer to become an algorithm interpreter.