Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Bubble sort


1. Bubble sort

2. Sorting
The sort something is to arrange that something into some order. Why is sorting important?

3. Sorting
Many algorithms are not practical in the sense that they must look at every possible permutation in order to determine an (optimum) result.

The number of permutations of 60 elements is about the number of seconds in 15 billion years.

4. Slow sort
Slow sort is to create and inspect every permutation of the items

In the case of sorting, however, implicit information can be retained during the sorting process to simplify work as the algorithm progresses. A general pseudo code algorithm that can be used to sort a list is as follows.

5. Bubble sort
For completeness, we will briefly discuss bubble sort. The idea of bubble sort is that during each pass through the list, elements make their way, as bubbles do, to their proper place in the final sorted list.

6. Warning
Bubble sort is the worst possible (practical) sort one could do and is never used in practice (except at the hardware level where parallelism can improve the performance).

7. Pseudo-code
The pseudo code algorithm for bubble sort is as follows.

FOR EACH of n passes DO
Here is the C code.


8. Examples of input and output
Here are some examples of input and output for the above program code.

Here is an example input.

For the above example input, here is the expected output.


9. End of page

10. Multiple choice questions for this page