Python: SelectionSort algorithm

preview_player
Показать описание
Selection Sort algorithm explained in animated example, with demo Python code implementation example.

PYTHON SORTING ALGORITHMS

#Python
Рекомендации по теме
Комментарии
Автор

That sound at the beginning man, it always startled me lmfao. Great tutorials btw!

tomcat
Автор

this is one of the best tutorials on YouTube, really appreciated. understanding the logic is very important and u explain that in the best way, I wish you could explain your code step wise in details, it would really help beginners a lot.
keep up the good work, cheers!

santoshpaul
Автор

great tutorial, useful for basic school levels.
thanks!

guidofabris
Автор

Very nice explained man, thanks alot it worked on my algorithm, im gonna show this video to my classmates if you dont mind

Satenc
Автор

This video really helped me understand selection sort, but I have a question—when writing the first for loop, why do we want our range to end at the second-to-last number?

KaiserWilhelmtherd
Автор

def selection_sort(A):
for i in range(0, len(A) - 1):
minIndex = i
for j in range(i+1, len(A)):
if A[j] < A[minIndex]:
minIndex = j
if minIndex != i:
A[i], A[minIndex] = A[minIndex], A[i]

xy
Автор

I am not good at Python but in C selection sort would look like this

void selectionSort(node **head)
{
node *sorted, *trav1, *trav2, *max, *maxPrev;

sorted = NULL;
trav1 = (*head);

while(trav1 != NULL)
{
//Wyszukiwanie elementu o najwiekszej wartosci klucza zachowujac jego poprzednika
trav2 = trav1;
max = trav1;
maxPrev = NULL;
while(trav2->next != NULL)
{
if(trav2->next->key >= max->key)
{
maxPrev = trav2;
max = trav2->next;
}
trav2 = trav2->next;
}
//Usuwanie dowiazan do znalezionego elementu
if(trav1 == max)
trav1 = max->next;
else
maxPrev->next = max->next;
//Wstawienie znalezionego elementu na poczatek listy
max->next = sorted;
sorted = max;
}
(*head) = sorted;
}

// Polish is my native language and thats why comments are in polish

holyshit
Автор

you should finish this tutorial by putting a return selection_sort at the end and put on a list to sort.
that would make for a better video

rverm
Автор

Very Clear Explanation! Thanks for clearing my doubts on it!

ssng
Автор

Can u suggest any website for practicing sorting in python ?

sailasyayadala
Автор

These videos are really helpful and detailed. Thank you !!

hardikgarg
Автор

it works nice and thank you. i added a 'print (A)' to mine so that I could see the output of the resorted list.

MissOakland
Автор

Thank you for the helpful tutorial videos. It really gave me a clear understanding of the different sorting algorithms.

blueberrychampagne
Автор

Please I need your assistance in doing a project I am trying

obedhi
Автор

Very straight forward, just one thing: what does the last line of your code mean?

mingyangli
Автор

That opening and ending music gave me a heart attack ..

deepikasalem
Автор

Sorry sir code is not working. I give a input statement after that I write down exact code as you suggest than I write a return and print statement. There is not any type of error but when I give input of 90 70 50 30 10 80 60 40 20 then it give output 10 30 50 70 90 80 60 40 20.

deepakjangir
Автор

Thanks for the video, helped me understand but do we really need if statement at line 7. I didn’t really understand why that is necessary. Once you have minIndex I don’t think it is necessary to put a condition until unless I am missing something.

rif
Автор

Could you explain line 4 - for j in range(i+1, len(A)): ?

papakazoo
Автор

The second if statement is not indented.

ishanmishra
welcome to shbcf.ru