An interactive web application that visualizes popular sorting algorithms in real-time. Watch how Bubble Sort, Selection Sort, Insertion Sort, and Quick Sort work step-by-step with dynamic visual feedback.
- Multiple Algorithms - Visualize 4 different sorting algorithms:
- Bubble Sort
- Selection Sort
- Insertion Sort
- Quick Sort
- Speed Control - Adjust animation speed from 1ms to 100ms
- Array Size Control - Test with arrays from 5 to 100 elements
- Performance Metrics - Track comparisons, array accesses, and execution time
- Color-Coded Visualization - Different colors for comparing, swapping, and sorted elements
- Algorithm Information - Learn about time complexity and how each algorithm works
- Responsive Design - Works on desktop, tablet, and mobile devices
This project demonstrates:
- Deep CS Knowledge - Understanding of fundamental sorting algorithms
- Visual Communication - Ability to explain complex concepts visually
- Performance Analysis - Tracking algorithm efficiency metrics
- User Experience - Intuitive controls and real-time feedback
- Clean Code - Well-structured, maintainable JavaScript
- Download
algorithm-visualizer.html - Double-click to open in any modern web browser
- No installation or dependencies required!
- Select an Algorithm - Choose from the dropdown menu
- Adjust Settings:
- Use the speed slider to control animation speed
- Change array size for different test cases
- Generate Array - Click "New Array" to create a random dataset
- Start Sorting - Click "Sort" to watch the algorithm in action
- Observe - Watch the color-coded visualization and metrics
- 🟣 Purple - Unsorted elements
- 🔴 Red - Currently comparing
- 🟡 Yellow - Being accessed/evaluated
- 🟢 Green - Sorted and in final position
Repeatedly steps through the list, compares adjacent elements, and swaps them if they're in the wrong order. Simple but inefficient for large datasets.
Time Complexity: O(n²)
Space Complexity: O(1)
Best Use Case: Educational purposes, nearly sorted data
Divides input into sorted and unsorted regions. Repeatedly selects the smallest element from the unsorted region.
Time Complexity: O(n²)
Space Complexity: O(1)
Best Use Case: Small datasets, minimal memory usage
Builds the final sorted array one item at a time, inserting each element into its correct position.
Time Complexity: O(n²) average, O(n) best case
Space Complexity: O(1)
Best Use Case: Small datasets, nearly sorted data
Uses divide-and-conquer by selecting a pivot and partitioning the array around it. Recursively sorts sub-arrays.
Time Complexity: O(n log n) average, O(n²) worst case
Space Complexity: O(log n)
Best Use Case: General-purpose sorting, large datasets
- HTML5 - Semantic structure
- CSS3 - Tailwind CSS via CDN for styling
- JavaScript (ES6+) - Algorithm implementation and DOM manipulation
- No frameworks - Pure vanilla JavaScript
The visualizer tracks three key metrics:
- Comparisons - Number of times two elements are compared
- Array Accesses - Total read/write operations on the array
- Time - Actual execution time in milliseconds
These metrics help understand the practical efficiency of each algorithm.
Perfect for:
- Computer Science Students - Visual learning of sorting algorithms
- Interview Preparation - Understanding algorithm complexity
- Teaching - Demonstrating concepts in classroom settings
- Self-Learning - Exploring how algorithms work internally
- Create your sorting function following the existing pattern
- Add algorithm info to the
algoInfoobject - Add case in the
startSort()switch statement
Modify the Tailwind color classes:
// In renderArray function
let bgColor = 'bg-purple-500'; // Change base color
if (highlighting.includes(idx)) {
bgColor = 'bg-red-500'; // Change comparison color
}Change the speed calculation:
const speed = 101 - parseInt(document.getElementById('speed').value);- ✅ Chrome/Edge 90+
- ✅ Firefox 88+
- ✅ Safari 14+
- ✅ Opera 76+
- ✅ Mobile browsers (iOS Safari, Chrome Mobile)
Potential features to add:
- More algorithms (Merge Sort, Heap Sort, Radix Sort)
- Step-by-step mode with pause between operations
- Code display showing current line executing
- Comparison mode to run multiple algorithms side-by-side
- Sound effects for comparisons and swaps
- Export visualization as video/GIF
- Dark mode support
- Optimized rendering using CSS transitions
- Efficient array manipulation
- Debounced updates for smooth animations
- Minimal DOM operations
This is a portfolio project, but suggestions are welcome! Feel free to:
- Fork the repository
- Create issues for bugs or feature requests
- Submit pull requests with improvements
This project is open source and available for educational and personal use.
Created to demonstrate front-end development skills and computer science knowledge.
- Inspired by VisuAlgo and other algorithm visualization tools
- Built with modern web standards and best practices
Learn by Watching, Understand by Doing 🎓
This project showcases the ability to transform complex computer science concepts into accessible, interactive visualizations.