Continuing from Part 1 of the post on Bubble Sort, here is a visualizer that helps us see how bubble sorting is carried out. Click on the' Start Bubble Sort' button in the graph above for a live view of how the sorting is carried out.
You will notice that the animation shows the step-by-step process of Bubble Sort, highlighting how elements are compared and swapped.
Conceptual Animation Steps:
Initial Array:
Display the unsorted array: [64, 34, 25, 12, 22, 11, 90] *The animation above picks any randomly generated unsorted array.
Passes:
It then swaps adjacent elements where needed. For example, during the first pass:
Compare 64 and 34, swap them.
Compare 64 and 25, swap them.
Continue this until the largest element (90) is placed in its correct position.
Subsequent Passes:
Show each subsequent pass with fewer elements being processed, and the array getting progressively sorted.
Conclusion
Hopefully this visualization gave a clearer understanding of how Bubble Sort works in a phased manner.
Liked it a lot!! 😀