Bubble
sort
Let
a be an array of n numbers. Our aim is to sort the numbers in the array in
ascending order. The principle is to scan the array sequentially n-1 times and
in each scan do the following steps.
Scan – 1
i)
Take the first element and compare it
with the second element. If it is small don’t interchange; or else interchange
the two elements.
ii)
Then compare the second element with the
third element. If it is small don’t interchange; or else interchange the two
elements.
iii)
This process is continued till (n-1)th
element is compared with the nth element.
iv)
At the end of the first scan, the
highest element comes to the nth position.
Scan – 2