Student Name: Adomas Zilickij Student Number: 20059569

Selection Sort

Selection sort is a type of sorting algorithm. It works by going through the array multiple times (passes), selecting the smallest element. After each pass, the smallest element gets swapped (if needed) with the element at the start, which becomes its final position. In each pass, we don't need to look at the elements that are already in their final positions - we only work with the remaining elements. Selection sort is not efficient for large data sets due to its time complexity of O(n2).

Compare Swap Unsorted Sorted

Enhance with AI

Pseudocode

numberOfPasses = arrayValues.length - 1
firstIndex = 0
currentIndex = 0
currentSmallestValue = 0
WHILE numberOfPasses > 0:
currentSmallestValue = arrayValues[currentIndex]
WHILE currentIndex < arrayValues.length - 1:
IF currentSmallestValue > arrayValues[currentIndex + 1]:
currentSmallestValue = arrayValues[currentIndex + 1]
END IF
currentIndex = currentIndex + 1
END WHILE
IF arrayValues[firstIndex] ≠ currentSmallestValue:
SWAP arrayValues[firstIndex], arrayValues[indexOfCurrentSmallestValue]
END IF
firstIndex = firstIndex + 1
currentIndex = firstIndex
numberOfPasses = numberOfPasses - 1
END WHILE