Selection sort

Let's start with the selection sort, which is one of the simplest sorting algorithms. The algorithm divides the array into two parts, namely sorted and unsorted. In the following iterations, the algorithm finds the smallest element in the unsorted part and exchanges it with the first element in the unsorted part. It sounds very simple, doesn't it?

To better understand the algorithm, let's take a look at the following iterations for an array with nine elements (-11, 12, -42, 0, 1, 90, 68, 6, -9), as shown in the following diagram:

To simplify the analysis, the bold line is used to present the border between the sorted and unsorted ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.