Selection Sort Algorithm Analysis

randerson112358
5 min readMar 24, 2018

Analyze Selection Sort using Big O Asymptotics Line by Line!

Note: The code I use in this article is slightly different

OVERVIEW

Selection sort is a sorting algorithm in computer science. It has O(n²) time complexity. O(n²) isn’t a good time complexity for sorting lists when it comes to large input sizes. This algorithm sorts an array or list by repeatedly finding the minimum value (if we are sorting in ascending order) from the list or array and placing it at the beginning of the list. Here I am going to go line by line on the selection sort algorithm to compute the algorithms runtime.

arr[] = 65 25 12 22 10

// Find the minimum element in arr[0...4]
// and place it at beginning
10 30 12 22 65

// Find the minimum element in arr[1...4]
// and place it at beginning of arr[1...4]
10 12 30 22 65

// Find the minimum element in arr[2...4]
// and place it at beginning of arr[2...4]
10 12 22 30 65

// Find the minimum element in arr[3...4]
// and place it at beginning of arr[3...4]
10 12 22 30 65

Selection Sort Code

Selection Sort C-Program Analysis

--

--