Selection Sort in python - Data Structures & Algorithms Tutorial Python #19

preview_player
Показать описание
Selection sort is a simple algorithm for sorting, it gives o(n^2) BIG O complexity. In this video we will go over some theory behind selection sort and implement in python. At the end of the video we will have an exercise for you to solve.

🔖Hashtags🔖

#selectionsort #datastructures #algorithms #python #selectionsortpython #sortalgorithm #pythonselectionsort #selectionsort #datastructure #selectionsortcode #selectionsortprogram

#️⃣ Social Medias #️⃣

❗❗ DISCLAIMER: All opinions expressed in this video are of my own and not that of my employers'.
Рекомендации по теме
Комментарии
Автор

I have been seeing your videos for so many years, and to date, I can say you are the best tutor, your way of explaining is very easy and understandable.

wzfcenu
Автор

Thankyou for creating such a wonderful series

priyanshupurohit
Автор

Thank you sir for explaining DSA in such a easy way. Please continue this series.

tamannasangwan
Автор

Please make more videos on topics like greedy, dynamic programming etc. since, its tough to find a channel which teaches on python

ritikajaiswal
Автор

This is my self made code for doing selection sort:


def selectionSort(array):
size=len(array)
for i in range(size-1):
candidate=array[i] # candidate is the minimum element
swap=False
for j in range(i+1, size):
if array[j]<candidate:
candidate=array[j]
index=j
swap=True
if swap:
swapVal=array[i]
array[i]=candidate
array[index]=swapVal
return array

if __name__=="__main__":
element=[38, 7, 29, 9, 2, 15, 7, 28, 3, 83]
print(selectionSort(element))


Thank You for the Playlist. 🙂

tupaiadhikari
Автор

One word for this course Absolutely "PERFECT"
and thanks sir with help of your courses i got job in my 7th sem of college.

sakshamsinha
Автор

I would highly recommend implementing the algorithms yourself after code basics goes through the theory. It really helps and then you can top that up with the exercises. Thanks code basics. Much appreciated

mohammadpatel
Автор

Sir this is an amazing playlist Thanks ♥️.Some basic ds like strings and algo like greedy, dp are still left ...?Are you gonna add more videos to this playlist? and how much time and how many videos can we expect?

trialaccount
Автор

Hi for the exercise on multilevel selection sort, I have an alternative code that is more similar to the normal selection sort. The keys parameter accepts the list of keys that is passed.

def multilevel_selection_sort(arr, keys):
size = len(arr)
for i in range(size - 1):
min_index = i
for j in range(min_index + 1, size):
for key in keys:
if arr[j][key] == arr[min_index][key]:
continue
if arr[j][key] < arr[min_index][key]:
min_index = j
break

if i != min_index:
arr[i], arr[min_index] = arr[min_index], arr[i]

alexlu
Автор

Thanks for this playlist.

Commenting the exercise answer for my reference.
def selection_sort(arr):
size = len(arr)
for i in range(size-1):
min_index = i
for j in range(min_index+1, size):
if arr[j]['First Name'] == arr[min_index]['First Name']:
if arr[j]['Last Name'] < arr[min_index]['Last Name']:
min_index = j
elif arr[j]['First Name'] < arr[min_index]['First Name']:
min_index = j
if i != min_index:
arr[i], arr[min_index] = arr[min_index], arr[i]

sunilingaleshwar
Автор

Wow you bring a clarity to my understanding of DSA Thank you man, and if you don't mind having the slides on the video will be much more helpful to us could you share it with us please? either way you are amazing Thanks

kassahungetachew
Автор

This is amazing playlist❤️
Sir when will you make videos on dynamic programming as it is very important for software interviews??

vatsalsharma
Автор

DONE with 1 for loop!!

elements=[7, 4, 10, 8, 3, 1]
size=len(elements)
j=0
for i in range(size, 1, -1):

#print(ind)
elements[j], elements[ind]=elements[ind], elements[j]
j+=1
print(elements)

debabrataadak
Автор

In the function find_min_elements can we not intialize the first element of the list as the minimum element and then compare and get a minimum value?

debarghyamondal
Автор

l = [4, 38, 17, 21, 25, 11, 32, 9]

def selection_sort(l):
for i in range(len(l)-1):
for j in range(i+1, len(l)):
if l[i]>l[j]:
temp = l[i]
l[i] = l[j]
l[j] = temp
return l

print(selection_sort(l))

# Ithink this approach is also correct and straight forward.

rohitchitte
Автор

Sir I did the exercise. Does the solution take O(n^3) since there is three for loops?
Can we optimize the runtime?

I did it in two for loops, is that efficient than the solution?

amranmohamed
Автор

Sir PLEASE COMPLETE the Python DSA Playlist

cherish
Автор

Can't we use min(arr) to find to minimum element, It's the same time complexity as the function *find_min* anyways!

prashanthveddula
Автор

Hi sir because of you I learn lots of skills for data analysis...
I learn Tableau
Google spreadsheets
MySQL
I think these course are enough for me With presentation skill and mathematical skills.

GANESHSHARMA-zyrg
Автор

Can anyone recommend a good book on Data Structures, that is language agnostic please!

bluesdog