0% found this document useful (0 votes)
9 views4 pages

Selection Sort

Selection sort is a simple sorting algorithm that works by repeatedly finding the smallest element in an unsorted portion of an array and placing it at the beginning. It does this by iterating through the array, finding the minimum value, and swapping it into the current sorting position. This is done for each element until the array is fully sorted, resulting in a time complexity of O(n^2).

Uploaded by

mo3azsaif.74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Selection Sort

Selection sort is a simple sorting algorithm that works by repeatedly finding the smallest element in an unsorted portion of an array and placing it at the beginning. It does this by iterating through the array, finding the minimum value, and swapping it into the current sorting position. This is done for each element until the array is fully sorted, resulting in a time complexity of O(n^2).

Uploaded by

mo3azsaif.74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SELECTION

SORT

MO3AZ
Selection Sort

A simple sorting algorithm that works by repeatedly selecting the


smallest element from the unsorted portion of an array and places it
at the beginning.

MO3AZ
SAIF
Selection Sort
Example :
Pseudocode :
3 1 4 2
function selectionSort( arr , n )
Min = 3 3>1 => Min
for i from 0 to n - 1 =1
Min = 1 1>4 => Min
minIndex = i =1
Min = 1 1>2 => Min
for j from i+1 to n = 11 3 4 2

if arr[j] < arr[minIndex] Pass=#1


Min 3 : Min3=>14 - Swap(
=> 3Min
,1)
=3
minIndex = j Min = 3 3>2 => Min
=2
swap(arr[i], arr[minIndex]) 1 #2 : Min
Pass 2 =2 - 4Swap( 3 ,32 )
Min = 4 4>3 => Min
Time Complexity in any case : O( ) =3
Pass #3 : Min = 3 - Swap( 4 , 3 )
1 2 3 4

1 2 3 4

MO3AZ
SAIF
QUESTION TIME !

MO3AZ

You might also like