Sorting Algorithm Tutorials - Herong's Tutorial Examples - 6.12, by Herong Yang
Shell Sort - Performance
This section provides a tutorial on how to measure the performance of the Shell Sort algorithm. My first Java implementation of Shell Sort is performing somewhere between O(N*Log2(N) and O(N*N) order levels.
Now let's see how my Java implementation of the Shell Sort algorithm performs. Here are the results with my SortTest.java class and HyArrays.shellSort() function using JDK 13.
Array size: 100000 Average sorting time: 54 milliseconds Number of tests: 1000 Performance: 0.54 O(N) microseconds Performance: 0.032511239531709965 O(N*Log2(N)) microseconds Performance: 5.4E-6 O(N*N) microseconds Array size: 200000 Average sorting time: 156 milliseconds Number of tests: 1000 Performance: 0.78 O(N) microseconds Performance: 0.04429391963636588 O(N*Log2(N)) microseconds Performance: 3.9E-6 O(N*N) microseconds Array size: 300000 Average sorting time: 281 milliseconds Number of tests: 1000 Performance: 0.9366666666666666 O(N) microseconds Performance: 0.05148046747409362 O(N*Log2(N)) microseconds Performance: 3.1222222222222224E-6 O(N*N) microseconds
As you can see, the performance of this Shell Sort is much better than Insertion sort. But it is still not as good as Quicksort.
As a reference, results from an older computer are listed below:
Array size: 10000 Average sorting time: 25 milliseconds Number of tests: 1000 Performance: 2.5 O(N) microseconds Performance: 0.18814374728998823 O(N*Log2(N)) microseconds Performance: 2.5E-4 O(N*N) microseconds Array size: 20000 Average sorting time: 81 milliseconds Number of tests: 1000 Performance: 4.05 O(N) microseconds Performance: 0.28346035337307884 O(N*Log2(N)) microseconds Performance: 2.025E-4 O(N*N) microseconds Array size: 30000 Average sorting time: 148 milliseconds Number of tests: 1000 Performance: 4.933333333333334 O(N) microseconds Performance: 0.3317045099854675 O(N*Log2(N)) microseconds Performance: 1.6444444444444444E-4 O(N*N) microseconds
Table of Contents
Introduction of Sorting Algorithms
Java API for Sorting Algorithms
Insertion Sort Algorithm and Java Implementation
Selection Sort Algorithm and Java Implementation
Bubble Sort Algorithm and Java Implementation
Quicksort Algorithm and Java Implementation
Merge Sort Algorithm and Java Implementation
Heap Sort Algorithm and Java Implementation
►Shell Sort Algorithm and Java Implementation
Shell Sort - Algorithm Introduction
Shell Sort - Java Implementation
Shell Sort - Implementation Improvements
Sorting Algorithms Implementations in PHP
Sorting Algorithms Implementations in Perl
Sorting Algorithms Implementations in Python