Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 746 Bytes

File metadata and controls

22 lines (16 loc) · 746 Bytes

Bubble Sort Documentation

Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order. This algorithm is not suitable for large data sets as its average and worst case complexity are of Ο(n2) where n is the number of items.

Pseudocode

Suppose A is an array of N values. We want to sort A in ascending order.

For I = 0 to N - 2
       For J = 0 to N - 2
         If (A(J) > A(J + 1)
           Temp = A(J)
           A(J) = A(J + 1)
           A(J + 1) = Temp
         End-If
       End-For
     End-For

Bubble Sort does roughly N2 / 2 comparisons and does up to N2 / 2 swaps.