Benchmark and compare classic sorting algorithms across data sizes and input orders.
- BubbleSort with early‑exit optimization and optional in‑range sort (
index1..index2) - InsertionSort
- MergeSort
- QuickSort (median‑of‑three pivot)
- ShellSort (Sedgewick gap sequence)
SortImpls.cpp— all sort implementationsSorter.cpp— single‑run driver with timing and optional printingSorterScript.cpp— batch runner that averages 3 trials for each caseRunTimeMeasurementResults.txt— sample output (averaged timings)Lab3Report.pdf— graphs & discussion
g++ -std=c++17 -O2 Sorter.cpp -o Sorter
g++ -std=c++17 -O2 SorterScript.cpp -o SorterScript# Sort once
./Sorter SORT_TYPE ARRAY_SIZE [YES|NO] [INDEX1 INDEX2]
# Examples
./Sorter QuickSort 10000 NO
./Sorter BubbleSort 100 YES 10 30 # only BubbleSort accepts an index rangeSORT_TYPE:BubbleSort | InsertionSort | MergeSort | QuickSort | ShellSortYES|NO: print the array before/after the run (omit to print by default)
Run the full experiment suite and print averaged results for random, ordered, partially ordered, and reversed inputs:
./SorterScript > RunTimeMeasurementResults.txt- Bubble/Insertion: best O(n) on ordered, worst O(n²) on reversed/random.
- Merge/Quick: about O(n log n); Quick uses median‑of‑three to avoid bad pivots.
- Shell: typical O(n^3/2) with Sedgewick gaps.
See
Lab3Report.pdfandRunTimeMeasurementResults.txtfor data and plots.
All timings use gettimeofday and report microseconds; the script averages three repetitions per case and size.