Skip to content

About

πŸ’‘ An algorithm recommendation and benchmarking tool.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

69 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logo Logo

Complexity

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.


The Problem

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.

How It Works

Your Input
   |
   v
ArrayAnalyzer
   |  size, sortedness, uniqueness, type
   v
ScoringEngine
   |  evaluates algorithms using data + preferences
   v
Recommendation
   |  algorithm + score + reasons
   v
Sorting (optional)

What Gets Analyzed

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

What You Can Configure

Preference Description
Speed over Memory Prioritize execution speed
Stable Prefer stable sorting algorithms
Memory Constrained Prefer algorithms with lower memory requirements

Modules

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

Complexity Core

The core module provides the Java API for analyzing and sorting collections.

Complexity CLI

The CLI provides commands for sorting values, analyzing input, and displaying usage information.


Quick Start β€” Java API

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());

Sort directly

List<Integer> sorted = complexity.sort(Algorithm.MERGESORT);

System.out.println(sorted);

Analyze, then sort

AlgorithmScore result = complexity.analyze();

List<Integer> sorted = complexity.sort(result.getAlgorithm());

System.out.println(sorted);

Installation

Complexity CLI requires Java 21 or later.

  1. Download the Complexity distribution ZIP.
  2. Extract the ZIP archive.
  3. Open a terminal in the extracted directory.
  4. Run the CLI using the Windows launcher.

Display available commands:

.\cmp.bat help

No Maven installation is required to use the packaged CLI.


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

Usage

cmp <command> [options]

On Windows, use cmp.bat to run the CLI.

Options

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

Examples

Analyze a collection:

.\cmp.bat analyze --values 8,3,5,1,9,2

Sort using a specific algorithm:

.\cmp.bat sort --values 8,3,5,1 --algorithm INSERTION_SORT

Sort with preferences:

.\cmp.bat sort --values 8,3,5,1 --algorithm MERGESORT --stable

Display help:

.\cmp.bat help

The CLI can also be launched directly through its executable JAR:

java -jar complexity-cli.jar help

Algorithms

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

Build the project from the root directory:

mvn clean verify

This builds the modules and runs the test suite.

To create the executable CLI JAR:

mvn clean package

The packaged JAR is generated in the CLI module's target directory.

Built With

  • Java
  • Maven
  • JUnit 5

v1.5.0 β€” works. future versions will make it better. that's the deal.

About

πŸ’‘ An algorithm recommendation and benchmarking tool.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages