Selection Sort implementation with early-termination/suffix-check optimization.
src/main/java/algorithms/SelectionSort.java
- main implementationsrc/main/java/metrics/PerformanceTracker.java
- counts comparisons/swaps/accessessrc/main/java/cli/BenchmarkRunner.java
- simple CLI benchmarksrc/test/java/algorithms/SelectionSortTest.java
- JUnit5 testspom.xml
- Maven build
Requirements: JDK 17+, Maven.
Build:
mvn -q -DskipTests=false test package
Run CLI (example):
mvn -q exec:java -Dexec.mainClass=cli.BenchmarkRunner
or build jar and run.
The implementation is standard selection sort with an additional suffix-sorted check when no swap is needed for a pass. This gives early termination on already-sorted or nearly-sorted arrays, while preserving selection sort stability of operation counts in general.
PerformanceTracker
records:
- comparisons
- swaps
- arrayAccesses (approximate)
Use BenchmarkRunner
to experiment with different input sizes and distributions (random, sorted,
reverse, nearly).