Тёмный
No video :(

Quick Sort Algorithm Explained (Full Code Included) - Python Algorithm Series for Beginners 

Derrick Sherrill
Подписаться 84 тыс.
Просмотров 176 тыс.
50% 1

This is a part of a full algorithm series - Check it out here:
• Bubble Sort Algorithm ...
Kite helps fund the channel, thanks for checking them out and supporting me --
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. www.kite.com/g...
#Python #QuickSort #Algorithm
In this one we're covering the quick sort algorithm! One of the favorite sorting algorithms due to its speed in an average case.
The Quick Sort algorithm takes an item from the unsorted list and uses it as the 'pivot' or the item to compare the remainder of the items in the list. We do comparisons placing the items in lists according to if they are larger or smaller than the pivot value.
We repeat this process creating smaller and smaller lists until we have list values of one which have been sorted.
Join The Socials -- Picking Shoutouts Across RU-vid, Insta, FB, and Twitter!
FB - / codewithderrick
Insta - / codewithderrick
Twitter - / codewithderrick
LinkedIn - / derricksherrill
GitHub - github.com/Der...
Thanks so much for the continued support of the channel! You guys are awesome and I'm very thankful to be at this point. 5,500+ subscribers at the time of writing. Thank you all so much!
*****************************************************************
Full code from the video:
def quick_sort(sequence):
length = len(sequence)
if length #less than= 1:
return sequence
else:
pivot = sequence.pop()
items_greater = []
items_lower = []
for item in sequence:
if item #greater than pivot:
items_greater.append(item)
else:
items_lower.append(item)
return quick_sort(items_lower) + [pivot] + quick_sort(items_greater)
print(quick_sort([5,6,7,8,9,8,7,6,5,6,7,8,9,0]))
#RU-vid Doesn't allow angled brackets - Sorry about that!
github.com/Der...
Packages (& Versions) used in this video:
Python 3.7
Atom Text Editor
*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:
github.com/Der...
Check out my website:
www.derrickshe...
If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!
--- Channel FAQ --
What text editor do you use?
Atom - atom.io/
What Equipment do you use to film videos?
www.amazon.com...
What editing software do you use?
Adobe CC - www.adobe.com/...
Premiere Pro for video editing
Photoshop for images
After Effects for animations
Do I have any courses available?
Yes & always working on more!
www.udemy.com/...
Where do I get my music?
I get all my music from the copyright free RU-vid audio library
www.youtube.co...
Let me know if there's anything else you want answered!
-------------------------
Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!

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

 

14 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 396   
@tai-shanlin615
@tai-shanlin615 4 года назад
this is the cleanest implementation of quicksort that I have seen. period. So easy to follow! Subscribed
@UnknownSend3r
@UnknownSend3r 3 года назад
100% it was clear and concise.
@riszard999
@riszard999 3 года назад
it's slower and has bigger memory complexity :)
@tursunalikholdorov1853
@tursunalikholdorov1853 3 года назад
@@riszard999 Do you know more efficient implementation?
@UnknownSend3r
@UnknownSend3r 3 года назад
@Leland Jon ofcourse we care that you hacked her account in 15 mins, Il be sure to use it once I've replied to that Nigerian prince that's been messaging me recently.
@waseemq1522
@waseemq1522 3 года назад
FRRR
@NEMOBANDZBEATS
@NEMOBANDZBEATS 2 года назад
This is the best explanation I have seen so far. It’s like other people try to explain things in the hardest way possible so you could think they’re more smart lol
@ugurdev
@ugurdev 3 года назад
Hey man, you are one of the most underrated channels on youtube for Python. It is sad to see you haven't uploaded in a while, but I hope everything is going well for you. Thank you for all you have done.
@icewreck
@icewreck 3 года назад
Quick sort is generally in-place, and your implementation, while simple to understand, is isn't which means it would have a disastrous memory footprint for larger input sets.
@ctormin
@ctormin 3 года назад
I wish every video on the internet was like this. You made my day, for real.
@fuleswaripal9536
@fuleswaripal9536 3 года назад
Why is this dude so underrated . I was searching for tutorials of sorting algorithms I didn't find a single video which explained well and mostly all the sorting videos were about bubble sort . Now after 2 days his video come to my recommendation.And yeah bro keep up the good work I can't even explain how much these sorting tutorials helped me keep it up . You will surely get what you deserve once👍👍😁
@nikomiller6168
@nikomiller6168 3 года назад
Great tutorial! However, quicksort is an in-place algorithm. This implementation is not in-place since it creates new lists rather than modifying the original. The in-place version is naturally a bit trickier, which is why most people seem to get your version better. Nevertheless, this video does a great job in explaining the intuition behind the algorithm.
@Sixthfred
@Sixthfred 4 года назад
Although it isn't in-place, your tutorial was very simple to understand and should definitely be how Quicksort ought to be taught!
@anshimagarg9661
@anshimagarg9661 3 года назад
Oh my god !! The best video of quick sort ! This is the first time I visited your channel and I'm totally recommending this to all my friends !!! thanks s lot ❤️❤️
@pratikzajam799
@pratikzajam799 4 года назад
man ur amazing, understood first time quick sort in my life
@user-ze7sj4qy6q
@user-ze7sj4qy6q 3 года назад
just found this channel rn and this dude is so easy to understand and chill (but not boring) untapped resource of knowledge right here
@webknowledge9989
@webknowledge9989 2 года назад
this is the BEST explanation of quicksort, EVER.
@UnrecycleRubdish
@UnrecycleRubdish 4 года назад
This was incredible. Thank you for explaining these algorithms in simple terms for beginners to understand. Your explanations are clear and your code clean. Cannot be thankful enough.
@glorysonhorace3265
@glorysonhorace3265 2 года назад
I'd definitely recommend this channel to everyone who wants to learn DSA in a very clear and easy-to-understand way. Thanks Derick Sherrill for this tutorial. Keep posting more and more videos
@chesslearn8103
@chesslearn8103 4 года назад
I have finally found a clear, well explain and simple answer to my questions. Ty very much.
@user-ng4bc3cv6g
@user-ng4bc3cv6g 3 года назад
Thank you, I understood the algorithm in the first 2 minutes of the video.
@pritam1366
@pritam1366 3 года назад
Man this is by far the best explanation, i wasted my time on so many videos. Thanks man
@linneadahmen5962
@linneadahmen5962 3 года назад
I kept thinking, I know I'm not stupid. I know I understand the logic. Why can't I understand anyone's CODE? and then I found this video. This code & your explanation is EXACTLY how my brain works and understands it. thank you for rocking.
@MariaAllstar
@MariaAllstar 3 года назад
Hi, Derrick! Thanks for your explanation, it was very helpful :) Anyway I found a small bug in your implementation. As you `pop()` to extract the pivot from the list, the values from the original list are modified. This causes that if the input array is already sorted you loose the pivot, which is your case is the last position. For a real code example of the situation, look at the following assertion: `quick_sort([1, 2, 3, 4, 5, 6, 7]) == [1, 2, 3, 4, 5, 6]` (note that the 7 is missing). This can be solved by using an operation that does not affect the original variable outside of the function's scope, like this two line version of pop: ``` pivot = sequence[-1] sequence = sequence[:-1] ``` Regards!
@belhaddadmohamed7
@belhaddadmohamed7 Год назад
Hi, Maria i don't find any error the output will be: [1, 2, 3, 4, 5, 6, 7] the value of the pivot is already stored in pivot variable thank you,
@pragyantiwari3885
@pragyantiwari3885 10 месяцев назад
Derrick already restored the pivot value at the end return statement....so the code works right . And Even I am not having problem with it
@jesuisravi
@jesuisravi 2 года назад
I appreciate that you take pains to make the coding easy to read. Many coding videos are essentially useless because the presenter doesn't magnify the code.
@msh104utube
@msh104utube 3 года назад
Nothing beats the smell of clean code in the morning. Great job, very clean code.
@FaysalIshtiaq
@FaysalIshtiaq 4 года назад
Quicksort is an in-place sorting algorithm. It is supposed not to take any additional space.
@left_eyebr0w
@left_eyebr0w 4 года назад
any tips on how upgrade it ?
@DeadManProp
@DeadManProp 4 года назад
You're referring to a different version of quicksort. Not all quicksort algorithms are "in-place".
@sq6003
@sq6003 4 года назад
@@DeadManProp is this version recursive?
@user-ky2vl2wm3j
@user-ky2vl2wm3j 2 года назад
With all that animation and description, it was great. So clean. I'm a beginner at programming and yet all this made complete sense. Thanks, man. Subscribed.
@ezekieljoseph1668
@ezekieljoseph1668 8 месяцев назад
Thanks, you have no idea how much this helps.
@easynow6599
@easynow6599 2 года назад
this kind of videos i wish i found for every algorithm i am searching.. 1) sort..really sort 2) straight to the explanation with example with nice visuals 3) code, simple and 1 to 1 match with the example and without any fancy and useless coding elements
@Knut_Eisbaer
@Knut_Eisbaer Год назад
That was an incredible explanation, man. That's pure elegance.
@roubarizkallah2172
@roubarizkallah2172 3 года назад
Strongly recommend this video for beginners. Cute guy and great teacher, what else would u ask for XD. More seriously now, short video with good editing going straight to the point and explaining this concept in a simple way. Thank you man, keep it up.
@gabrielkondo5246
@gabrielkondo5246 2 месяца назад
Bro, this is the best explanation and small and eficient code i've ever seen so far
@souvikguria1414
@souvikguria1414 3 года назад
after going over 4-5 paid rock hard explanations I found your channel....liked, shared, subscribed faster than any sorting algorithm :P
@shrirajshakunt7203
@shrirajshakunt7203 3 года назад
Where were you, Derrick...you saved my life. best of best programming video so far.
@gautamacharekar
@gautamacharekar 4 года назад
Hi Derrick, Thanks for wonderful and simple explanation of the quick sort algorithms. Never understood the quick sort much better. Could you also please explain time and space complexity of the algo that you explain. Then it would be more clear to understand advantage of one over other. Thanks again
@DeadManProp
@DeadManProp 4 года назад
for i in range(1, infinity): print("THANK YOU!!")
@grishakek
@grishakek 4 года назад
while True: print("this is better")
@halfword
@halfword 4 года назад
DeadManProp amazing
@Cartouchai
@Cartouchai 3 года назад
@Nishad Joshi lol recursion is the best 1
@Cartouchai
@Cartouchai 3 года назад
@Nishad Joshi jks stack overflow
@hemantkosrekar3309
@hemantkosrekar3309 3 года назад
How he choose pivot = sequence.pop() It returns additional character y 🤔?
@fazilrahmanz9797
@fazilrahmanz9797 6 месяцев назад
I was like keep on looking into many youtube videos to find a perfect video for quick sort then landed over here and got the most easiest and understandable way to code it in python for the quick sort !!
@kamilosok4454
@kamilosok4454 3 года назад
You wrote this algorithm more clearly than anyone else I've seen
@soseofficial3923
@soseofficial3923 2 года назад
if i was rich i would have donated 10,000 dollars to you for this best explanation of quick sort. Thank you Derrick sherrill. God Bless you
@shreehari2589
@shreehari2589 3 года назад
This gotta be the awesomest explanation about quick sort, great job Derrick keep up the good work, i hope to see more data structures and algorithms tutorials from you!!!
@abhishekbhardwaj7214
@abhishekbhardwaj7214 4 года назад
Thanks for making it a piece of cake man, cheers.
@arielm7248
@arielm7248 4 года назад
Amazing explanation!!!!!!!! Much better than what my TA's and Prof did in a whole week.. you did it in 6 minutes!!!! Thank you~~
@dikshyantauprety4020
@dikshyantauprety4020 2 года назад
The simplicity of this is divine..... Thank you so much
@ayman6237
@ayman6237 4 года назад
This is the best, cleanest, efficient and the most beginner friendly quick sort algorithm i've stumbled upon. Thanks my man!
@mayankbaber9384
@mayankbaber9384 2 года назад
I've my university prac exam tomorrow and U JUST FU*KING NAILED IT MAN!!!!!! YEAH, U ALSO EARNED A SUB!!!!
@tingtingcheng6386
@tingtingcheng6386 11 месяцев назад
Amazing, after watching so many videos... I finally got it! so underrated tutorial
@sakshiwahi2025
@sakshiwahi2025 3 года назад
WHOA 🤯🤯 HOW COULD YOU MAKE IT SO EASY TO UNDERSTAND !!!!!
@Nick-gs4em
@Nick-gs4em 2 года назад
Bro keep doing what you're doing I spent like an hour trying to understand quicksort, and the code to implement it, and I got it after 5 minutes of your video!
@engdoretto
@engdoretto 2 года назад
The best explanation I found on the internet… thanks a lot!
@mohammedumarfarhan9900
@mohammedumarfarhan9900 2 года назад
Man ur a freaking genius May God bless u abdundantly
@turjo119
@turjo119 3 года назад
My God I've been searching for hours for an easy coding solution to follow. Your vid literally saved me! Thank you so much
@sud0gh0st
@sud0gh0st 2 года назад
You explained it perfectly in 6 minutes can't argue that this is content with value got my sub
@sagarsonkar6961
@sagarsonkar6961 Год назад
Wtf man I'm literally stunned on how easy you made it.
@nappdaddy2000
@nappdaddy2000 4 года назад
just finished mosh's python course...was interested in algorithms for sorting and graphing(searching)... Great video, well explained, thanks mate!
@benjaminbennington213
@benjaminbennington213 3 года назад
Wow that was amazingly simple. I learned this a while ago in college, but my teacher made it a 3 week process that was beyond confusing. That was so clean and simple. Great job. I immediately subscribed.
@HamzaKhan-zj6dn
@HamzaKhan-zj6dn 6 месяцев назад
first time was able to understand this algo....loved it...
@pegahmirabedini1848
@pegahmirabedini1848 2 года назад
This tutorial is the clearest description of the quick sort algorithm that I found on RU-vid. Can you add a discussion of why the time complexity if nlogn, please?
@srijitbhattacharya6770
@srijitbhattacharya6770 Год назад
this is certainly one of your top drawer explanantions
@samer820
@samer820 2 года назад
I have watched multiple quicksort videos and so far this is the best and the cleanest explanation I have seen so far 👍
@nehalzaman1159
@nehalzaman1159 Год назад
Thanks sir! I have seen various implementations of quick sort that literally made no sense to me, until I saw your explanation. That is really an awesome implementation. If I say thanks 100 times, that would still not enough. Keep up the good work, sir!
@raweenweerakoon6086
@raweenweerakoon6086 2 года назад
Superb one ☝️ even our lecturer was unable to give complete idea and unable to gave a code like this simple. it was very complicated i gave it up then searched and fined this what an algorithm great keep your good work😊❤️
@subhashreebehera2994
@subhashreebehera2994 3 года назад
I am a beginner in ds algo...after seeing another video thought of quiting as I couldn't understand properly but ur videos now made me wanting to learn more...how amazing explanations man🙏🙏
@kavizz_lifestyle
@kavizz_lifestyle 3 года назад
The best. Dropping a like. Subscribed. Suggested your channel to my friends. Keep doing more videos like this !
@054siddarth3
@054siddarth3 3 года назад
Oh my god! this is the best and easiest solution of quicksort, thank you so much.
@wissammoussa7540
@wissammoussa7540 3 года назад
oh my god man thank you!!! I wasted my afternoon watching quicksort animations and I finally understand it
@arunnp7348
@arunnp7348 2 года назад
Excellent explanation...I went through multiple videos about quick sorting & Hands down , this one is the best !!
@girishkakumanu4117
@girishkakumanu4117 Год назад
FANTASTIC TUTORIAL! I always thought quick sort was the hardest, but your video helped me learn it thoroughly. Tysm!
@robertue1
@robertue1 2 года назад
Great, really simple and easy to follow explanation, thanks Derrick.
@alwayssporty8102
@alwayssporty8102 3 года назад
best quicksort video on this planet thanks bro
@PeizhiYan
@PeizhiYan 10 месяцев назад
Absolute amazing! Your tutorial is the best and most understandable I have ever watched!
@abhinabamajumder4818
@abhinabamajumder4818 4 года назад
Thank you so much specially for simplifying it to such an extent. Artistic elegance!
@0xd4n10
@0xd4n10 4 года назад
Amazing explination! Most of the other tutorials are so hard to follow. Subscribed!
@lokeshnaidu1935
@lokeshnaidu1935 3 года назад
Ohhhhhh your code logic simplicity is really awesome derrick
@nokibulislam9423
@nokibulislam9423 4 года назад
this is the most underrated channel i have ever seen .Keep up the good work man
@tareqmahmud3902
@tareqmahmud3902 3 года назад
you ar ethe best-est teacher I can ever imagine...thank you ...!
@bsdtux
@bsdtux 4 года назад
Agree with the comments below. I was trying to understand the implementation from "The Practice of Programming" but quickly got confused trying to reimplement their version from C to python. Watching your video breaking down the concepts I got it right away. Many thanks for this video
@tuesdayb3957
@tuesdayb3957 Год назад
Thank you for this. I wish I saw this prior to my coding interviews. New subscriber here
@rob_dyy
@rob_dyy 4 года назад
This is one of the cleaner implementation of all the quicksort I've seen
@DeepakSah3.0
@DeepakSah3.0 4 месяца назад
You deserve likes and comments and subscriber. Keep going and growing,
@richcs8287
@richcs8287 2 года назад
Hi Derrick, Thanks for wonderful and simple explanation of the quick sort algorithms. Never understood the quick sort much better.
@mohitshetty8535
@mohitshetty8535 2 года назад
You are making coding easier for me. Thank you.
@davidle8881
@davidle8881 4 года назад
I don't normally comment on the video. This is by far an easier explanation to quicksort.
@shiv4667
@shiv4667 3 года назад
Was thinking of making a sorting visualiser project. Now I can code this in JavaScript for sure. Thanks man!
@Nikhilkumar-ro4nc
@Nikhilkumar-ro4nc 3 года назад
Great learning experience, really clean implementation. But I have a small doubt here : your implementation takes extra space for storing two partition array but by definition quick sort should be "in-place" algorithm. Space complexity is quick sort's edge over Merge. Will this implementation work in interviews ?
@aryansinghthakur16
@aryansinghthakur16 2 года назад
Yes , i have same doubt This is not optimal in space...!!
@gedeonnokbak760
@gedeonnokbak760 3 месяца назад
awesome bro, very helpful to understand quick sort behind the scene. marvelous. But if the space complexity matter the most, we could struggle with your algorithm, since quick sort should be an in-place algo. But this is the best intuitive explanation of quick sort I have ever seen. Awesome
@Cpt.C
@Cpt.C Год назад
This implementation is also good. def quick_sort(arr): if len(arr) pivot] return quick_sort(left) + middle + quick_sort(right)
@helikopter1231
@helikopter1231 2 года назад
This pythin solution was soooooo much easier to understand! Thank you!
@ZinduZatism
@ZinduZatism 4 года назад
U R D Man, many thanks, others explain logarithm over half hour and still struggle to understand, urs short, clear and easy thank you subscribed. please make video of merge sort as well if possible. thank you
@shangliu6687
@shangliu6687 4 года назад
The best video for quick sort explanation!!! Clean and clear! theoretical and practical!
@shahzan525
@shahzan525 4 года назад
Awesome man awesome ...... I never see that easiest explanation on RU-vid...... But damm absolutely great.....
@SuperMixGamer
@SuperMixGamer Год назад
thank you very much, this was the best implementation i could find and the easier to understand
@edwinjonah
@edwinjonah 3 года назад
Wow, it looked so complicated and you just made it simple! Amazing, thanks a lot.
@hsoley
@hsoley 2 года назад
Amazing Derrick, learned alot! Thank you from freezing NYC
@rogueceska
@rogueceska Год назад
Fantastic m8 great explanation and nice simple code. You got a sub, hope you get many many more.
@hitechdivyanshu6329
@hitechdivyanshu6329 4 года назад
great man this is one of the easiest quick sort algo i've ever seen....liked and subscribed
@RobsondaMota
@RobsondaMota Год назад
Thank you for your concise and easy to understand implementation Derrick. Very good videos. Thanks!
@armberg8935
@armberg8935 4 года назад
this channel is amazing, had trouble understanding my lecturer but this was super clear!
@wanou_4259
@wanou_4259 Год назад
recursive function i see, pretty clever although not that efficient with much more values, it is still pretty impressive to see that's quite simple
@norbertoignaciojr3365
@norbertoignaciojr3365 3 года назад
Subscribed!!! Very clean and concise explanation!! Im just starting out with algorithms yet you explained it very well :D keep going buddy!
@selvakumar-zt5mz
@selvakumar-zt5mz 4 года назад
nice explanation ! Can you plz make tutorials on merge and counting sort :)
@dhavalgala4222
@dhavalgala4222 3 года назад
nice explanation! We need merge sort and heap sort videos as well.
@SanjuKumar-hk8yy
@SanjuKumar-hk8yy 3 года назад
Your explanation very clearly. I understand your explanation. Therefor I subscribed your channel. great job Derrick 🤟🤟
@miguelmarques6233
@miguelmarques6233 2 года назад
Such a good and simple way of explaining quick sort! Thank you for sharing!!
@ShahidiDewitness
@ShahidiDewitness 4 года назад
Amazing content. I'm reading Grokking Algorithms books and this greatly supplements my knowledge being first time I'm learning these advanced algorithms. Much appreciated and blessings 👊🏿
Далее
Хитрость старого мастера #diy
00:54
Learn Quick Sort in 13 minutes ⚡
13:49
Просмотров 317 тыс.
Does this sound illusion fool you?
24:55
Просмотров 853 тыс.
Quicksort In Python Explained (With Example And Code)
14:13
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
5 Useful F-String Tricks In Python
10:02
Просмотров 293 тыс.