Gadgets 4 Students Career Guide Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
1.4k views

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Selection sort

It is an sorting algorithm in which the array is divided into sorted array and unsorted array and we need to find the minimum element from unsorted array  and put it in a sorted array sequence.

Algorithm: 

  1. Set minimum element to index 0

  2. Search the minimum element in the array

  3. Swap with value at minimum index 

  4. Increment minimum to point to next element

  5. Repeat until list is sorted

Example: 

a = [64, 25, 12, 22, 11]

here we need to find the minimum element and place it in the beginning from i=0 to 4

11 25 12 22 64

here we need to find the minimum element and place it in the beginning from i=1 to 4

11 12 25 22 64

here we need to find the minimum element and place it in the beginning from i=2 to 4

11 12 22 25 64

here we need to find the minimum element and place it in the beginning from i=3 to 4

11 12 22 25 64

Program Code

def selsort(n):

    for i in range(len(n)-1,0,-1):

        max=0

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

            if n[j]>n[max]:

                max = j

            temp = n[i]

            n[i] = n[max]

            n[max] = temp

n = [78,25,11,29,75,69,45,67]

selsort(n)

print("Sorted array : ",n)

Output

Sorted array : [11, 25, 29, 45, 67, 69, 75, 78]

For more RGPV/UTMP CSE V Sem Python Lab Experiments Click here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...