"Watch algorithms think, then race them on bare metal to prove the math."
An enterprise-grade, browser-native Computer Science research and interactive visualization platform that bridges the divide between theoretical computational complexity and physical hardware execution. Built from the ground up on modern web primitives, AlgoVisualizer combines fine-grained time-traveling ES6 generator visualizations, a multi-threaded Web Worker benchmarking engine capable of processing millions of elements, an in-browser Monaco Editor algorithm sandbox, a symbolic Master Theorem solver, and a dynamic 5-palette HSL theming system.
- Core Philosophy: Theory vs. Reality
- Project Architecture & Directory Structure
- Deep-Dive Engineering Highlights
- 1. Time-Traveling State Machines via ES6 Generators
- 2. Multi-Threaded Bare-Metal Benchmarking via Web Workers
- 3. Monaco Code Editor & Live Custom Algorithm Sandbox
- 4. Radial Linked List Geometry & Framer Motion Morphing
- 5. Expression Tree (AST) & Notation Converter
- 6. Symbolic Master Theorem & Recurrence Engine
- 7. Extreme Performance Polish & Anti-Lag Optimizations
- Algorithm & Data Structure Suite
- Dynamic Theming System
- Getting Started & Installation
- Production Verification & Build
- License
Academic computer science traditionally models algorithms under the theoretical RAM model (Random Access Machine), which presumes uniform memory access latency and ignores physical hardware factors. In reality, execution speed is dictated by:
-
CPU Cache Spatial & Temporal Locality (
$L1/L2/L3$ caches vs. DRAM fetch cycles) - Branch Prediction & Pipeline Stalls
- V8 JIT Hidden Classes, Inline Caching, and Monomorphic Typing
- Garbage Collection (GC) pauses and memory fragmentation
AlgoVisualizer makes these phenomena tangible:
-
Bubble Sort vs. Quick Sort: While asymptotic theory proves
$\mathcal{O}(n^2)$ vs.$\mathcal{O}(n \log n)$ , physical execution shows Bubble Sort collapsing exponentially past$10,000$ integers due to massive write-pipeline thrashing, while Quick Sort sorts millions of integers in milliseconds. -
Cache Locality in Action: In-place Heap Sort vs. Merge Sort illustrates how pointer chasing and non-contiguous memory access in heap trees can lag behind sequential array scans despite sharing
$\mathcal{O}(n \log n)$ upper bounds. -
Empirical Theoretical Overlays: By computing the scaling constant
$C = \frac{\text{Time}(N_{\max})}{f(N_{\max})}$ , the benchmarking lab superimposes asymptotic curves ($\mathcal{O}(n \log n), \mathcal{O}(n^2), \mathcal{O}(n)$) directly over real execution data to prove where theory and reality converge.
AlgoVisualizer/
βββ .gitignore # Git exclusion configuration for builds, dependencies, and caches
βββ README.md # Master project manual, architecture documentation, and guide
βββ index.html # Single Page Application HTML entry point with fonts and root DOM
βββ package.json # NPM package manifest, scripts, and runtime/development dependencies
βββ package-lock.json # Deterministic dependency lockfile ensuring reproducible installs
βββ postcss.config.js # PostCSS toolchain configuration for Tailwind CSS and Autoprefixer
βββ tailwind.config.js # Custom Tailwind CSS theme extensions, color tokens, and animations
βββ vite.config.js # Vite build configuration, worker bundling, and manual chunking
β
βββ src/
βββ App.jsx # Root application component orchestrating view routing and themes
βββ index.css # Global styles declaring dynamic HSL theme CSS variables
βββ main.jsx # React 18 bootstrap entry point mounting App to the DOM
β
βββ components/
β βββ BenchmarkLab.jsx # Multi-threaded benchmark lab with Monaco Sandbox and Recharts
β βββ Home.jsx # Interactive overview dashboard with feature cards and metrics
β βββ MathLab.jsx # Symbolic Master Theorem solver, tree visualizer, and Big-O curves
β βββ Navigation.jsx # Application navigation bar, tab switcher, and theme selector modal
β βββ VisualizerView.jsx # Interactive Sorting and Searching execution canvas and debugger
β β
β βββ DataStructures/
β βββ ExpressionConverterView.jsx # Infix to Postfix/Prefix expression tree converter and tracer
β βββ GraphView.jsx # Graph algorithms visualizer (Dijkstra shortest path & Kruskal MST)
β βββ LinkedListView.jsx # Radial circular, singly, and doubly linked list visualizer
β βββ StackQueueView.jsx # Linear LIFO stack and FIFO queue visualizer with spring animations
β βββ TreeView.jsx # Self-balancing AVL tree visualizer with real-time balancing rotations
β
βββ core/
β βββ algorithms/
β β βββ graphs/
β β β βββ dijkstra.js # Generator-based Dijkstra shortest path algorithm with live tables
β β β βββ kruskal.js # Generator-based Kruskal Minimum Spanning Tree with Union-Find
β β β
β β βββ raw/
β β β βββ binarySearch.js # Bare-metal iterative Binary Search for nanosecond hardware benchmarks
β β β βββ bubbleSort.js # Bare-metal iterative Bubble Sort for CPU race benchmarks
β β β βββ heapSort.js # Bare-metal in-place Heap Sort for CPU race benchmarks
β β β βββ index.js # Central export barrel and registry of all raw benchmark algorithms
β β β βββ linearSearch.js # Bare-metal iterative Linear Search for CPU race benchmarks
β β β βββ mergeSort.js # Bare-metal buffer-allocated Merge Sort for CPU race benchmarks
β β β βββ quickSort.js # Bare-metal in-place Quick Sort for CPU race benchmarks
β β β
β β βββ searching/
β β β βββ binarySearch.js # Generator-based Binary Search with dynamic search-window dimming
β β β βββ linearSearch.js # Generator-based Linear Search with sequential pointer tracking
β β β
β β βββ sorting/
β β β βββ bubbleSort.js # Generator-based Bubble Sort yielding comparison and swap states
β β β βββ heapSort.js # Generator-based Heap Sort yielding max-heapify and extract states
β β β βββ mergeSort.js # Generator-based Merge Sort with recursive divide-and-conquer delegation
β β β βββ quickSort.js # Generator-based Quick Sort with Lomuto partitioning delegation
β β β
β β βββ trees/
β β βββ avlTree.js # AVL Tree class with LL/RR/LR/RL rotation step generator engines
β β βββ expressionTree.js # Shunting-Yard AST parser and Postfix/Prefix traversal generators
β β
β βββ math/
β β βββ curveFitter.js # Theoretical asymptotic curve fitting and scaling engine
β β βββ masterTheorem.js # Regex-based Master Theorem recurrence relation parser and solver
β β
β βββ utils/
β βββ graphData.js # Preset graph topologies (Wheel, Grid, Bottleneck) and coordinate mappers
β βββ treeLayout.js # Node and edge coordinate layout generator for binary and expression trees
β
βββ workers/
βββ benchmark.worker.js # Dedicated Web Worker executing CPU-intensive benchmarks in background thread
| File | Exact Purpose & Functionality |
|---|---|
.gitignore |
Configures files and directories excluded from version control, such as node_modules/, dist/, .env, build artifacts, and system scratch directories. |
README.md |
The primary engineering documentation, architecture overview, project directory structure file-by-file guide, and getting started instructions. |
index.html |
The single HTML document loaded by the browser. Injects Google Fonts (Inter, JetBrains Mono), sets up the viewport, declares the application title, and provides the <div id="root"> anchor for React. |
package.json |
The project's package manifest. Defines project metadata, npm build/dev scripts, runtime dependencies (react, framer-motion, recharts, lucide-react, @monaco-editor/react, canvas-confetti), and dev tools (vite, tailwindcss, postcss, autoprefixer). |
package-lock.json |
Automatically generated lockfile pinning exact semantic versions of all direct and transitive npm dependencies to guarantee deterministic builds across environments. |
postcss.config.js |
Configures the PostCSS transformation pipeline to load Tailwind CSS and Autoprefixer, injecting browser vendor prefixes for modern CSS rules. |
tailwind.config.js |
Configures Tailwind CSS styling rules, custom font families (font-sans, font-mono), transition durations, and theme color classes wired directly into dynamic HSL CSS variables (--color-bg, --color-surface, --color-primary, etc.). |
vite.config.js |
Configures the Vite development server (port 3000), enables the official React plugin (@vitejs/plugin-react), configures Web Worker bundling formats, and sets custom Rollup manualChunks partitioning for code splitting large dependencies (recharts, framer-motion). |
| File | Exact Purpose & Functionality |
|---|---|
src/main.jsx |
The client-side entry point that initializes the React application root using ReactDOM.createRoot() and renders <App /> into the DOM. |
src/index.css |
Core stylesheet defining CSS root tokens, dynamic theme definitions (Default Dark, Minimal Light, Ocean Depths, Tech Innovation, Arctic Frost), typography defaults, scrollbar customization, and utility styles. |
src/App.jsx |
The master application component. Manages top-level navigation states (home, visualizer, data-structures, trees, equation-converter, graphs, benchmark, recurrence), dynamic theme switching, responsive mobile navigation drawers, and code-split component rendering with <Suspense>. |
| File | Exact Purpose & Functionality |
|---|---|
src/components/Navigation.jsx |
Top navigation bar component rendering brand identity, primary navigation links with active indicators, theme selector modal button, and mobile menu toggles. |
src/components/Home.jsx |
Overview landing page featuring animated hero copy, quick-action cards launching specific modules, theory vs. hardware execution summaries, and system architectural badges. |
src/components/VisualizerView.jsx |
Core execution canvas for sorting (Bubble, Quick, Merge, Heap) and searching (Linear, Binary) algorithms. Includes playback controls (Play, Pause, Step, Reset), execution speed sliders, custom array generators (Random, Reversed, Nearly Sorted), line-by-line code inspector, and state telemetry. |
src/components/BenchmarkLab.jsx |
The bare-metal hardware benchmarking dashboard. Dispatches sorting/searching algorithms to dedicated Web Workers, scales datasets from 10 to 5,000,000 elements, embeds a live Monaco Code Editor for running custom JavaScript algorithms, and displays real-time Recharts execution graphs with theoretical asymptotic curve fitting. |
src/components/MathLab.jsx |
Mathematical analysis laboratory featuring an interactive Master Theorem recurrence relation solver with regex parsing, step-by-step recursion tree breakdown, and an interactive Big-O complexity comparator graph. |
| File | Exact Purpose & Functionality |
|---|---|
src/components/DataStructures/LinkedListView.jsx |
Advanced Linked List visualizer supporting Singly, Doubly, and Circular Linked Lists. Features a literal radial circle layout engine with trigonometric node placement, orbital guide tracks, spring-physics morphing between linear and circular topologies, and animated pointer step-by-step traversal. |
src/components/DataStructures/StackQueueView.jsx |
Linear data structures visualizer demonstrating LIFO Stack mechanics (push, pop, peek, overflow protection) and FIFO Queue operations (enqueue, dequeue, capacity tracking) using Framer Motion animations. |
src/components/DataStructures/TreeView.jsx |
Interactive self-balancing AVL Tree visualizer displaying dynamic balance factors, height updates, and animated Left (LL), Right (RR), Left-Right (LR), and Right-Left (RL) balancing rotations with memoized SVG edge connectors and subpixel debounce optimizations. |
src/components/DataStructures/ExpressionConverterView.jsx |
Interactive Expression Tree visualizer. Parses mathematical infix equations into a binary AST via Shunting-Yard logic, renders the tree with memoized SVG connectors, and dynamically animates Postfix (RPN) and Prefix (Polish) traversals with a live Result HUD. |
src/components/DataStructures/GraphView.jsx |
Graph visualizer supporting Dijkstra's Shortest Path and Kruskal's Minimum Spanning Tree algorithms across Wheel, City Grid, and Bottleneck topologies. Features edge weight randomization, live priority queue telemetry, and plain-English real-world analogies. |
| File | Exact Purpose & Functionality |
|---|---|
src/core/algorithms/sorting/bubbleSort.js |
Generator-based Bubble Sort algorithm yielding comparison pairs, swap events, and confirmed sorted boundary indices for real-time visual playback. |
src/core/algorithms/sorting/quickSort.js |
Generator-based Quick Sort with Lomuto partitioning. Uses recursive generator delegation (yield*) to animate active subarray bounds, pivot selections, and partition swaps. |
src/core/algorithms/sorting/mergeSort.js |
Generator-based Merge Sort. Implements divide-and-conquer recursion via yield*, tracking subarray splitting, auxiliary buffer states, and animated value write-backs. |
src/core/algorithms/sorting/heapSort.js |
Generator-based Heap Sort. Visually illustrates initial max-heap building, recursive sift-down operations, and root-to-end element extractions. |
src/core/algorithms/searching/linearSearch.js |
Generator-based Linear Search yielding current index pointer examinations, target match confirmations, and target-not-found completions. |
src/core/algorithms/searching/binarySearch.js |
Generator-based Binary Search yielding low, mid, and high pointer movements while computing eliminated subarray ranges for dynamic visual dimming. |
src/core/algorithms/graphs/dijkstra.js |
Generator-based Dijkstra algorithm with greedy relaxation, yielding node extractions, neighbor edge evaluations, distance table updates, and shortest-path backtraces. |
src/core/algorithms/graphs/kruskal.js |
Generator-based Kruskal MST algorithm. Employs Disjoint Set Union (Union-Find with path compression), yielding sorted edge evaluations, accepted tree edges, and discarded cycle edges. |
src/core/algorithms/trees/avlTree.js |
Self-balancing AVL Tree implementation. Provides methods for node insertion, height and balance factor updates, and generator functions for Left and Right rotations that yield step-by-step visual snapshots. |
src/core/algorithms/trees/expressionTree.js |
Expression Tree engine parsing infix mathematical strings using a stack-based Shunting-Yard AST algorithm. Contains generator functions for buildExpressionTree, getPostfix (Post-order), getPrefix (Pre-order), and getInfix (In-order). |
| File | Exact Purpose & Functionality |
|---|---|
src/core/algorithms/raw/bubbleSort.js |
Hyper-optimized in-place iterative Bubble Sort stripped of all generator and UI overhead for pure CPU microsecond benchmarking. |
src/core/algorithms/raw/quickSort.js |
High-performance in-place Quick Sort implementation using 3-way/Lomuto partitioning tuned for bare-metal V8 execution. |
src/core/algorithms/raw/mergeSort.js |
High-throughput Merge Sort implementation utilizing pre-allocated auxiliary buffers for optimal hardware benchmarking without garbage collection spikes. |
src/core/algorithms/raw/heapSort.js |
In-place bare-metal iterative Heap Sort implementation designed for continuous memory benchmarks. |
src/core/algorithms/raw/linearSearch.js |
Minimalist iterative sequential search implementation measuring raw CPU instruction cycle execution on arrays up to 5,000,000 integers. |
src/core/algorithms/raw/binarySearch.js |
Zero-overhead iterative Binary Search function measuring logarithmic search speeds on sorted datasets in nanoseconds. |
src/core/algorithms/raw/index.js |
Central registry exposing raw algorithms, metadata, theoretical complexities, and benchmark runner dispatch hooks. |
| File | Exact Purpose & Functionality |
|---|---|
src/core/math/masterTheorem.js |
Symbolic recurrence relation parser that extracts parameters |
src/core/math/curveFitter.js |
Empirical curve fitting utility that normalizes theoretical asymptotic functions ( |
src/core/utils/graphData.js |
Graph topology presets (Wheel, City Grid, Bottleneck map), normalized coordinate maps, edge weight generators, and responsive canvas coordinate scaling utilities. |
src/core/utils/treeLayout.js |
Deterministic tree layout engine computing |
| File | Exact Purpose & Functionality |
|---|---|
src/workers/benchmark.worker.js |
Dedicated Web Worker operating on an isolated OS background thread. Handles dataset generation, V8 JIT warmup iterations, high-precision performance.now() microsecond timing, safe execution of user-submitted Monaco Editor code, and asynchronous progress reporting back to the main UI. |
Standard educational visualizers rely on crude setTimeout loops or recursive callbacks that freeze the main thread, cause memory leaks, or cannot pause or reverse.
AlgoVisualizer designs every algorithm as a pure ES6 generator function (function* and yield*):
- Deterministic Step-by-Step Traversal: The UI controls execution using
.next(), pulling immutable snapshots only when needed. - Recursive Generator Delegation: Complex recursive algorithms (Quick Sort, Merge Sort) delegate execution to subproblems using
yield*, retaining standard call stack semantics while preserving pause and step capabilities. - Spring-Physics Rendering: State snapshots are rendered via Framer Motion layout projections. When array elements swap or AVL trees undergo rotations, nodes smoothly glide across screen coordinates.
Visualizers with animation overhead cannot accurately benchmark raw execution speeds. To measure genuine computational throughput:
-
Dedicated Web Worker Offloading: Raw, bare-metal algorithm implementations run in an isolated V8 thread (
benchmark.worker.js) via Vite's?workermodule syntax. -
Zero UI Stutter: Benchmarking executes datasets up to
$5,000,000$ integers on background threads without locking the 60fps main UI thread. -
V8 JIT Warmup & Monomorphic Typing: Benchmark runs execute warmup iterations to ensure V8 optimizes hot loops. Large datasets utilize typed
Int32Arraybuffers for high-density cache utilization. -
High-Precision Timing: Execution runtimes are measured using
performance.now()microsecond timestamps and streamed back via typed worker messages to interactive Recharts visualizations.
The Benchmarking Lab integrates a full in-browser IDE powered by Monaco Editor (@monaco-editor/react):
- Write custom sorting or searching algorithms directly in JavaScript.
- Monaco provides full syntax highlighting, bracket matching, line numbering, and dark theme support.
- Code is compiled into a self-executing function and executed inside the Web Worker against native algorithms across matching dataset sizes.
In LinkedListView.jsx, the Circular Linked List variant renders in a literal mathematical circle rather than a straight line with a wrapped arrow:
-
Trigonometric Coordinate System:
$$c_x = \frac{\text{width}}{2}, \quad c_y = \frac{\text{height}}{2}, \quad R = \max\left(130, \min(R_{\max}, \max(150, N \times 25))\right)$$ $$\theta_i = \left(\frac{i}{N}\right) \times 2\pi - \frac{\pi}{2}$$ $$x_i = c_x + R \cdot \cos(\theta_i), \quad y_i = c_y + R \cdot \sin(\theta_i)$$ -
Topological Morphing: Nodes use
<motion.div layout layoutId={ll-node-${node.id}}>. When switching between Singly/Doubly (linear coordinates) and Circular (radial coordinates), Framer Motion calculates bounding box deltas and smoothly swings the nodes into a circle. -
Closing Directed Arrow: A dedicated SVG arrow connects the last node
$(N-1)$ directly back to the head node$(0)$ , completing the visual ring.
In expressionTree.js and ExpressionConverterView.jsx:
-
Shunting-Yard AST Generation: Parses infix mathematical expressions (e.g.
(a+b)*(c-d)ora+b*c^d) into a binary Expression Tree respecting operator precedence (^>*,/,%>+,-) and parentheses. -
Interactive Traversal Tracers:
-
Postfix (RPN): Post-order generator (Left
$\to$ Right$\to$ Root) tracing token-by-token evaluation. -
Prefix (Polish): Pre-order generator (Root
$\to$ Left$\to$ Right) tracing expression generation. -
Infix: In-order generator (Left
$\to$ Root$\to$ Right) reconstructing parenthesized infix expressions.
-
Postfix (RPN): Post-order generator (Left
- Dynamic Result HUD: Bottom telemetry bar displaying animated token chips as they are generated in real time.
In masterTheorem.js and MathLab.jsx:
-
Regex Equation Parser: Parses recurrence relations of the form:
$$T(n) = aT(n/b) + \Theta(n^d)$$ -
Analytical Solver:
- Computes critical exponent
$c_{\text{crit}} = \log_b(a)$ . - Compares
$c_{\text{crit}}$ against$d$ to classify into:-
Case 1 (
$c_{\text{crit}} > d$ ): Tree-heavy work$\implies \Theta(n^{\log_b a})$ . -
Case 2 (
$c_{\text{crit}} = d$ ): Balanced work across all levels$\implies \Theta(n^d \log n)$ . -
Case 3 (
$c_{\text{crit}} < d$ ): Root-heavy work$\implies \Theta(n^d)$ .
-
Case 1 (
- Computes critical exponent
- Recursion Tree Visualization: Generates level-by-level breakdowns showing node count, subproblem size, and work per level.
To eliminate rendering jank and layout thrashing across all visualizers:
-
Debounced Resize Observers: Container
ResizeObserverinstances ignore subpixel noise ($< 4\text{px}$ variations), preventing unnecessary layout recalculation cycles. -
Memoized Layout & SVG Elements: Tree coordinate calculations (
calculateTreeLayout) and rendered SVG<line>elements are wrapped inuseMemo, recalculating only when tree structure or dimensions change. -
Framer Motion Layout ID Caching: Every node uses persistent keys and
layoutIdprops (tree-node-${id},expr-node-${id},graph-node-${id},ll-node-${id}), enabling GPU transform animations without unmounting or remounting DOM elements. -
GPU-Accelerated SVG Edge Transitions: Replaced heavy motion line projections with standard SVG
<line>elements styled with CSS GPU transitions (will-change: x1, y1, x2, y2), offloading edge updates to the compositor.
| Category | Structure / Algorithm | Theoretical Complexity | Visual & Engineering Highlight |
|---|---|---|---|
| Sorting | Bubble Sort | Real-time comparison highlights, animated pointer swaps, sorted bounds | |
| Sorting | Quick Sort | Lomuto partitioning, recursive generator delegation (yield*), active pivot |
|
| Sorting | Merge Sort | Divide-and-conquer splitting, auxiliary buffer tracking, animated writes | |
| Sorting | Heap Sort | Max-heap construction, sift-down restructuring, root-to-tail extraction | |
| Searching | Binary Search | Dynamic low/mid/high pointers, out-of-scope window dimming |
|
| Searching | Linear Search | Sequential index scanning, target match and not-found confirmations | |
| Linear Data Structures | Singly Linked List |
|
Dynamic pointer-following traversal, animated head/tail insertions |
| Linear Data Structures | Doubly Linked List |
|
Bidirectional pointer visualization (Next -> and <- Prev) |
| Linear Data Structures | Circular Linked List |
|
Radial Circle Layout ( |
| Linear Data Structures | Stack (LIFO) |
|
Top-pointer tracking, peek operations, capacity limit safeguards |
| Linear Data Structures | Queue (FIFO) |
|
Head dequeue slide-out, tail enqueue entry, capacity indicators |
| Self-Balancing Trees | AVL Tree |
|
Live balance factor indicators, Left/Right/LR/RL balancing rotations |
| Expression Trees | Infix |
|
Shunting-Yard AST builder, Post-order & Pre-order visual tracer |
| Graphs | Dijkstra's Algorithm | Greedy relaxation, live distance cost table, backtrace shortest path | |
| Graphs | Kruskal's Algorithm | Disjoint Set Union (Union-Find), cycle rejection, MST construction |
AlgoVisualizer features a dynamic theming system built on CSS custom properties. Switching themes instantly updates all UI components, SVGs, charts, and background layers without a full-page reload:
- Modern Minimalist (Dark) (Default): Slate and charcoal backdrop with glowing emerald, cyan, and amber telemetry accents.
- Modern Minimalist (Light): High-contrast paper aesthetic with crisp zinc borders and subtle shadows.
- Ocean Depths: Deep marine abyss styling with cyan, aqua, and deep sea tones.
- Tech Innovation: High-voltage electric blue accents on graphite surfaces.
- Arctic Frost: Cold glacial blue palette with crisp border highlights.
-
Clone the repository:
git clone https://github.com/Prakhar-Sethi012/AlgoVisualizer.git cd AlgoVisualizer -
Install project dependencies:
npm install
-
Start the local development server:
npm run dev
Open your browser and navigate to
http://localhost:3000.
To compile an optimized production distribution with manual chunking and Web Worker asset bundling:
npm run buildTo preview the production bundle locally:
npm run previewThis project is licensed under the MIT License.