Step 2: In the unsorted sub-array, the minimum element is 3, so swap element 3 with an element 4, which is at the beginning of the unsorted sub-array. Now, the sorted array contains only one element, i.e., 1, while the unsorted array contains 5 Step 1: In the above array, the minimum element is 1 swap element 1 with an element 7. The following are the steps used to sort the array: The above array is an unsorted array whose indexing starts from 0 and ends at 5. Let's understand the selection sort through an example.Īs we can observe in the above array that it contains 6 elements. This algorithm is named as selection sort because it is selecting the minimum element and then performs swapping. First, we will find the minimum element from the unsorted subarray, and we will swap the minimum element with an element which is at the beginning position of the array. Initially, we assume that the sorted subarray is empty. In selection sort, an array is divided into two sub- arrays, i.e., one is an unsorted sub-array, and the other is sorted sub-array. Selection sort is one sorting technique used for sorting the array. Sorting means arranging the elements of an array in ascending order. Before understanding the differences, we should know about the selection sort and bubble sort individually. Here we will look at the differences between the selection sort and bubble sort.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |