Basic Usage
The Sorting Algorithms Visualiser accepts an optional command-line parameter to control the visualization speed:Syntax
- Program Name:
SortingAlgos.exe(Windows) orsortingalgos(Unix-like systems) - Parameter: Single integer value representing the delay between operations in nanoseconds
- Optional: If no parameter is provided, the default delay is used
Delay Parameter
The delay parameter controls how long the program waits between each comparison or swap operation during sorting.Default Value
FromSortingAlgos.h:18, the default SORT_DELAY is:
How It Works
- The program reads the command-line argument
- Validates that it’s a positive integer
- Sets
SORT_DELAYto the provided value - Uses
std::this_thread::sleep_for(std::chrono::nanoseconds(SORT_DELAY))between operations
The delay affects every comparison and swap operation, so the total sorting time is proportional to both the delay and the algorithm’s complexity.
Examples
Fast Visualization
Moderate Speed
Slow Motion
Very Slow
Help Flag
Display usage information with the help flag:Help Output
When using the help flag, the program displays:0.
Error Handling
Invalid Input
If you provide a non-numeric value, the program displays an error message:1.
Validation Logic
FromSortingAlgos.h:28-36, the program validates input:
Performance Considerations
Choosing the Right Delay
Small Delays (1-1000 ns)
- Nearly instantaneous
- Good for benchmarking
- Hard to observe individual steps
Medium Delays (1ms-10ms)
- Balanced visualization
- Steps are observable
- Reasonable completion time
Large Delays (10ms-100ms)
- Educational demonstrations
- Each step clearly visible
- Longer total time
Very Large Delays (>100ms)
- Step-by-step analysis
- May feel sluggish
- Best for small arrays
Time Calculations
For an array of 250 elements:- Bubble Sort: ~31,000 comparisons × delay
- Selection Sort: ~31,125 comparisons × delay
- Quick Sort: ~2,000-3,000 comparisons × delay
With a delay of 1ms (1,000,000 ns), Bubble Sort on 250 elements takes approximately 31 seconds to complete.
Running Without Arguments
If you run the program without any arguments:- Uses the default
SORT_DELAYvalue of1nanosecond - Starts normally with the graphical interface
- Sorts will run at maximum speed (limited only by rendering)