Skip to content

1001api/algo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

banner

Algorithm Visualizer

An interactive web application for visualizing algorithms and data structures, built with SvelteKit 5 and TypeScript. This project provides real-time visual demonstrations of Big O complexity, sorting algorithms, and pathfinding algorithms.

✨ Features

πŸ”’ Big O Complexity Analysis

  • Interactive Algorithm Comparison: Visualize and compare time complexity of different algorithms
  • Real-time Performance Tracking: Measure actual execution time using Web Workers
  • Supported Complexities:
    • O(1) - Constant time
    • O(log n) - Logarithmic time
    • O(n) - Linear time
    • O(n log n) - Linearithmic time
    • O(nΒ²) - Quadratic time
    • O(nΒ³) - Cubic time
    • O(2ⁿ) - Exponential time
    • O(n!) - Factorial time
  • Dynamic Charts: Visualize algorithm performance with Chart.js
  • Predefined Examples: Auto-play feature to demonstrate all algorithms

πŸ”„ Sorting Algorithm Visualizations

  • Bubble Sort: O(nΒ²) comparison-based sorting
  • Selection Sort: O(nΒ²) in-place sorting
  • Insertion Sort: O(nΒ²) adaptive sorting
  • Merge Sort: O(n log n) divide-and-conquer
  • Quick Sort: O(n log n) efficient partitioning
  • Visual Bars: Real-time animated bar chart representation
  • Keyboard Controls: Quick access with keyboard shortcuts

πŸ—ΊοΈ Pathfinding Algorithm Visualizations

  • Dijkstra's Algorithm: Shortest path with weighted edges
  • A Algorithm*: Heuristic-based pathfinding
  • Breadth-First Search (BFS): Unweighted shortest path
  • Depth-First Search (DFS): Graph traversal exploration
  • Interactive Grid: Click to create walls/obstacles
  • Drag & Drop: Paint walls by dragging
  • Grid Sizes: Tiny (10Γ—10) to Huge (70Γ—150)
  • Save/Load: Persist grid configurations locally

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ or Bun
  • npm, pnpm, or bun package manager

Installation

# Clone the repository git clone <repository-url> cd algo # Install dependencies npm install # or bun install

Development

Start the development server:

npm run dev # or bun run dev # Open in browser npm run dev -- --open

The application will be available at http://localhost:5173

Building for Production

npm run build

Preview the production build:

npm run preview

πŸ› οΈ Tech Stack

πŸ“ Project Structure

algo/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ components/ # Reusable UI components β”‚ β”‚ β”œβ”€β”€ BigOChart.svelte β”‚ β”‚ β”œβ”€β”€ BigOOutputChart.svelte β”‚ β”‚ β”œβ”€β”€ Highlighter.svelte β”‚ β”‚ β”œβ”€β”€ KeyboardHandler.svelte β”‚ β”‚ β”œβ”€β”€ loading/ β”‚ β”‚ └── navbars/ β”‚ β”œβ”€β”€ data/ # Data structures and algorithm logic β”‚ β”‚ β”œβ”€β”€ big-o.ts # Big O algorithm implementations β”‚ β”‚ β”œβ”€β”€ sort.ts # Sorting algorithms β”‚ β”‚ β”œβ”€β”€ path.ts # Pathfinding utilities β”‚ β”‚ β”œβ”€β”€ pq.ts # Priority Queue implementation β”‚ β”‚ β”œβ”€β”€ q.ts # Queue implementation β”‚ β”‚ β”œβ”€β”€ state.svelte.ts # Svelte 5 state management β”‚ β”‚ └── swap.ts # Array swap utility β”‚ β”œβ”€β”€ services/ # Background services β”‚ β”‚ β”œβ”€β”€ worker.ts # Web Worker manager β”‚ β”‚ └── background.ts # Background task handler β”‚ β”œβ”€β”€ routes/ # SvelteKit routes β”‚ β”‚ β”œβ”€β”€ +page.svelte # Big O visualization page β”‚ β”‚ β”œβ”€β”€ sort/ # Sorting algorithms page β”‚ β”‚ └── path/ # Pathfinding page β”‚ └── app.css # Global styles β”œβ”€β”€ static/ # Static assets β”œβ”€β”€ package.json β”œβ”€β”€ svelte.config.js β”œβ”€β”€ tailwind.config.js β”œβ”€β”€ tsconfig.json └── vite.config.ts 

⌨️ Keyboard Shortcuts

Sorting Page

  • Alt + R: Randomize array
  • Ctrl + Space: Play animation
  • Delete: Stop animation

Pathfinding Page

  • Alt + S: Set start point
  • Alt + E: Set end point
  • Alt + R: Random obstacles
  • Ctrl + Space: Play algorithm
  • Ctrl + S: Save grid
  • Ctrl + L: Load grid
  • Delete: Clear results
  • Shift + Delete: Reset grid

🎯 Key Features Implementation

Web Workers for Performance

Heavy computational tasks run in background threads to prevent UI blocking, allowing smooth visualization even with large input sizes (1B+ operations).

Svelte 5 Runes

Modern reactive state management using Svelte 5's new runes API ($state, $derived, $effect).

Priority Queue & Queue

Custom implementations for efficient pathfinding algorithms (Dijkstra, A*).

Real-time Visualization

Asynchronous rendering with setTimeout for smooth, step-by-step algorithm visualization.

πŸ“ License

This project is open source and available under the MIT License.

🀝 Contributing

Contributions, issues, and feature requests are welcome!

About

Algo Visualizer to learn by visual popular Big-O, sorting and path-finding algorithms.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •