A web-based tool to visualize various sorting algorithms in action. This project allows users to shuffle an array, select a sorting algorithm, and watch the sorting process step by step with visual and audio feedback.
Try it out here: Sorting Visualizer
- Sorting Algorithms: Visualize the following algorithms:
- Bubble Sort
- Insertion Sort
- Selection Sort
- Merge Sort
- Quick Sort
- Heap Sort
- Counting Sort
- Radix Sort
- Bucket Sort
- Shell Sort
- Cocktail Shaker Sort
- Comb Sort
- Bogo Sort
- Customizable Settings:
- Adjust the number of items in the array.
- Control the sorting speed.
- Enable or disable sound effects.
- Toggle Rainbow Mode for colorful visualizations.
- Dark and Light Themes: Switch between dark and light modes.
- Visit the Live Demo: Open the Sorting Visualizer in your browser.
- Choose a Sorting Algorithm: Use the dropdown menu to select an algorithm.
- Customize Settings:
- Adjust the number of items using the slider.
- Set the sorting speed using the latency slider.
- Shuffle the Array: Click the "🔀 Shuffle" button to randomize the array.
- Run the Algorithm: Click the "
▶️ Run" button to start the sorting process. - Toggle Features:
- Use the "🌈 Rainbow" button to enable or disable colorful visualizations.
- Use the "🔊 Sound" button to enable or disable sound effects.
- Use the "🌓 Toggle Theme" button to switch between dark and light modes.
- Stop the Sorting: Click the "⏹️ Stop" button to cancel the sorting process.
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Repeatedly compares adjacent elements and swaps them if they are in the wrong order.
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Builds the sorted array one element at a time by inserting elements into their correct position.
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Selects the smallest element from the unsorted part and swaps it with the first unsorted element.
- Time Complexity: O(n log n)
- Space Complexity: O(n)
- Divides the array into halves, sorts each half, and merges them back together.
- Time Complexity: O(n log n)
- Space Complexity: O(log n)
- Selects a pivot element and partitions the array into elements less than and greater than the pivot, then recursively sorts the partitions.
- Time Complexity: O(n log n)
- Space Complexity: O(1)
- Builds a max heap and repeatedly extracts the largest element to sort the array.
- Time Complexity: O(n + k)
- Space Complexity: O(k)
- Counts the occurrences of each element and uses this information to place elements in sorted order.
- Time Complexity: O(nk)
- Space Complexity: O(n + k)
- Sorts numbers digit by digit, starting from the least significant digit.
- Time Complexity: O(n + k)
- Space Complexity: O(n + k)
- Distributes elements into buckets, sorts each bucket, and concatenates them.
- Time Complexity: O(n log² n)
- Space Complexity: O(1)
- Sorts elements at specific intervals, reducing the interval with each pass.
- Time Complexity: O(n²)
- Space Complexity: O(1)
- A variation of Bubble Sort that sorts in both directions.
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Improves Bubble Sort by using a gap to compare elements.
- Time Complexity: O((n+1)!)
- Space Complexity: O(1)
- Randomly shuffles the array until it is sorted.
- A modern web browser (e.g., Chrome, Edge, Firefox).
- A text editor (e.g., VS Code) for local development.
- Clone the repository:
git clone https://github.com/khaishea/sorting-visualizer.git
- Navigate to the project directory:
cd sorting-visualizer
- Open
index.html
in your browser.
This project is licensed under the GNU Affero General Public License (AGPL).
You are free to use, modify, and distribute this project, provided that any modifications or derivative works are also licensed under the AGPL.
For more details, see the LICENSE file.
- Inspired by various sorting algorithm visualizers.
- Built with ❤️ by khaishea.