Тёмный

Selection Sort: Background & Python Code 

Brian Faure
Подписаться 13 тыс.
Просмотров 6 тыс.
50% 1

In this lesson we'll introduce the Selection Sort algorithm, a very simple approach to sorting lists and arrays. After covering the basics, we'll open up a coding editor and implement the algorithm in Python, at the end we'll benchmark the performance of the algorithm against various other sorting approaches, including our Bubble Sort from the prior video.
Bubble Sort Lesson: • Bubble Sort: Backgroun...
If you'd like to learn about Python data structures, check out my video series starting with: • Python Data Structures...
Video series covering GUI development in Python: • Python GUI Development...
References:
[1] bigocheatsheet.com/
[2] en.wikipedia.org/wiki/Selecti...
End song is "Paris" by LASERS.

Опубликовано:

 

19 сен 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 15   
@Oryx_777
@Oryx_777 6 лет назад
you`r channel super cool. Thanks for your job.
@BrianFaure1
@BrianFaure1 6 лет назад
It would be far more pythonic to replace the for loop in the code from lines 13 to 18 with a single call to the "min" function, but I've refrained from this so that the code can be more portable to other languages. Take note that if you're sticking to Python, lines 13 to 18 could be replaced with the following single line of code: min_idx=a[sort_len:].index(min(a[sort_len:]))+sort_len For further simplification, you may choose to replace the sort_len declaration and while loop on lines 11 and 12 with a single for loop [for sort_len in range(len(a))], in which case you wouldn't need to increment the sort_len variable on each iteration (line 20).
@harunsalman1199
@harunsalman1199 5 лет назад
Quality videos Brian!! Just wasn't sure about the purpose by initializing min_idx=None instead of min_idx=0?
@Promar22
@Promar22 5 лет назад
Great video, I'm just having a little trouble understanding one small part why do you add sort_len in the line min_idx = i + sort_len, why not just min_idx = i? Thanks
@BrianFaure1
@BrianFaure1 5 лет назад
Hey Omar, thanks for watching! In the for loop we're iterating over the remaining elements in the unsorted portion of the array, which starts at the end of the sorted portion (at index equal to 'sort_len'). Despite this, our index variable for the for loop, 'i', begins at 0. To translate 'i' into our index in the overall array (containing both the sorted and unsorted portions) we need to add the length of the sorted portion 'sort_len' to 'i'. If we didn't add sort_len to i then the element we are currently looking at a[i] wouldn't be the element 'elem' (at a[sort_len+i]) it would actually be some other element at a lower index, offset to the left by the current length of the sorted portion. It's somewhat confusing because the enumerate function is returning an index 'i' that doesn't correspond to the actual location of the element 'elem', but that's because we're calling enumerate on only a portion of the array a[sort_len:] (the unsorted remaining portion). If you have any other questions or need this clarified be sure to let me know.
@Promar22
@Promar22 5 лет назад
@@BrianFaure1 Thanks for the really in depth explanation, I understand now!
@eytchde
@eytchde 6 лет назад
need help: sponge_gar.zip not found How do i fix this
@BrianFaure1
@BrianFaure1 6 лет назад
Here this should help you out bruh: i.imgur.com/Kzk9I8o.png , let me know if this fixes the error.
@nashaeshire6534
@nashaeshire6534 4 года назад
Great explanation. As good as CS50 from Harvard.
@isha6510
@isha6510 5 лет назад
if the default method is better than these sorting techniques then why do we use them??
@BrianFaure1
@BrianFaure1 5 лет назад
Well, in this case, the default sorting method for Python is probably written in C or some other lower level language, or C compiled from Python code, so it will always be faster. The actual algorithm they use though is likely one of the more efficient of the 5 or so people generally learn (Quicksort, Merge sort, etc). The reason for learning various different sorting algorithms is to introduce some examples of algorithmic efficiency and to learn to compare different algorithms that all have the same goal and result, not just based on the result, but on the speed and memory complexity. I think that teaches people to not just always accept the first solution they come up with, and to try to think of alternatives that might be better.
@isha6510
@isha6510 5 лет назад
@@BrianFaure1 thanks for the answer. I really like it videos. It helped me a lot ... Can u please also upload videos for stacks and queues like u did for linked list?
@BrianFaure1
@BrianFaure1 5 лет назад
@@isha6510 I've got a couple I'm actually working on now, I just have waaay less time than I did last year so it takes forever to fact check and make sure all the code has minimal bugs. But yeah I'll look into stacks and queues. For time being I'd recommend checking out mycodeschool, I'm sure that man has covered them considering he has videos on literally everything lmao. Thanks for watching!
@isha6510
@isha6510 5 лет назад
@@BrianFaure1 thanks for the recommendation
@mishavlog7112
@mishavlog7112 6 лет назад
Bla bla bla bla, why is this video so fast
Далее
Insertion Sort: Background & Python Code
8:55
Просмотров 6 тыс.
The Bubble Sort Curve
19:18
Просмотров 521 тыс.
BRO, EXCEEDED EXPECTATIONS 🥶 #shorts
00:13
Просмотров 651 тыс.
Python Decorators in 15 Minutes
15:14
Просмотров 435 тыс.
The moment we stopped understanding AI [AlexNet]
17:38
Просмотров 879 тыс.
This AI Agent with RAG Manages MY LIFE
10:52
Просмотров 6 тыс.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Genetic Algorithms Explained By Example
11:52
Просмотров 320 тыс.
What's Your ENGLISH LEVEL? Take This Test!
21:31
Просмотров 1,8 млн
The Clever Way to Count Tanks - Numberphile
16:45
Просмотров 850 тыс.
Sorting Algorithms Explained Visually
9:01
Просмотров 527 тыс.
why are switch statements so HECKIN fast?
11:03
Просмотров 395 тыс.
Merge Sort In Python Explained (With Example And Code)
13:35
BRO, EXCEEDED EXPECTATIONS 🥶 #shorts
00:13
Просмотров 651 тыс.