Велимир Майсторов Posted on Jul 29, 2017 Explain Bubble Sort Algorithm Like I`m Five #explainlikeimfive #algorithm #sortalgorithms I see this tag is popular here, so please explain me for example Bubble Sort Algorithm like I`m five :) Top comments (3) Subscribe Submit Preview Dismiss Collapse Expand David Taitingfong David Taitingfong David Taitingfong Follow 🇬🇺 🇲🇵 // software dev trying to find tech'ish ways to learn & teach the Chamoru language. I also like automating stuff. Location California Education B.S. Comp Sci, books, & YouTube Work Software Engineer Joined May 6, 2017 • Jul 31 '17 Dropdown menu Copy link Hide Say you were given a list of 6 numbers and you wanted to sort them from least to greatest. The list looks like this: 1 4 5 2 3 6 With Bubble Sort, you start from the beginning (the left in this case), and you put a "bubble" around the first two indices and sort, like so: [1 4] 5 2 3 6 Since 1 < 4 (which is what we want), you move the "bubble" one index to the right. 1 [4 5] 2 3 6 ...and so on and so forth... 1 4 [5 2] 3 6 At this point, 5 > 2, so those two would be swapped 1 4 [2 5] 3 6 1 4 2 [5 3] 6; 5 > 3 so we swap. 1 4 2 [3 5] 6 1 4 2 3 [5 6] Then we start over at the beginning, and repeat until no further swaps are needed, i.e., until the list is sorted from least to greatest. Collapse Expand Jess Lee Jess Lee Jess Lee Follow Building DEV with everyone here. What do we have if not community? Email jess@majorleaguehacking.com Location USA / TAIWAN Pronouns she/they Work Founder-in-Residence at Major League Hacking, Co-Founder at DEV Joined Jul 29, 2016 • Aug 10 '17 Dropdown menu Copy link Hide Here's an awesome explanation: dev.to/vaidehijoshi/bubbling-up-wi... Collapse Expand hidden_dude hidden_dude hidden_dude Follow Joined Aug 26, 2018 • Jun 26 '21 Dropdown menu Copy link Hide Bubblesort stinks Learn Quicksort instead Code of Conduct • Report abuse
Top comments (3)
Say you were given a list of 6 numbers and you wanted to sort them from least to greatest. The list looks like this:
1 4 5 2 3 6
With Bubble Sort, you start from the beginning (the left in this case), and you put a "bubble" around the first two indices and sort, like so:
[1 4] 5 2 3 6
Since 1 < 4 (which is what we want), you move the "bubble" one index to the right.
1 [4 5] 2 3 6
...and so on and so forth...
1 4 [5 2] 3 6
At this point, 5 > 2, so those two would be swapped
1 4 [2 5] 3 6
1 4 2 [5 3] 6; 5 > 3 so we swap.
1 4 2 [3 5] 6
1 4 2 3 [5 6]
Then we start over at the beginning, and repeat until no further swaps are needed, i.e., until the list is sorted from least to greatest.
Here's an awesome explanation: dev.to/vaidehijoshi/bubbling-up-wi...
Bubblesort stinks
Learn Quicksort instead