Java console application
Sorting problem: Total number of item to be sorted
Branch | Pipeline | Code coverage | Test report |
---|---|---|---|
master | link |
- YouTube video
- All details and explanation about the benchmark
- Exercises about sorting algorithms found on the Internet
- Maven
- Java 11 (AWS Corretto)
- Lombok
- JUnit 5
- Mockito
- LogCaptor
- Enable annotation processing in your IDE (Lombok requires it)
- Install Maven dependencies/Import this repository as Maven project.
- Run application using a main class:
SortingAlgorithmsAppLauncher
An algorithm is a set of instructions designed to perform a specific task.
Sometimes an algorithm might produce a different output when given the same input.
This relates to the area of deterministic and non-deterministic algorithms.
Sorting algorithms are deterministic.
Algorithm | 50000 elements (ns) | 100000 elements (ns) | 150000 elements (ns) | Best complexity | Average complexity | Worst complexity | Space complexity (the worst) | Stable | In place |
---|---|---|---|---|---|---|---|---|---|
Bubble sort | 4928230700 | 20074524300 | 37438477400 | O(n) | O(n^2) | O(n^2) | O(1) | yes | yes |
Cocktail Shaker sort (Bidirectional bubble sort) |
1622600 | 1603300 | 1278200 | O(n) | O(n^2) | O(n^2) | O(1) | yes | yes |
Selection sort | 469744400 | 1834796800 | 4116949900 | O(n^2) | O(n^2) | O(n^2) | O(1) | no | yes |
Insertion sort | 1595300 | 1352000 | 208500 | O(n) | O(n^2) | O(n^2) | O(1) | yes | yes |
Shell sort | 6446800 | 2566500 | 1116300 | O(n log n) | depends on gap sequence | O(n^2) | O(1) | no | yes |
Counting sort | 16629700 | 6919800 | 7940500 | O(n+k) | O(n+k) | O(n+k) | O(n+k) | yes/no* | no/yes* |
Heap sort | 11219900 | 33287900 | 16133000 | O(n log n) | O(n log n) | O(n log n) | O(1) | no | yes |
Merge sort | 11539000 | 8662800 | 18594200 | O(n log n) | O(n log n) | O(n log n) | O(n) | yes | no |
Quick sort | 4743300 | 2344100 | 3392600 | O(n log n) | O(n log n) | O(n^2) | O(log n) | no | yes |
The table is auto generated using the app. Choose 10
to generate new results and copy the table from resources
.
Table generated using: https://www.tablesgenerator.com/markdown_tables#
Big O Notation reference: https://www.bigocheatsheet.com/
Symbol explanations:
- ns
- nanoseconds
- B
- Bytes
- n
- number of elements in an array
- k
- the dataset/array elements range
Remarks:
- *The counting sort can be implemented as:
- not in-place: stable, O(N) space complexity.
- in-place: none stable, O(1) space complexity.
Run Maven commands using Maven Release plugin.
mvn release:prepare
If you want to only update versions, use below command:
mvn release:update-versions -DautoVersionSubmodules=true