Posts

Showing posts with the label Selection sort in c

Selection sort

Image
Selection sorting technique in python and C Selection sort  It is one of the sorting techniques. In this technique, we repeatedly sort the array by finding the minimum element in the array and swapping the minimum element with the element in the first index, the second minimum element with the element in the second index, and so on. By repeating the procedure we will be having two sub arrays, a sorted array, and an unsorted array. At the end, finishing the above procedure till the last index we'll be having a single sub array that is the sorted array. Explanation : Selection sort Look at the above example, where we have the array [5, 3, 4, 1, 6, 2] to be sorted. At First, we have to find the first minimal element in the array, the minimum element is 1. Now swap it with the element at index 0, which is 5. After swapping 1 and 5, the array will be [1, 3, 4, 5, 6, 2]. Then swap the second smallest element (2)  with the element at index 1 ( 3), the array will be [1, 2, 4, 5, 6, 3]. Swa