Bubble Sorting

Bubble Sorting

Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. Algorithm pushes (bubble) smallest or largest element to the end of the list and the pass through the list is repeated until the list is sorted.

Bubble Sorting algorithm (ascending / descending) #

info Pseudocode for Bubble Sorting algorithm (ascending)
FOR element counter INDEX from 0 TO list count
ITERATE over the list s UNTIL s[length - INDEX]
    IF s[i] > s[i+1] THEN
        swap s[i] with s[i+1]

Sorted Array = s

“Bubble Sorting algorithm’s visualization, ascending order”


------ Execution ------


Slice (before): [3 1 4 2]
Sort Ascending [1 2 3 4]
Sort Descending [4 3 2 1]