Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AlgoVision - Algorithm Visualizer

React Vite Tailwind Framer Motion

An interactive algorithm visualizer for engineering students to understand algorithms step-by-step through beautiful animations.

AlgoVision Preview

✨ Features

Supported Algorithms

πŸ”’ Sorting Algorithms

Algorithm Time Complexity (Average) Space Complexity
Bubble Sort O(nΒ²) O(1)
Merge Sort O(n log n) O(n)
Quick Sort O(n log n) O(log n)

πŸ” Search Algorithms

Algorithm Time Complexity Space Complexity
Binary Search O(log n) O(1)

🌐 Graph Algorithms

Algorithm Time Complexity Space Complexity
Breadth First Search (BFS) O(V + E) O(V)
Depth First Search (DFS) O(V + E) O(V)
Dijkstra's Algorithm O(E log V) O(V)
Bellman-Ford Algorithm O(VE) O(V)
Floyd-Warshall Algorithm O(VΒ³) O(VΒ²)
Prim's Algorithm O(E log V) O(V)
Kruskal's Algorithm O(E log E) O(V)

Interactive Features

  • Step-by-step Visualization: Watch algorithms execute one step at a time
  • Speed Control: Adjust playback speed from Very Slow to Turbo
  • Play/Pause/Resume: Control the visualization playback
  • Previous/Next Step: Navigate through algorithm steps manually
  • Reset: Start over with fresh data
  • Custom Input:
    • Sorting: Adjustable array size, random generation, pre-sorted, reverse-sorted
    • Binary Search: Custom target value
    • Graph: Selectable start/end nodes
  • Pseudocode Panel: View algorithm pseudocode with highlighted active lines
  • Explanation Text: Real-time descriptions of what's happening at each step
  • Dark Mode: Modern UI with dark/light theme toggle

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/algo-visualizer.git
    cd algo-visualizer
  2. Install dependencies

    npm install
  3. Start the development server

    npm run dev
  4. Open in browser Navigate to http://localhost:5173

Build for Production

npm run build

The build output will be in the dist/ folder.


πŸ“ Project Structure

algo-visualizer/
β”œβ”€β”€ public/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ algorithms/          # Pure algorithm logic
β”‚   β”‚   β”œβ”€β”€ bubbleSort.js
β”‚   β”‚   β”œβ”€β”€ mergeSort.js
β”‚   β”‚   β”œβ”€β”€ quickSort.js
β”‚   β”‚   β”œβ”€β”€ binarySearch.js
β”‚   β”‚   └── graphAlgorithms.js
β”‚   β”œβ”€β”€ components/          # React UI components
β”‚   β”‚   β”œβ”€β”€ Controls.jsx
β”‚   β”‚   β”œβ”€β”€ SortingBoard.jsx
β”‚   β”‚   β”œβ”€β”€ GraphBoard.jsx
β”‚   β”‚   β”œβ”€β”€ Navbar.jsx
β”‚   β”‚   └── PseudocodePanel.jsx
β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”‚   └── useAlgoPlayer.jsx
β”‚   β”œβ”€β”€ utils/              # Utility functions
β”‚   β”‚   └── helpers.js
β”‚   β”œβ”€β”€ App.jsx
β”‚   β”œβ”€β”€ main.jsx
β”‚   └── index.css
β”œβ”€β”€ package.json
β”œβ”€β”€ tailwind.config.js
└── vite.config.js

🎨 Architecture

Trace/Snapshot Pattern

The core innovation of AlgoVision is the Trace/Snapshot Pattern:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ALGORITHM EXECUTION                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚   Algorithm Function                                            β”‚
β”‚        β”‚                                                        β”‚
β”‚        β”‚  Run instantly, generate all steps                     β”‚
β”‚        β–Ό                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
β”‚   β”‚ Trace Array β”‚  Each element is a "snapshot"                 β”‚
β”‚   │─────────────│  containing complete state                    β”‚
β”‚   β”‚ Step 0      β”‚  - Array/Graph state                          β”‚
β”‚   β”‚ Step 1      β”‚  - Comparison indices                         β”‚
β”‚   β”‚ Step 2      β”‚  - Swap operations                            β”‚
β”‚   β”‚ ...         β”‚  - Current line of pseudocode                 β”‚
β”‚   β”‚ Step N      β”‚  - Description text                           β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
β”‚                                                                 β”‚
β”‚   Playback Engine (useAlgoPlayer hook)                          β”‚
β”‚        β”‚                                                        β”‚
β”‚        β”‚  Simply plays back the trace                           β”‚
β”‚        β”‚  like a video                                          β”‚
β”‚        β–Ό                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
β”‚   β”‚   UI State  β”‚  React renders current step                   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benefits:

  • βœ… True Pause: Just stop the step counter
  • βœ… Rewind: Simply decrease the step counter
  • βœ… Speed Control: Change the interval duration
  • βœ… Smooth Animation: All computation happens upfront
  • βœ… Time Travel: Jump to any step instantly

πŸ”§ Customization

Adding a New Sorting Algorithm

  1. Create a new file in src/algorithms/:
// src/algorithms/newSort.js

export const generateNewSort = (array) => {
  const trace = [];
  const arr = [...array];

  // Initial state
  trace.push({
    array: [...arr],
    compare: [],
    swap: [],
    sorted: [],
    desc: "Starting New Sort",
    codeLine: 0,
  });

  // Your algorithm here...
  // Push snapshots to trace at each interesting step

  // Final state
  trace.push({
    array: [...arr],
    compare: [],
    swap: [],
    sorted: [...Array(arr.length).keys()],
    desc: "Sort Complete!",
    codeLine: 10,
  });

  return trace;
};

export const newSortPseudocode = ["START: ...", "...", "END: Array sorted"];
  1. Import and add to App.jsx:
import { generateNewSort, newSortPseudocode } from "./algorithms/newSort";

// Add to ALGORITHM_CATEGORIES.sorting
// Add to pseudocode switch statement

Adding a New Graph Algorithm

Graph algorithms follow a similar pattern but work with the graph object structure:

trace.push({
  graph: { nodes: [...graph.nodes], edges: [...graph.edges] },
  visited: [...visited],
  highlight: [currentNode],
  edgesHighlight: [{ from: current, to: neighbor }],
  distances: { ...distances },
  parentMap: { ...parentMap },
  desc: "Description of current step",
  codeLine: 1,
});

🎯 Learning Outcomes

This project helps students understand:

  1. Algorithm Fundamentals: How basic sorting and search algorithms work
  2. Time Complexity: Visual difference between O(nΒ²), O(n log n), O(log n), O(VE), and O(VΒ³)
  3. Data Structure Traversal: How BFS/DFS explore graphs differently
  4. Shortest Path: How Dijkstra's, Bellman-Ford, and Floyd-Warshall find optimal paths in weighted graphs
  5. Minimum Spanning Tree: How Prim's and Kruskal's algorithms build optimal spanning trees
  6. Visual Debugging: Step through algorithms to understand each operation

πŸ› οΈ Tech Stack

Technology Purpose
React 18 UI component library
Vite 5 Fast build tool and dev server
TailwindCSS 3 Utility-first styling with dark mode
Framer Motion Smooth animations for bars and nodes
Lucide React Beautiful icon set
ESLint Code linting

πŸ“ License

MIT License - feel free to use for learning and teaching!


🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


πŸ“š Resources for Learning


Built for Engineering Students

About

A high-performance, animation-driven algorithm visualizer designed to help engineering students understand core algorithms through step-by-step execution, real-time state tracing, and intuitive visual feedback. Built with React, Vite, Tailwind CSS, and Framer Motion, it transforms complex algorithmic concepts into an interactive learning experience

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages