Algorithm Visualizer is an interactive web application that helps users understand various algorithms through step-by-step visualizations. It currently supports binary tree traversals and other array-based algorithms.
To run this project locally, follow these steps:
- Node.js (v14 or later)
- Python (v3.7 or later)
- npm (usually comes with Node.js)
-
Clone the repository:
git clone https://github.com/yourusername/algorithm-visualizer.git cd algorithm-visualizer
-
Install frontend dependencies:
npm install
-
Start the frontend development server:
npm run dev
-
Navigate to the backend directory:
cd backend
-
Create and activate a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\\Scripts\\activate`
-
Install Python dependencies:
pip install -r requirements.txt
-
Start the backend server:
python run.py
Once both frontend and backend servers are running:
- Open your web browser and navigate to
http://localhost:3000
(or the port specified by your frontend server). - Select an algorithm from the sidebar.
- Use the input selector to choose or input data for the algorithm.
- Click the "Start" button to begin the visualization.
- Use the playback controls to step through the algorithm or adjust the playback speed.
The main component that orchestrates the visualization process.
import React from "react";
import CodeEditor from "./CodeEditor";
import Visualizer from "./Visualizer";
import Controls from "./Controls";
export default function AlgorithmVisualizer({ selectedAlgorithm }) {
// ... state and effect hooks ...
return (
<div className="flex flex-col h-full">
<CodeEditor code={code} onCodeChange={setCode} />
<Visualizer
data={visualizationData}
currentStep={currentStep}
theme="light"
/>
<Controls
isRunning={isRunning}
isPlaying={isPlaying}
onStart={handleStart}
onStop={handleStop}
onPlayPause={handlePlayPause}
onStepForward={handleStepForward}
onStepBackward={handleStepBackward}
/>
</div>
);
}
A component for visualizing tree-based algorithms using D3.js.
import React, { useRef, useEffect } from "react";
import * as d3 from "d3";
const TreeVisualizer = ({ data, currentStep, theme }) => {
const svgRef = useRef(null);
useEffect(() => {
// D3.js visualization logic
// ...
}, [data, currentStep, theme]);
return <svg ref={svgRef}></svg>;
};
export default TreeVisualizer;
- Frontend:
- React
- Next.js
- D3.js for visualizations
- Tailwind CSS for styling
- Backend:
- Python
- Flask
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.