This document presents selection sort, an in-place comparison sorting algorithm. It works by dividing the list into a sorted part on the left and unsorted part on the right. It iterates through the list, finding the smallest element in the unsorted section and swapping it into place. This process continues until the list is fully sorted. Selection sort has a time complexity of O(n^2) in all cases. While it requires no extra storage, it is inefficient for large lists compared to other algorithms.
Contents
Description.
SortAlgorithm.
Example.
Analysis.
Advantages of Sorting Algorithms.
Disadvantages of Sorting Algorithms.
3.
Description
This sortingalgorithm 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.
4.
Description Contd.
Thesmallest 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
each time selecting an item according to its ordering
and placing it in the correct position in the sequence.
5.
The Selection SortAlgorithm
For each index position i
Find the smallest data value in the array from positions i
through length - 1 , where length is the number of data
values stored.
Exchange (swap) the smallest value with the value at
position i.
6.
Algorithm
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
Advantages & Disadvantages
AdvantagesDisadvantages
The main advantage of the
selection sort is that it performs
well on a small list.
no additional temporary
storage is required.
The primary disadvantage of
the selection sort is its poor
efficiency when dealing with
a huge list of items.
the selection sort requires n-
squared number of steps for
sorting n elements.