Data Structures
Home / My courses / BCA204A21T / Unit 2 - SEARCHING & SORTING -Selection Sort / SELECTION SORT
SELECTION SORT
Definition
Example
Algorithm
Definition : Selection Sort
Selection sort is a simple sorting algorithm. This sorting algorithm is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at
the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list.
The smallest element is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array. This process
continues moving unsorted array boundary by one element to the right.
This algorithm is not suitable for large data sets as its average and worst case complexities are of Ο(n2), where n is the number of items.
Example
◄ QUICK SORT Jump to... Selection Sort Demo ►
Data Structures
Home / My courses / BCA204A21T / Unit 2 - SEARCHING & SORTING -Selection Sort / SELECTION SORT
SELECTION SORT
Definition
Example
Algorithm
Algorithm
Steps to be followed for Selection Sort:
Step 1 − Set MIN to location 0
Step 2 − Search the minimum element in the list
Step 3 − Swap with value at location MIN
Step 4 − Increment MIN to point to next element
Step 5 − Repeat until list is sorted
Algorithm: Selection Sort
procedure selection sort
list : array of items
n : size of list
for i = 1 to n - 1
/* set current element as minimum*/
min = i
/* check the element to be minimum */
for j = i+1 to n
if list[j] < list[min] then
min = j;
end if
end for
/* swap the minimum element with the current element*/
if indexMin != i then
swap list[min] and list[i]
end if
end for
end procedure
Challenging Questions
◄ QUICK SORT Jump to... Selection Sort Demo ►
Data Structures
Home / My courses / BCA204A21T / Unit 2 - SEARCHING & SORTING -Selection Sort / SELECTION SORT
SELECTION SORT
Definition
Example
Algorithm
Example : Selection Sort
Step 1: Find the smallest element. Compare the smallest element 11 with the first element in the array 64.
Since 11 is less than 64, so swap it
Step 2: Start scanning the entire list, and find the next least element i.e 12. It is compared the element in the second position 25. Compare and swap it
Step 3: Start scanning the entire list, and find the next least element i.e 22. It is compared the element in the third position 25. Compare and swap it
The list is completely sorted.
Steps to be followed for Selection Sort:
◄ QUICK SORT Jump to... Selection Sort Demo ►