**Sorting Algorithm Tutorials - Herong's Tutorial Examples** - 6.12, by Herong Yang

Selection Sort - Performance

This section provides a tutorial on how to measure the performance of the Selection Sort algorithm. My first Java implementation of Selection Sort is performing at the O(N*N) order level.

Now let's see how my Java implementation of the Selection Sort algorithm performs. Here are the results with my SortTest.java class and HyArrays.selectionSort() function using JDK 13.

Array size: 10000 Average sorting time: 55 milliseconds Number of tests: 1000 Performance: 5.5 O(N) microseconds Performance: 0.4139162440379741 O(N*Log2(N)) microseconds Performance: 5.5E-4 O(N*N) microseconds Array size: 20000 Average sorting time: 250 milliseconds Number of tests: 1000 Performance: 12.5 O(N) microseconds Performance: 0.8748776338675273 O(N*Log2(N)) microseconds Performance: 6.25E-4 O(N*N) microseconds Array size: 30000 Average sorting time: 600 milliseconds Number of tests: 1000 Performance: 20.0 O(N) microseconds Performance: 1.3447480134545982 O(N*Log2(N)) microseconds Performance: 6.666666666666666E-4 O(N*N) microseconds

The results showed us that the performance of selection method is O(N*N), because the last performance line gave me a constant, when I increased the array size.

Comparing with the Insertion Sort implementation, the Selection Sort implementation is much slower.

As a reference, results from an older computer are listed below:

Array size: 1000 Average sorting time: 38 milliseconds Number of tests: 1000 Performance: 38.0 O(N) microseconds Performance: 3.813046611743762 O(N*Log2(N)) microseconds Performance: 0.038 O(N*N) microseconds Array size: 2000 Average sorting time: 153 milliseconds Number of tests: 1000 Performance: 76.5 O(N) microseconds Performance: 6.976245201813886 O(N*Log2(N)) microseconds Performance: 0.03825 O(N*N) microseconds Array size: 3000 Average sorting time: 347 milliseconds Number of tests: 1000 Performance: 115.66666666666667 O(N) microseconds Performance: 10.01378255586346 O(N*Log2(N)) microseconds Performance: 0.03855555555555556 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

Selection Sort - Algorithm Introduction

Selection Sort - Java Implementation

Selection Sort - Implementation Improvements

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

Sorting Algorithms Implementations in PHP

Sorting Algorithms Implementations in Perl

Sorting Algorithms Implementations in Python