- index.html: Contains the UI structure (controls, container, info card, footer).
- styles.css: Manages the visual layout and appearance.
- main.js: Core logic, event handlers, speed settings, info card updates.
- bubbleSort.js, selectionSort.js, etc.: Each file contains one sorting algorithm.
- A modern web browser (Chrome, Firefox, Edge, Safari).
- (Optional) A local web server (e.g., Live Server in VSCode) for best results, but you can also open
index.htmldirectly in your browser.
- Clone or Download this repository.
- Open
index.htmlin your browser (or serve it via a local server). - You’ll see the controls at the top and an empty container for bars.
- Number of Bars: Set how many bars to generate (e.g., 50).
- Algorithm: Select from the dropdown (Bubble, Selection, etc.).
- Speed: Choose Slow, Medium, or Fast.
- Generate Bars: Creates new bars of random heights.
- Start Sorting: Runs the chosen algorithm, blinking any bars that move.
- Watch the info card for a short description and complexities.
-
Bubble Sort
- Compares adjacent pairs and swaps if out of order.
- Time: O(n^2), Space: O(1)
-
Selection Sort
- Finds the minimum and places it at the start.
- Time: O(n^2), Space: O(1)
-
Insertion Sort
- Inserts each element into the correct position among the sorted portion.
- Time: O(n^2), Space: O(1)
-
Merge Sort
- Recursively divides the array, sorts each half, and merges.
- Time: O(n log n), Space: O(n)
-
Quicksort
- Uses a pivot to partition the array, then sorts partitions recursively.
- Time: O(n log n), Space: O(log n)
-
Counting Sort
- Counts occurrences of each distinct element, then outputs in order.
- Time: O(n + k), Space: O(k)
-
Radix Sort
- Sorts by individual digits, from least to most significant.
- Time: O(d*(n + k)), Space: O(n + k)
-
Bucket Sort
- Distributes elements into buckets, sorts buckets, and concatenates.
- Time: O(n + k), Space: O(n*k)
-
Heap Sort
- Builds a heap, repeatedly extracts the top, and heapifies.
- Time: O(n log n), Space: O(1)
-
Shell Sort
- Variation of insertion sort with decreasing gap sizes.
- Time: O(n^(3/2)) or depends on gap sequence, Space: O(1)
- Blink Behavior: Adjust
blinkBarinmain.jsfor different colors or number of blinks. - Speeds: Modify
speedSelect.addEventListener("change", ...)inmain.jsto set your own delays. - Styling: Update
styles.cssfor different backgrounds, bar colors, or layouts.