Student B: Selection Sort (with early termination optimization)
Partner: [ΠΠΌΡ ΡΠ²ΠΎΠ΅Π³ΠΎ ΠΏΠ°ΡΡΠ½ΡΡΠ°] β Insertion Sort
This repository implements the Selection Sort algorithm with optimizations:
- Bidirectional selection (min & max per pass)
- Early termination when no swaps occur
- Pre-check for already sorted arrays (O(n) best case)
- Performance tracking for comparisons, swaps, reads, writes, and time.
| Case | Time Complexity | Space Complexity | Description |
|---|---|---|---|
| Best | Ξ(n) | O(1) | Already sorted (detected early) |
| Average | Ξ(nΒ²) | O(1) | Typical unsorted input |
| Worst | Ξ(nΒ²) | O(1) | Reverse-sorted array |
assignment2-selection-sort/
βββ src/main/java/com/assignment2/algorithms/SelectionSort.java
βββ src/main/java/com/assignment2/metrics/PerformanceTracker.java
βββ src/main/java/com/assignment2/cli/BenchmarkRunner.java
βββ src/test/java/com/assignment2/algorithms/SelectionSortTest.java
βββ docs/analysis-report.docx
βββ docs/performance-plots/selection-sort.png
βββ pom.xml
mvn compile exec:java -Dexec.mainClass="com.assignment2.cli.BenchmarkRunner"
mvn test
Benchmark Results
n=100, time=0,840 ms, comparisons=5101, swaps=92
n=1000, time=20,919 ms, comparisons=501001, swaps=993
n=10000, time=126,702 ms, comparisons=50009997, swaps=9986
n=100000, time=7417,909 ms, comparisons=5000099890, swaps=99944Observation: Execution time and comparisons grow quadratically with input size (O(nΒ²)), while swaps increase linearly (O(n)).
π Performance Plot
Below is the performance chart showing execution time (ms) vs input size (n):
π¨βπ» Author
Name: Agabekuly Asylbek Group: SE-2438 Role: Student B β Selection Sort