Visualizing Bubble Sort, first.

**not all that efficient or commonly used. it can be fun with optimization considered[29, 10, 14, 30, 37, 14, 18] ***SWAP 29, 10 & why? i=29 > i+1=10
[10, 29, 14, 30, 37, 14, 18] ***SWAP 29, 14
[10, 14, 29, 30, 37, 14, 18] ***SWAP 37, 14
[10, 14, 29, 30, 14, 37, 18] ***SWAP 37, 18
[10, 14, 29, 30, 14, 18, 37] *the largest value bubbles to the top aka "sinking sort" the largest value sinks to the bend or bottom
^^first pass/iterations all the way thru the array. Now, let's keep on bubble sorting, below.
[10, 14, 29, 14, 30, 18, 37] *2nd past and now ***SWAP 29, 14
[10, 14, 14, 29, 18, 30, 37] ***SWAP 29, 18
[10, 14, 14, 18, 29, 30, 37] ***SWAP 29, 14
[10, 14, 14, 18, 29, 30, 37] *completed sorted array in bubble sortNext Steps:
* Try with pen and paper if this is more intuitive
* Next try brute force, built-in JS (language of choice) methods to execute this algorithm
* Now try refactoring the code
Test this in your IDE with console.log’s to reveal what is under the hood.
Test this in your IDE with console.log’s to reveal what is under the hood.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Toni T Diep

Toni T Diep

multilingual Software Engineer, always learning and growing.