Тёмный
No video :(

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

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

Bubble Sort is a simple sorting algorithm that repeatedly swaps two adjacent elements through iterations through the list length to create a sort list.
The Bubble sort algorithm is one of the simplest algorithms to learn in computer science and is a great starting point to learn tougher algorithms.
In this one we'll cover how to implement the bubble sort algorithm using python programming.
#Python #BubbleSort #Algorithm
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 videos! 5320+ subscribers at the time of writing. So awesome. Thank you all for supporting the content I make! It's incredible to get the opportunity to make these videos for you all. Thanks so much!
*****************************************************************
Full code from the video:
def bubble(list_a):
indexing_length = len(list_a) - 1 #SCan not apply comparision starting with last item of list (No item to right)
sorted = False #Create variable of sorted and set it equal to false
while not sorted: #Repeat until sorted = True
sorted = True # Break the while loop whenever we have gone through all the values
for i in range(0, indexing_length): # For every value in the list
if list_a[i] #"Angled brackets not allowed in RU-vid Description :( list_a[i+1]: #if value in list is greater than value directly to the right of it,
sorted = False # These values are unsorted
list_a[i], list_a[i+1] = list_a[i+1], list_a[i] #Switch these values
return list_a # Return our list "unsorted_list" which is not sorted.
print(bubble([4,8,1,14,8,2,9,5,7,6,6]))
github.com/Der...
Packages (& Versions) used in this video:
Python 3.7
*****************************************************************
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!

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

 

3 сен 2019

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 179   
@BN-hy1nd
@BN-hy1nd Год назад
There are thousands of python tutorials on the internet but this dude has the attitude of "keep it simple , stupid" which suits me fine as a beginner who asks stupid questions. Thank you👏
@vidushimohan9949
@vidushimohan9949 3 года назад
Man, you're a godsend! Such a crisp and on-point elucidation, I've never felt anything clearer than this in my life!
@kartikchauhan2778
@kartikchauhan2778 2 года назад
yes
@samyeung122
@samyeung122 2 года назад
agree!
@marwanhamdaoui8327
@marwanhamdaoui8327 5 месяцев назад
True
@abhijaiallgamesgamer2075
@abhijaiallgamesgamer2075 2 месяца назад
no kiddin 🫡
@gachle
@gachle 3 месяца назад
This is the first time of thousands, that I check a tutorial o YT and I see no troubles with me understanding it... Simple and easy! Thanks
@EllenDivaIbanez
@EllenDivaIbanez 2 месяца назад
same, this guy can explain the concept in the simple way and also in the short time
@rajanhossain9250
@rajanhossain9250 2 месяца назад
Same here, finally I get this clearly! Explaining the whole thing while writing code makes it super easy to understand.
@andrewtate8792
@andrewtate8792 3 месяца назад
Nice, you kept it very simple. A quick improvement tip: in every outer loop you can actually decrease the index length since bubblesprt always sorts the biggest element each iteration.
@uppalapraveen959
@uppalapraveen959 4 года назад
Fell in love with the way, you explain things. It's easy to grasp. Please keep posting the videos. (if possible , could you please post a video on recursion and how to apply it in different scenarios). Thank You
@leonquadros4552
@leonquadros4552 4 года назад
This is great stuff. Pls continue making videos
@timohelasvuo9650
@timohelasvuo9650 5 лет назад
Really a fan of your videos. Well presented every time and it keeps getting better and better. Keep up the good work. This series seems very interesting. Cheers!
@Impedance_Z
@Impedance_Z Год назад
People go to indians for tutorial and I'm an indian coming to you for tutorial 😂
@nasttygamer08
@nasttygamer08 6 месяцев назад
Bro first learn English
@Impedance_Z
@Impedance_Z 6 месяцев назад
@@nasttygamer08 What was wrong in it could please enlighten me with my mistake?
@nasttygamer08
@nasttygamer08 6 месяцев назад
@@Impedance_Z people go to Indians for tutorial ❌ people go to Indian tutorial ✅ The meaning of both the things is correct but according to what you want to say, I said it is correct, And you said that it sounds difficult to read and listen to. 👍
@t.h.e.unknown_
@t.h.e.unknown_ 3 месяца назад
​@@nasttygamer08 bruh yours sounds incomplete... Leave lil bro alone💀
@ivanxavier9022
@ivanxavier9022 Месяц назад
@@nasttygamer08you have no right to tell someone to learn English when your grammar is no different from a 4 year old 😂😂
@user-ve9wy4ud1b
@user-ve9wy4ud1b 5 месяцев назад
Great video - very clearly explained and helped the penny drop very quickly!
@TechEndeavor
@TechEndeavor 4 года назад
Great explanation. I've been trying to wrap my head around this one for a minute.
@kharlopena7512
@kharlopena7512 2 года назад
Been searching for so many explanations for sorting and I get it, but yours have been the easiest to understand by far. Godly!
@tareqmahmud3902
@tareqmahmud3902 3 года назад
Boss I have solved the problem when you said to try it by myself. You are the extraordinary teacher I could ever find.
@codeNexus-bb2mb
@codeNexus-bb2mb 9 месяцев назад
after 4 years this is by far the best video
@thedataprofs3867
@thedataprofs3867 Год назад
Great, short and straight to the point explanation!
@fareselamine8115
@fareselamine8115 2 года назад
In my opinion, this is a more elegant solution than the two for loops a lot of other videos suggest using. This makes more intuitive sense, thank you!
@adithyaramesh7251
@adithyaramesh7251 3 года назад
Bro u are an absolute legend. I was trying to learn this from my teacher but did not understand anything but after watching this video I have no more doubt. TYSM
@serranoaaronjamesv.6436
@serranoaaronjamesv.6436 2 года назад
The easiest tutorial to follow, straight to the point, will definitely recommend this to my colleagues.
@erikajanecabanban5100
@erikajanecabanban5100 2 года назад
true
@paula98033
@paula98033 3 года назад
Hi Derrick , please start making video from begging for python!. You really explain the bubble sort very clearly.Please make more videos in python programming. Thanks
@banquotheholstein
@banquotheholstein Год назад
I was lost and unable to code this until I watched your video, I am very thankful for the help you've provided me! I am looking forward to using your channel to learn more.
@jupjyotkhosla4640
@jupjyotkhosla4640 2 года назад
Great video! Simply explained. Just one thing you could use indexing_length=indexing_length-1 outside the for loop to improve the speed, as bubble sort keeps sorting the last element.
@coreyjordan6733
@coreyjordan6733 2 года назад
I was researching this algorithm, your code and explanation is so much more simple and I appreciate that.
@kvelez
@kvelez 9 месяцев назад
Great tutorial, please continue uploading more Algorithms, Data Structures, and Interview coding challenges. def bubble_sort(arr): ordered = False length = len(arr) - 1 while not ordered: ordered = True for i in range(length): if arr[i] > arr[i+1]: ordered = False arr[i], arr[i+1] = arr[i+1], arr[i] return arr print(bubble_sort([65,677,55,45,0,3,1]))
@champion_life
@champion_life 3 года назад
This is how all the explanation should be done. precise and on point !! way to go buddy
@thescoobiestdoo2642
@thescoobiestdoo2642 3 года назад
how tf is this dude not huge this shit is life saving
@benduitsman3161
@benduitsman3161 2 года назад
Perfect explanations. Never followed a channel so fast XD
@lucysnowe9974
@lucysnowe9974 2 года назад
Thank you - first guide I have managed to find that explains each line of code.
@devindeepak
@devindeepak 3 года назад
I just love the way you're making the concepts simpler. Please keep doing...
@jamieshaw5605
@jamieshaw5605 4 года назад
Clear and concise, thanks mate!
@austintownsend3974
@austintownsend3974 Год назад
You accent is really calming while learning
@poppyecave3966
@poppyecave3966 Год назад
great going derrik just started coding
@ershadramezani6716
@ershadramezani6716 4 года назад
Hi. Thank you for the video. I didn’t get your mean for ‘while not sorted, sorted False and sorted True’. Could you please explain or suggest me a tutorial link for that? Thanks a lot again.
@cheeweng1060
@cheeweng1060 2 года назад
hope its not too late.. how this works is that the outer while loop, when initiated, assumes that the list is sorted, until it isn't, and this is verified by the inner for loop. This structure keeps the sorting going until eventually, the list becomes sorted
@shaharyarahmed5777
@shaharyarahmed5777 4 года назад
This was an amazing tutorial man! You just earned a new subscriber!
@kuykuy8800
@kuykuy8800 2 года назад
Great explanation! So much clearer and easier to understand!
@rhodabaruch4
@rhodabaruch4 Год назад
Perfectly clear. Thanks, Derrick.
@shrutikanikhar7987
@shrutikanikhar7987 4 года назад
OMG!....the best video on bubble sort. Thankyou and keep up the good work
@vivekr4690
@vivekr4690 5 лет назад
Thanks for your videos. They're well presented and quality is crisp!
@respect_gamers5695
@respect_gamers5695 4 года назад
Well, I had been messing up with the codes i get in my Book which is definitely not for beginners but it is preferred for them. Then comes your codes directly hits my brain and i catch it very easily. Ty for the codings. Plz come up with Data structure with python series. Thanks. Keep up the Good Work Sir
@MrAmbarish710
@MrAmbarish710 3 года назад
Different implementation than the usual nested for loop implementation. But really nice and easy explanation!
@theminertom11551
@theminertom11551 3 года назад
Of course, as usual, GREAT content!
@natashasen3548
@natashasen3548 Год назад
Awesome! The way you implement the technique is completely different from the usual one. But very clean explanation.
@adittorahman8255
@adittorahman8255 4 года назад
you way of explaining things is greatv .. A new member in your hood
@ReverantKnight
@ReverantKnight Год назад
Great explanation! Thanks Derrick.
@pappymekk4790
@pappymekk4790 3 года назад
Thanks dude, you actually made a simple implementation than the one I was struggling with
@tambahsaah8005
@tambahsaah8005 Год назад
Genius Derrick! Thanks
@MANOJKumar-lk6qz344
@MANOJKumar-lk6qz344 Год назад
Love the clarity bro 🙏
@subhashreebehera2994
@subhashreebehera2994 3 года назад
Never gonna miss ur videos now onwards..just awsm explanations...keep teaching us 🙏🙏
@FrenchyFlyTv
@FrenchyFlyTv 4 года назад
This video show simplicity and great explanation for reading the Head First: Learn to Code
@aminetlemcani693
@aminetlemcani693 3 года назад
Thanks for the video: This is mine: unslist = [3,7,2,6,4,9,1,5,1] totlist = [ ] j =0 while True: for i in range(len(unslist)-1): if unslist[i]>unslist[i+1]: unslist[i],unslist[i+1]=unslist[i+1],unslist[i] else: continue totlist.append(unslist) if len(totlist)>len(unslist)-2: if totlist[len(totlist)-1] == totlist[-1]: break print(unslist)
@kasvisreemurthy7009
@kasvisreemurthy7009 3 года назад
This stuff was real helpful !! Thanks for makin' it
@генпол
@генпол 3 года назад
Этот канал просто находка, только начал учить Python
@thaniacisneros5785
@thaniacisneros5785 3 месяца назад
Wow!! Awesome, thank you so much!!!
@iamjustahair1315
@iamjustahair1315 2 месяца назад
this was just amazing. thank you so sos os much
@lamedev1342
@lamedev1342 3 года назад
You are truly gifted dude with your explanations awesome video!
@likag.105
@likag.105 4 года назад
Quick and simple explanation, thank you!
@Princeali736
@Princeali736 Год назад
@derricksherill3511. I wish u could do more on DSA. I haven't understood these alogrithms with a lot of ease before you. Come back Legend.
@barelycodingtoday
@barelycodingtoday Год назад
You could do the root For Loop as a enumeration here? This was such an easy explanation of Bubble Sort. Thanks!
@mayankumar1312
@mayankumar1312 3 года назад
Great job Derrick.
@lucasm4299
@lucasm4299 2 года назад
Which is a better implementation, this one or the nested for loop one? I think this one is able to terminate the program earlier
@piotrgruszecki2400
@piotrgruszecki2400 2 года назад
@Lucas M both seems fine but personally i find the nested for loop simpler to undestand since you do not need to think about any way to escape the while loop since there is none. Even if the while loop version of bubble sorting executes faster than the classic one, they are both inefficient for bigger lists. I created a program in c++ that puts 50000 random numbers in a list, then i measured the time for the bubble sort function and it took 70 seconds while quicksort function took 0.019 seconds lol
@NicoAn2
@NicoAn2 Год назад
it was easy to understand and follow thank you!
@BN-hy1nd
@BN-hy1nd Год назад
sorting list_a[3,5,1,-6,7,45,-3,8,0] in ascending order took 8 iterations but 25 iterations in descending order. Why? Any help will be appreciated. thanks
@BN-hy1nd
@BN-hy1nd Год назад
managed to change two lines containing boolean statements to get sorting in descending order... thank you
@CC-bm3wb
@CC-bm3wb 3 года назад
Good god this makes so much more sense than my textbook
@nor123100
@nor123100 3 года назад
You explain in an amazing way! Thank you
@valenoveb3339
@valenoveb3339 3 года назад
Wonderful. If possible could you post a video on shuffling class in algorithms
@Re9sTwitch
@Re9sTwitch 3 года назад
Great vid, well explained. Thank you!
@majidzarinkolah
@majidzarinkolah 3 года назад
Clear and fast!
@itaco8066
@itaco8066 2 года назад
Awesome video & great explanation
@ted2091
@ted2091 2 года назад
clean and concise, thank you!
@naiadbaksh3996
@naiadbaksh3996 3 года назад
Great series! Massive help.
@Kait07_
@Kait07_ Год назад
Great video!
@keuair
@keuair 4 года назад
Thanks for the clear explanation, great vid
@manashbehera961
@manashbehera961 2 года назад
such simple explanation
@Hytension
@Hytension Год назад
I wish this would be broken down slower and in more detail, but I understand what you're doing.
@khalid11221122
@khalid11221122 4 года назад
Down to earth individual no cockiness unlike some other python immature kids who think they run NASA on their own because they know they basics of python. You just got a subscriber.
@PepeTostado
@PepeTostado 2 года назад
Why isn’t the while lip breaking because of the variable that is true?
@entity5678
@entity5678 Год назад
I took a different approach. "loop" is used in inner for loop bcoz we don't need to check the last elements after every iteration i.e if I have a list of 1000 elements, at the 500th iteration I would not be checking the last 500 elements and somehow tutorials missing this. def bubbleSort(unsorted): lst = list(unsorted) for loop in range(len(lst)-1): for num in range(len(lst)-1-loop): if lst[num] >= lst[num+1]: lst[num], lst[num+1] = lst[num+1], lst[num] return lst print(bubbleSort([5, 1, 3, 4, 2, 2, 5]))
@emerymusicdisc7172
@emerymusicdisc7172 5 месяцев назад
this makes so much sense, unfortunatly i have to add unto pre-existing code and its at least 8 lines longer and i still have no clue wtf to do...
@muhammadnasser312
@muhammadnasser312 3 года назад
Man u a Mighty God
@subramanianchenniappan4059
@subramanianchenniappan4059 4 года назад
came here from udemy. Thanks for great videos
@shakots
@shakots 5 лет назад
Excellent Vid, keep it
@rasoulkhoshravan5912
@rasoulkhoshravan5912 3 года назад
Thanks for informative videos. I want to write a code to transfer Excel tables and charts from my laptop to a website. Di you have a tutorial in this regard?
@shrvansudhakar7514
@shrvansudhakar7514 3 года назад
Thanks a lot Derrick.
@jmitch474
@jmitch474 3 года назад
Wow amazing video, thank you!
@dr1lltrckz147
@dr1lltrckz147 3 года назад
Hey Derrick can you explain why line 7 is necessary? Why do you change sorted to True?
@kyffran6084
@kyffran6084 4 года назад
Good video and explanation are clear !
@krishnachapagain3628
@krishnachapagain3628 4 года назад
Please try putting numbers greater than 9 as well. I tried putting 10 and 11 in the number list and function didnt work for sorting in ascending order.
@somarjaber1275
@somarjaber1275 Год назад
are that sublime text ? what extension you are using for text snippets and the them
@dijkstra1144
@dijkstra1144 2 года назад
for i in range(len(arr)): for j in range(i+1,len(arr)): if arr[i]>arr[j]: arr[i],arr[j]=arr[j],arr[i]
@user-hu7xi2dz4q
@user-hu7xi2dz4q 18 дней назад
love you bro!
@saisankalp25
@saisankalp25 Год назад
Never seen an explanation so quick and easy Thanks a lot sir!
@sivakumaranbazhagan1672
@sivakumaranbazhagan1672 9 месяцев назад
Can you cover merge sort as well
@DerickGudo
@DerickGudo 4 года назад
What's the difference between using a for loop and a while loop for the outer loop?
@omarawad946
@omarawad946 4 года назад
Hello Sir big fan of your videos first of all great tutorial as always! Secondly can you please explain to me the following line of code: while not sorted: sorted =True Why do we write sorted = True since sorted is initially set to False and the list has not yet been sorted? Thank you.
@shaharyarahmed5777
@shaharyarahmed5777 4 года назад
We write sorted = True because if the first element is less than the second element we set sorted to false. Lets suppose on the last iteration the first element is not greater than the second element so we don't run the if statement but since sorted is initially set to false we wont be able to break out the while loop.
@andrewagita901
@andrewagita901 4 года назад
@@shaharyarahmed5777 hey bro i really dont understand why we put the "sorted = true" after the while loop, wouldn't it directly break the loop and disregard everything below it?
@bob_-js4gd
@bob_-js4gd 2 года назад
@@andrewagita901 not until it loops through it first once. but then if the if statement is true its set back to false as it isnt sorted yet.
4 года назад
Ley me know, you are genius instructor, I can send the subtitles
@tanzirhossain7159
@tanzirhossain7159 3 года назад
Great explanation! Can you please create a python critical problem solving playlist?
@manolo6048
@manolo6048 3 года назад
@Derrick.. you're the best
@anonranger6428
@anonranger6428 Год назад
Excellent
@Dallasjb
@Dallasjb Год назад
Thank you so much!!!
@PIYdeveloper
@PIYdeveloper 3 года назад
Dude. You're awesome.
@senahugtfl7789
@senahugtfl7789 Год назад
literally ı loveeee it!!
Далее
How I would learn Leetcode if I could start over
18:03
Просмотров 429 тыс.
10 Sorting Algorithms Easily Explained
10:48
Просмотров 46 тыс.
Learn Quick Sort in 13 minutes ⚡
13:49
Просмотров 317 тыс.
Can you solve these number puzzles?
8:03
Просмотров 19 тыс.
5 Useful F-String Tricks In Python
10:02
Просмотров 293 тыс.