ONLINE SUMMER TRAINING Online Courses Free Tutorials 
 Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
0 like 0 dislike
150 views
in RTU/BTU B.Tech(CSE-VI SEM) PYTHON LAB by Goeduhub's Expert (7.6k points)
Write a Program  to implement Selection sort

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

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

Ques . Write a Program  to implement Selection sort

Answer : Selection sort 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 = [86, 45, 6, 32, 5]

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

5 45 6 32 86

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

5 6 45 32 86

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

5 6 32 45 86

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

5 6 32 45 86

program : 

def selection_Sort(L):
   # i indicates how many items were sorted
   for i in range(len(L)-1):
        # To find the minimum value of the unsorted segment
        # We first assume that the first element is the lowest
        min_index = i
        # We then use j to loop through the remaining elements
        for j in range(i+1len(L)-1):
            # Update the min_index if the element at j is lower than it
            if L[j] < L[min_index]:
                min_index = j
        # After finding the lowest item of the unsorted regions, swap with the first unsorted item
        L[i], L[min_index] = L[min_index], L[i]
   return L

# Driver code to test above  
L = [801060407050
print("Unsorted list is:",L)
# Let's see the list after we run the Selection Sort
print("Sorted list is:",selection_Sort(L))

Output : 

Unsorted list is: [80, 10, 60, 40, 70, 50] 

Sorted list is: [10, 40, 60, 70, 80, 50]


For more Rajasthan Technical University CSE VI Sem Python Lab Experiments Click here


Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

 Goeduhub:

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