Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views2 pages

Selection Sort

Selection sort is an in-place sorting algorithm that improves upon bubble sort by making only one exchange per pass. It works by repeatedly finding the smallest element in the list and swapping it with the current position until the entire list is sorted in ascending order. The document also includes a Python implementation of the selection sort algorithm.

Uploaded by

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

Selection Sort

Selection sort is an in-place sorting algorithm that improves upon bubble sort by making only one exchange per pass. It works by repeatedly finding the smallest element in the list and swapping it with the current position until the entire list is sorted in ascending order. The document also includes a Python implementation of the selection sort algorithm.

Uploaded by

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

SELECTION SORT

 Selection sort is an in-place sorting algorithm. This sorting technique improves over
bubble sort by making only one exchange in each pass.

 The selection sort finds the smallest element in the list and it is swapped with the first
element in the list.

 Then the second smallest element is searched and it is swapped with the second
element in the list.

 This selection and exchange process continues, until all the elements in the list have
been sorted in ascending order.

 This algorithm is called selection sort since it repeatedly selects the smallest element.
Algorithm

1. Find the minimum value in the list

2. Swap it with the value in the current position

3. Repeat this process for all the elements until the entire array is sorted.

Implementation

def selectionsort(A):

for i in range(len(A)):

minimum=i

for j in range(i+1,len(A)):

if A[j]<A[minimum]:

minimum = j
swap(A,minimum,i)

def swap(A,x,y):

temp=A[x]

A[x]=A[y]

A[y]=temp

A=[54,26,93,17,77,31,44,55,20]

selectionsort(A)

print(A)

You might also like