A comprehensive, interactive web application for visualizing sorting algorithms built with Next.js and React. This project demonstrates various sorting algorithms with real-time animations, sound effects, and educational features.
- 7 Sorting Algorithms: Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, Heap Sort, and Radix Sort
- Interactive Visualization: Real-time animation of sorting processes with color-coded elements
- Array Generation: Multiple array types including random, reversed, and custom arrays
- Array Size Control: Configurable array size from 5 to 30 elements
- Color-coded Elements:
- ๐ด Red: Elements being compared
- ๐ก Yellow: Elements being swapped
- ๐ข Green: Elements in correct position
- ๐ฃ Purple: Pivot elements (Quick Sort)
- ๐ต Cyan: Elements being merged (Merge Sort)
- Smooth Animations: CSS transitions and keyframe animations
- Responsive Design: Works on desktop, tablet, and mobile devices
- Algorithm Pseudocode: Real-time display of algorithm steps with highlighting
- Step-by-step Explanations: Detailed descriptions of each sorting operation
- Performance Metrics: Real-time tracking of comparisons, swaps, and execution time
- Complexity Information: Time and space complexity for each algorithm
- Dark/Light Mode: Toggle between dark and light themes
- Sound Effects: Audio feedback for comparisons, swaps, and completion
- Playback Controls: Start, pause, resume, and reset functionality
- Custom Arrays: Input your own array of numbers to sort
- Statistics Panel: Comprehensive metrics and array information
- Framework: Next.js 16 with React 19
- Language: TypeScript
- Styling: CSS Modules with responsive design
- Audio: Web Audio API for sound effects
- Algorithms: Custom implementations of all sorting algorithms
sorting-algorithm-visualizer/
โโโ app/ # Next.js app directory
โ โโโ globals.css # Global styles
โ โโโ layout.tsx # Root layout
โ โโโ page.tsx # Main page
โโโ components/ # React components
โ โโโ Bar.tsx # Individual array element component
โ โโโ Controls.tsx # Control panel component
โ โโโ Pseudocode.tsx # Algorithm pseudocode display
โ โโโ Visualizer.tsx # Main visualizer component
โโโ algorithms/ # Sorting algorithm implementations
โ โโโ bubbleSort.ts # Bubble sort algorithm
โ โโโ selectionSort.ts # Selection sort algorithm
โ โโโ insertionSort.ts # Insertion sort algorithm
โ โโโ mergeSort.ts # Merge sort algorithm
โ โโโ quickSort.ts # Quick sort algorithm
โ โโโ heapSort.ts # Heap sort algorithm
โ โโโ radixSort.ts # Radix sort algorithm
โ โโโ index.ts # Algorithm exports
โโโ utils/ # Utility functions
โ โโโ arrayUtils.ts # Array generation and manipulation
โ โโโ audioUtils.ts # Audio management
โ โโโ constants.ts # Application constants
โโโ styles/ # CSS modules
โ โโโ Bar.module.css # Bar component styles
โ โโโ Controls.module.css # Controls component styles
โ โโโ Pseudocode.module.css # Pseudocode component styles
โ โโโ Visualizer.module.css # Main visualizer styles
โโโ hooks/ # Custom React hooks (if needed)
- Node.js 18+
- npm or yarn
-
Clone the repository
git clone <repository-url> cd sorting-algorithm-visualizer
-
Install dependencies
npm install
-
Start the development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
npm run build
npm start- Select an Algorithm: Choose from the dropdown menu
- Choose Array Type: Select random, reversed, or custom
- Adjust Settings: Set array size (5-30)
- Start Sorting: Click "Start Sorting" to begin visualization
- Control Playback: Use pause/resume and reset buttons as needed
- Select "Custom" array type
- Enter numbers separated by commas (e.g., "5,2,8,1,9")
- Click "Use" to apply the custom array
- Start sorting to visualize your custom data
- ๐ Dark Mode: Toggle between light and dark themes
- ๐ Sound Effects: Enable/disable audio feedback
- ๐ Statistics: View real-time performance metrics
- ๐ Pseudocode: Follow algorithm steps with highlighted code
- ๐ฑ Responsive: Works on all device sizes
- Time Complexity: O(nยฒ)
- Space Complexity: O(1)
- Description: Repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order
- Time Complexity: O(nยฒ)
- Space Complexity: O(1)
- Description: Finds the minimum element from the unsorted portion and moves it to the beginning
- Time Complexity: O(nยฒ)
- Space Complexity: O(1)
- Description: Builds the final sorted array one item at a time by inserting each element into its correct position
- Time Complexity: O(n log n)
- Space Complexity: O(n)
- Description: Divides the array into halves, sorts them separately, then merges them back together
- Time Complexity: O(n log n) average, O(nยฒ) worst case
- Space Complexity: O(log n)
- Description: Picks a pivot element and partitions the array around the pivot
- Time Complexity: O(n log n)
- Space Complexity: O(1)
- Description: Uses a binary heap data structure to sort elements
- Time Complexity: O(dn) where d is the number of digits
- Space Complexity: O(n)
- Description: Sorts numbers by processing individual digits
- Create a new file in
algorithms/directory - Implement the algorithm as an async generator function
- Export it from
algorithms/index.ts - Add it to the
SORTING_ALGORITHMSconstant inutils/constants.ts - Add pseudocode to the
PSEUDOCODEconstant
- All styles use CSS Modules for component isolation
- Dark mode support is built into all components
- Responsive design uses CSS Grid and Flexbox
- Custom CSS properties for easy theme customization
- Sound effects are managed by the
AudioManagerclass - Uses Web Audio API for high-quality audio generation
- Easily customizable frequencies and durations
The application includes comprehensive error handling and validation:
- Array size limits (5-200 elements)
- Custom array input validation
- Algorithm step validation
- Responsive design testing
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by various sorting algorithm visualizations
- Built with modern web technologies
- Designed for educational purposes
If you encounter any issues or have questions:
- Check the browser console for errors
- Ensure you're using a supported browser
- Try refreshing the page
- Create an issue in the repository
Happy Sorting! ๐