Sorting Algorithm Comparator
Compare sorting algorithms by entering an array of numbers and selecting algorithms to visualize their performance, steps, and runtime metrics.
Sorting Algorithm Comparator
Comparison Results
About the Sorting Algorithm Comparator
The Sorting Algorithm Comparator runs multiple sorting algorithms on a user-defined array, comparing their performance in terms of execution time, number of comparisons, and swaps. This tool is designed for computer science students, developers, and educators studying algorithm efficiency.
Sorting Algorithms: Include Bubble Sort (\( O(n^2) \)), Selection Sort (\( O(n^2) \)), Insertion Sort (\( O(n^2) \)), Merge Sort (\( O(n \log n) \)), and Quick Sort (\( O(n \log n) \) average).
This comparator is ideal for learning algorithm design, performance analysis, and complexity theory.
- Features:
- Compares multiple sorting algorithms on the same input array.
- Supports input of comma-separated numbers (integers or floats, positive or negative).
- Keypad includes digits (0–9), comma (,), negative sign (-), and decimal point (.).
- Visualizes performance with a bar chart of execution times.
- Displays sorted arrays, steps, and metrics (time, comparisons, swaps).
- Clear and backspace functionality, with a "Copy" button for results.
- Practical Applications: Useful in algorithm education, performance optimization, and competitive programming.
- How to Use:
- Enter a comma-separated array of numbers (e.g., \( 5,2,8,1,9 \)).
- Select one or more sorting algorithms using the checkboxes.
- Use the keypad to input digits, commas, negative signs, and decimal points.
- Click "Compare" to run the algorithms and view results.
- Use "Clear" to reset or "⌫" to delete the last character.
- Use "Copy" to copy the comparison results.
- Share or embed the comparator using the action buttons.
- Helpful Tips:
- Input arrays should have at least 2 elements; limit to 100 elements for performance.
- Use commas to separate numbers (e.g., \( 3,-2,4.5 \)).
- Select multiple algorithms for a comprehensive comparison.
- Execution times are approximate and depend on browser performance.
- Results include sorted arrays, steps, and metrics for each algorithm.
- Bar chart scales execution times for visualization (logarithmic for large differences).
- Examples:
- Example 1: Small Array:
- Input: Array = \( [5,2,8,1,9] \), Algorithms = Bubble, Merge
- Steps (Bubble Sort):
- Pass 1: Compare and swap adjacent elements, e.g., \( [5,2] \to [2,5] \).
- Continue passes until sorted: \( [1,2,5,8,9] \).
- Steps (Merge Sort):
- Divide array: \( [5,2], [8,1,9] \), then \( [5], [2], [8], [1,9] \).
- Merge sorted subarrays: \( [2,5], [1,8,9] \), then \( [1,2,5,8,9] \).
- Result: Sorted = \( [1,2,5,8,9] \), Bubble Sort (time, comparisons, swaps), Merge Sort (time, comparisons).
- Example 2: Negative and Float:
- Input: Array = \( [-3,4.5,0,-1.2] \), Algorithms = Insertion, Quick
- Steps (Insertion Sort):
- Insert each element into sorted portion, e.g., \( -3,4.5 \to -3,4.5 \).
- Result: \( [-3,-1.2,0,4.5] \).
- Steps (Quick Sort):
- Choose pivot (e.g., 0), partition: \( [-3,-1.2], [4.5] \).
- Recurse on partitions, result: \( [-3,-1.2,0,4.5] \).
- Result: Sorted = \( [-3,-1.2,0,4.5] \), metrics for both algorithms.
- Example 3: Single Algorithm:
- Input: Array = \( [3,1] \), Algorithm = Selection
- Steps:
- Find min \( 1 \), swap with \( 3 \): \( [1,3] \).
- Result: Sorted = \( [1,3] \), metrics for Selection Sort.
- Example 1: Small Array:
Compare sorting algorithms and analyze their performance with this tool. Share or embed it on your site!