0% found this document useful (0 votes)
7 views

Data Structure and Algorithms Selection Sort

Selection sort can be good for checking if data is already sorted or when memory space is limited. It works by finding the minimum element in an array and swapping it into sorted position without using extra storage. The algorithm involves setting a minimum index, finding the minimum element, swapping it into position, and repeating until sorted.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Data Structure and Algorithms Selection Sort

Selection sort can be good for checking if data is already sorted or when memory space is limited. It works by finding the minimum element in an array and swapping it into sorted position without using extra storage. The algorithm involves setting a minimum index, finding the minimum element, swapping it into position, and repeating until sorted.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Data Structure and Algorithms

Selection Sort
Selection sort can be good at checking if everything is
already sorted. It is also good to use when memory space
is limited. This is because unlike other sorting algorithms,
selection sort doesn’t go around swapping things until the
very end, resulting in less temporary storage space used.
So that’s selection sort. Sorting algorithms is often one of
the things that have a high chance of cropping up in
technical tests, so be sure to know how they work, even if
you don’t end up using them in your projects.
The purpose of technical tests is to check your awareness
of algorithms, which in turn deals with data and
everything boils down to data if you think about it.
What is selection sort?
The selection sort algorithm is based on the
logic of locating and sorting the smallest
element in an array. The selection sort algorithm
is actually a comparison-based algorithm in
which the entire input array is divided into two
sections, one sorted and one unsorted. The
other types of sorting (i.e., insertion sort) are
also based on in-place comparisons.
Now, let us learn some programming aspects of
selection sort.
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
Characteristics of Selection Sort
• The selection sort's primary advantage is that
it performs well on small lists.
• Because it is an in-place sorting algorithm, no
additional temporary storage beyond that
required to hold the initial list is required.
• The selection sort's disadvantage is its
inefficiency when dealing with large lists of
items.
Another Example:

You might also like