Demo โข Features โข Screenshots โข Quick Start โข How To Use โข The Algorithm โข Technologies โข Customizing
An interactive visualization tool that beautifully showcases the merge sort algorithm in action. Designed with dual tree visualization to separately display both divide and merge phases, this project offers educational value for students learning algorithms while delivering an engaging visual experience with particle effects.
- ๐ Dual Tree Visualization - Separate trees for divide and merge phases
- ๐ Interactive UI - Control speed, array size, and step through the algorithm
- ๐ Zoom & Pan - Examine complex visualizations with intuitive controls
- ๐ฌ Detailed Logs - Step-by-step explanation of the algorithm's execution
- ๐จ Beautiful Particle Effects - Dynamic background with interactive particles
- ๐ฑ Responsive Design - Optimized for desktop, tablet, and mobile devices
- ๐ Performance Optimized - GPU-accelerated animations and efficient rendering
- ๐ง Educational Value - Perfect for algorithm learning and teaching
- ๐ฏ Accessibility Features - Keyboard shortcuts and screen reader support
- ๐ Eye-friendly Design - Dark theme with carefully selected colors
Tablet View | Mobile View |
---|---|
![]() |
![]() |
-
Clone the repository:
git clone https://github.com/NICxKMS/interactive-merge-sort-visualizer.git
-
Navigate to the project directory:
cd interactive-merge-sort-visualizer
-
Open
index.html
in your browser:# On Windows start index.html # On macOS open index.html # On Linux xdg-open index.html
-
Alternative: Use a local development server:
# Using Python python -m http.server 8000 # Using Node.js with http-server npx http-server -o
Icon | Control | Description |
---|---|---|
โ๏ธ | Array Size | Set the number of elements (8-32 recommended) |
๐ข | Speed Slider | Adjust animation speed (left=faster, right=slower) |
Start | Begin the visualization process | |
โธ๏ธ | Pause/Resume | Toggle animation playback |
๐ | Reset | Generate a new random array |
๐ | Zoom Controls | Examine complex visualizations (+ / - / reset) |
- Use keyboard shortcuts for faster control (Space, R, S, +, -)
- On mobile, use pinch gestures to zoom and swipe to navigate
- Long press on any node to see detailed information about that step
Merge Sort is a classic divide-and-conquer algorithm that:
- Divide: Split the array into two halves recursively until single elements remain
- Conquer: Merge sorted subarrays back into larger sorted arrays
- Combine: Build the final sorted array through successive merges
Click to expand the full algorithm implementation
// ๐ MERGE SORT MAIN FUNCTION
function mergeSort(arr, start, end) {
// โ
Base case: single element is already sorted
if (start >= end) return;
// ๐น Find the middle point
let mid = Math.floor((start + end) / 2);
// ๐ Recursively sort first and second halves
mergeSort(arr, start, mid); // Sort left half
mergeSort(arr, mid + 1, end); // Sort right half
// ๐ Merge the sorted halves
merge(arr, start, mid, end);
}
// ๐ MERGE FUNCTION
function merge(arr, start, mid, end) {
// ๐ Create temporary arrays
let L = arr.slice(start, mid + 1); // Left subarray
let R = arr.slice(mid + 1, end + 1); // Right subarray
// ๐ข Initial indices for left, right, and merged arrays
let i = 0, j = 0, k = start;
// ๐ Merge the two arrays back into arr[start..end]
while (i < L.length && j < R.length) {
if (L[i] <= R[j]) { // โ
If left element is smaller
arr[k] = L[i];
i++;
} else { // โ
If right element is smaller
arr[k] = R[j];
j++;
}
k++;
}
// โฉ Copy remaining elements of L[] if any
while (i < L.length) {
arr[k] = L[i];
i++, k++;
}
// โฉ Copy remaining elements of R[] if any
while (j < R.length) {
arr[k] = R[j];
j++, k++;
}
}
Metric | Best Case | Average Case | Worst Case |
---|---|---|---|
Time Complexity | O(n log n) | O(n log n) | O(n log n) |
Space Complexity | O(n) | O(n) | O(n) |
Stable | Yes | ||
In-place | No |
- โ Predictable O(n log n) performance regardless of input data
- โ Works well for large datasets
- โ Stable sorting algorithm (maintains relative order of equal items)
- โ Optimal for external sorting (when data doesn't fit in memory)
Algorithm | Best | Average | Worst | Memory | Stable |
---|---|---|---|---|---|
Merge Sort | n log n | n log n | n log n | O(n) | โ |
Quick Sort | n log n | n log n | nยฒ | O(log n) | โ |
Heap Sort | n log n | n log n | n log n | O(1) | โ |
Bubble Sort | n | nยฒ | nยฒ | O(1) | โ |
- Merge Sort: ๐ Predictable performance, ๐ Stable sorting, ๐พ External sorting
- Quick Sort: โก Fastest in practice, ๐ง Cache efficient, ๐ In-place (with stack)
- Heap Sort: ๐ก๏ธ Guaranteed performance, ๐ช In-place sorting, ๐ No extra memory
- Bubble Sort: ๐ Simple implementation, โ Detects already sorted data, ๐ข Only good for tiny datasets
- HTML5 - Structure and semantic elements
- CSS3 - Advanced animations, transitions, and responsive design
- JavaScript ES6 - Modern JS with async/await for animations
- particles.js - Interactive background particle system
- SVG - Vector graphics for tree connections and visual elements
Technique | Description | Benefit |
---|---|---|
GPU Acceleration | Using CSS transform: translate3d |
Smooth animations even on complex visualizations |
Lazy Tree Rendering | Nodes created only when needed | Minimizes DOM operations and memory usage |
Connection Batching | SVG connections updated in batches | Reduces layout thrashing and improves performance |
Animation Throttling | Limiting animation frames during heavy operations | Prevents frame drops and UI freezing |
Visibility Detection | Pauses animations when not in viewport | Saves CPU/GPU resources when content not visible |
Mobile Optimization | Reduced particle count and effect complexity | Better performance on mobile devices with limited resources |
interactive-merge-sort-visualizer/
โ
โโโ index.html # Main HTML file
โ
โโโ css/
โ โโโ mergesort.css # Main styling
โ โโโ particle-effects.css # Particle effect styling
โ
โโโ js/
โ โโโ browser-compatibility.js # Browser compatibility helpers
โ โโโ mergesort-algorithm.js # Core algorithm implementation
โ โโโ mergesort-bridge.js # Bridge between algorithm and visualization
โ โโโ mergesort-core.js # Core utility functions
โ โโโ mergesort-init.js # Initialization module
โ โโโ mergesort-visualization.js # Visualization functions
โ โโโ particles-config.js # Particle system configuration
โ
โโโ README.md # Project documentation
Module | Role | Description |
---|---|---|
๐งฉ Algorithm | Brain | Pure implementation with no UI dependencies |
๐จ Visualization | View | Handles all DOM updates and animations |
๐ Bridge | Connector | Links algorithm execution to visual updates |
๐ ๏ธ Core Utilities | Foundation | Shared functions used across modules |
๐ Initialization | Bootstrap | Sets up the environment on page load |
โจ Particles | Aesthetics | Background visual effects and interactions |
- User initiates sort โ
- Algorithm executes step โ
- Bridge captures state โ
- Visualization renders changes โ
- User observes algorithm in action
HTML5 Canvas, SVG Rendering, Interactive UI | ||
โฌ๏ธ โฌ๏ธ | ||
Merge Sort Implementation, Animation Controller | ||
โฌ๏ธ โฌ๏ธ | ||
Array transformation JavaScript ES6 |
Step-by-step visualization requestAnimationFrame |
Visual representation SVG, Canvas API |
Tree structure generation DOM Manipulation |
Background effects particles.js |
Interactive controls Event Listeners, CSS3 |
Component | Description | Technologies |
---|---|---|
Visualization Layer | Renders the sorting process visually | HTML5, CSS3, SVG |
Algorithm Core | Pure implementation of merge sort | JavaScript ES6 |
Animation Engine | Controls timing and sequence of steps | requestAnimationFrame API |
Tree Builder | Creates and updates visualization trees | DOM manipulation |
Data Processing | Handles array operations and transformations | JavaScript Arrays |
Rendering System | Draws the visualization elements | SVG, HTML Elements |
User Interface | Provides interactive controls | Event Listeners |
Particle System | Creates engaging background visuals | particles.js |
|
|
Detailed examination of the algorithm
|
Visual representation of data transformation
|
Detailed step-by-step explanation
|
Cross-device compatibility
|
This visualization tool serves as an excellent educational resource for:
- Computer Science students learning divide-and-conquer algorithms
- Educators teaching sorting algorithms and computational complexity
- Visual learners who grasp concepts better through animation
- Developers interested in algorithm visualization techniques
- Interview preparation for technical coding questions
- Understand the divide and merge phases of merge sort
- Visualize the recursive nature of the algorithm
- See how the array is transformed at each step
- Compare the efficiency with other sorting methods
- Gain intuition about O(n log n) complexity
Status | Feature | Priority |
---|---|---|
๐ฒ | Multiple sorting algorithms for comparison | High |
๐ฒ | Custom array input | Medium |
๐ฒ | Algorithm time complexity visualization | Medium |
๐ฒ | Step back functionality | Medium |
๐ฒ | Audio representation of sorting process | Low |
๐ฒ | Dark/light theme toggle | Low |
๐ฒ | Export sorted arrays and statistics | Low |
Why is merge sort useful despite requiring extra space?
While merge sort requires O(n) auxiliary space, its guaranteed O(n log n) time complexity makes it valuable for many applications. It's particularly useful for external sorting (when data doesn't fit in memory), linked list sorting (can be implemented with O(1) extra space), and when stability is required (preserving the relative order of equal elements).
How can I contribute to this project?
Contributions are welcome! Check the contribution guidelines in the next section. Areas where help is particularly appreciated include adding new sorting algorithms, improving accessibility, enhancing mobile experience, and adding educational descriptions.
Is this visualization accurate for educational purposes?
Yes, this visualization accurately represents the merge sort algorithm's execution. It separates the divide and merge phases clearly, making it excellent for educational purposes. The step-by-step logs also provide detailed information about each operation performed.
Can I use this project for teaching or in my own applications?
Absolutely! This project is licensed under MIT, which means you can use, modify, and distribute it freely, even for commercial purposes. Attribution is appreciated but not required.
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add some amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Maintain the existing code style
- Add unit tests for new features
- Update documentation as needed
- Ensure browser compatibility
- Test on both desktop and mobile devices
Version | Date | Changes |
---|---|---|
1.0.0 | 2025-02-20 | Initial release with core visualization features |
1.1.0 | 2025-02-26 | Added particle effects and tree zooming |
1.2.0 | 2025-03-02 | Enhanced mobile experience and performance optimizations |
This project is licensed under the MIT License - see the LICENSE file for details.
- particles.js for the beautiful particle effects
- Algorithm Visualizations for inspiration
- Icons8 for the beautiful icons used in this README
- Shields.io for the status badges
- JavaScript.info for excellent resources on modern JS
- MDN Web Docs for comprehensive web development documentation
- 95% found the visualization helpful for understanding merge sort
- 89% appreciated the dual tree visualization approach
- 92% rated the UI as intuitive and easy to use
- 78% successfully used the tool on mobile devices
- Multiple sorting algorithms for side-by-side comparison
- Custom array input for testing specific scenarios
- Step backward functionality for reviewing previous states
- Time complexity visualization to better understand performance
- Dark/light theme options for different viewing preferences
- Documentation: docs/
- Issues: GitHub Issues
- Email: support@github_Nikhil.com