Part 10 — Data Structures and Algorithms in Plain English | Bubble Sort

  1. Begin an iteration (loop) that spans across the entire length of the array or list.
  2. Then start another iteration inside the above iteration. This new iteration will span across the length of the array minus the current value of the above iteration minus 1. This is because Bubble Sort starts to correctly order the elements from the end of the list or array.
  3. Now, using the second iteration value as the indexer, compare the first and the second element of the list or array.
  4. Depending on your sort order, compare if the elements are greater or less than each other and swap as necessary. For the case of ascending, the first element must be greater than the second element. And in the case of descending, it is the reverse.
  5. The loop will follow this pattern till the last elements of the array or list are compared and swapped as necessary.
  6. This process continues till the first iteration, which spans across the length o the array, is complete.
a python program for Bubble Sort

--

--

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
Loveday Perfection

Loveday Perfection

66 Followers

A Magician! Stay honest — Promote inclusion. Mixing magical potions @lighthouseweb3 @digitaleyesnft @kobo_360 @blacheinc | Building @cholatrek_tech