A sorting algorithm advisor.
Give it a list, tell it what you care about, and it tells you which sorting algorithm to use β and why.
Choosing a sorting algorithm is usually either blind β "just use QuickSort" β or overkill, requiring research papers to sort a handful of integers.
Complexity sits in the middle.
It analyzes your data, considers your preferences, evaluates available algorithms, and recommends a suitable one with an explanation.
Your Input
|
v
ArrayAnalyzer
| size, sortedness, uniqueness, type
v
ScoringEngine
| evaluates algorithms using data + preferences
v
Recommendation
| algorithm + score + reasons
v
Sorting (optional)
| Property | Description |
|---|---|
| Size | Number of elements |
| Sortedness | How close the input is to being sorted |
| Uniqueness | Number of distinct values |
| Type | Input data type and applicable algorithms |
| Preference | Description |
|---|---|
| Speed over Memory | Prioritize execution speed |
| Stable | Prefer stable sorting algorithms |
| Memory Constrained | Prefer algorithms with lower memory requirements |
Complexity is organized as a Maven multi-module project.
complexity/
βββ complexity-core/
β βββ Sorting and algorithm analysis library
β
βββ complexity-cli/
β βββ Command-line interface
β
βββ dist/
βββ cmp.bat
βββ complexity-cli.jar
βββ README.md
The core module provides the Java API for analyzing and sorting collections.
The CLI provides commands for sorting values, analyzing input, and displaying usage information.
Complexity<Integer> complexity = new Complexity.Builder<>(
List.of(3, 1, 4, 1, 5, 9, 2, 6))
.speedOverMemory(true)
.needsStable(false)
.memoryConstrained(false)
.build();
AlgorithmScore result = complexity.analyze();
System.out.println(result.getAlgorithm());
System.out.println(result.getScore());
System.out.println(result.getReason());List<Integer> sorted = complexity.sort(Algorithm.MERGESORT);
System.out.println(sorted);AlgorithmScore result = complexity.analyze();
List<Integer> sorted = complexity.sort(result.getAlgorithm());
System.out.println(sorted);Complexity CLI requires Java 21 or later.
- Download the Complexity distribution ZIP.
- Extract the ZIP archive.
- Open a terminal in the extracted directory.
- Run the CLI using the Windows launcher.
Display available commands:
.\cmp.bat helpNo Maven installation is required to use the packaged CLI.
Complexity CLI supports three commands:
| Command | Description |
|---|---|
sort |
Sort values using a selected algorithm |
analyze |
Analyze values and recommend an algorithm |
help |
Display command usage |
cmp <command> [options]
On Windows, use cmp.bat to run the CLI.
| Option | Description |
|---|---|
--values <v1,v2,...> |
Comma-separated integer values |
--algorithm <name> |
Sorting algorithm to use |
--stable |
Prefer stable algorithms |
--speed-over-memory |
Prioritize speed over memory |
--memory-constrained |
Prefer lower memory usage |
Analyze a collection:
.\cmp.bat analyze --values 8,3,5,1,9,2Sort using a specific algorithm:
.\cmp.bat sort --values 8,3,5,1 --algorithm INSERTION_SORTSort with preferences:
.\cmp.bat sort --values 8,3,5,1 --algorithm MERGESORT --stableDisplay help:
.\cmp.bat helpThe CLI can also be launched directly through its executable JAR:
java -jar complexity-cli.jar help| Algorithm | Time Complexity | Space Complexity | Stable |
|---|---|---|---|
| QuickSort | O(n log n) average | O(log n) average | No |
| MergeSort | O(n log n) | O(n) | Yes |
| TimSort | O(n log n) | O(n) | Yes |
| HeapSort | O(n log n) | O(1) | No |
| Insertion Sort | O(nΒ²) | O(1) | Yes |
| Counting Sort | O(n + k) | O(k) | Yes |
| Radix Sort | O(nk) | O(n + k) | Yes |
Complexities may vary depending on implementation and input characteristics.
Build the project from the root directory:
mvn clean verifyThis builds the modules and runs the test suite.
To create the executable CLI JAR:
mvn clean packageThe packaged JAR is generated in the CLI module's target directory.
- Java
- Maven
- JUnit 5
v1.5.0 β works. future versions will make it better. that's the deal.

