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

Selection Sort

Selection sort works by scanning through an array to find the smallest element, swapping it with the element in the first position, then finding the next smallest and swapping it with the second position, continuing until the array is fully sorted. This process moves each element directly into its final sorted position rather than taking small incremental steps like bubble sort.

Uploaded by

jehoshua35
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Selection Sort

Selection sort works by scanning through an array to find the smallest element, swapping it with the element in the first position, then finding the next smallest and swapping it with the second position, continuing until the array is fully sorted. This process moves each element directly into its final sorted position rather than taking small incremental steps like bubble sort.

Uploaded by

jehoshua35
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SELECTION SORT

SELECTION SORT
• If bubble sort was to be performed on an
bookshelf of books out of order, then comparing
each neighbouring books and then swapping
them over would be an expensive operation as
you would be taking a book out multiple times
depending on the number of swaps and possible
passes.
• The cost of moving items is relatively large
against the cost of comparing items.
Selection Sort
• Scan through all the elements find the smallest
element and then swap it with the element in the
left most position.
• Scan through remaining elements (N-1) finds the
smallest amongst them and then put that
smallest element to the right of the 1 st smallest
element. This process goes on finding the
smallest element to the right of those already
sorted and then doing a swap if necessary. In
this sort each element is moved directly to its
final position rather that taking small steps to the
final position.
first find the smallest in the array and exchange it with the element in
the first position, then find the second smallest element and exchange
it with the element in the second position, and continue in this way until
the entire array is sorted
10 12 2 9 4 6 5 3 1

1 12 2 9 4 6 5 3 10

1 2 12 9 4 6 5 3 10

1 2 3 9 4 6 5 12 10

1 2 3 4 9 6 5 12 10

1 2 3 4 5 6 9 12 10

1 2 3 4 5 6 9 10 12
THE END

You might also like