Selection SortIn selection sort, the smallest value among the unsorted elements of the array is selected in every pass and inserted to its appropriate position into the array. First, find the smallest element of the array and place it on the first position. Then, find the second smallest element of the array and place it on the second position. The process continues until we get the sorted array. The array with n elements is sorted by using n1 pass of selection sort algorithm.
Therefore, by following the above explained process, the elements A[0], A[1], A[2],...., A[n1] are sorted. ExampleConsider the following array with 6 elements. Sort the elements of the array by using selection sort. A = {10, 2, 3, 90, 43, 56}.
Sorted A = {2, 3, 10, 43, 56, 90} Complexity
AlgorithmSELECTION SORT(ARR, N)
SMALLEST (ARR, K, N, POS)
C ProgramOutput: printing sorted elements... 7 9 10 12 23 23 34 44 78 101 C++ ProgramOutput: printing sorted elements... 7 9 10 12 23 23 34 44 78 101 Java ProgramOutput: printing sorted elements... 7 9 10 12 23 23 34 44 78 101 C# ProgramOutput: printing sorted elements... 7 9 10 12 23 23 34 44 78 101 Python ProgramOutput: printing sorted elements... 7 9 10 12 23 23 34 44 78 101 Rust ProgramOutput: printing sorted elements... 7 9 10 12 23 23 34 44 78 101 JavaScript ProgramOutput: printing sorted elements ... 7 9 10 12 23 23 34 44 78 101 PHP ProgramOutput: printing sorted elements ... 7 9 10 12 23 23 34 44 78 101
Next TopicShell Sort
