Selection sort with Python

Photo by Sabri Tuzcu on Unsplash

Selection sort with Python

Hey techies, I hope and wish u have a good day today, welcome to this week's article. Today, we are going to learn about "Selection Sort" with python" . Hope you are loving my articles and I appreciate it if you show a response by commenting, liking or even sharing on your socials. I am focusing more on Python .so I also suggest you to read my previous articles on Python.

1.) What is Selection Sort?

Selection sort sorts the elements in the un-sorted array.

2.) How it Works?

We will sort the array elements from [left-right] It will choose the minimum element and it will compare that minimum element to the end of loop to see whether any other element is shorter than current .if present then it will select it as minimum and keep its in the first place of array.

3.) Time Complexity?

Selection Sort has a time complexity of O(n^2).

Let's Easily Understand with codenow:

#Present in un-sorted format
arr = [8,5,1,3,7] 

for i in range(0,len(arr)):
    min_ind = i 
    for j in range(i+1,len(arr)):
        if arr[min_ind] > arr[j]:
            min_ind = j
    arr[i],arr[min_ind] = arr[min_ind],arr[i]

print('The array after sorting in Ascending Order by selection sort is:')
print(arr)

#Sorted array
[1,3,5,7,8]

4.) Advatages of Bubble sort ?

  • it performs well on a small list.

  • Selection sort helps in sorting the algorithm by checking the whole array for minimum and swaps it at that iteration for "n" or "loop" times.

5.) Dis-advantages of Bubble sort ?

  • Time complexity of " O(N^2) " which is very slow.

  • It is not efficient for large lists of data.

I hope that u enjoyed reading the blog, However, I'm glad you will find the information helpful! If you enjoyed the blog, feel free to share it with others who might find it interesting. Sharing knowledge and information is always a great way to help others learn and grow.

"HAPPY LEARNING - HAPPY CODING"

Quote Of The Day~~

Did you find this article valuable?

Support Smd Sohail by becoming a sponsor. Any amount is appreciated!