Explain orting array, explain Bubble sort with example

Sorting array, Bubble sort with example


Sorting data

Important computing application
Virtually every organization must sort some data
Bubble sort (sinking sort)
Several passes through the array
Successive pairs of elements are compared
If increasing order (or identical ), no change
If decreasing order, elements exchanged
Repeat

Example:
original:   3  4  2  6  7
pass 1:      3  2  4  6  7
pass 2:      2  3  4  6  7  
Small elements "bubble" to the top

Mean – average
Median – number in middle of sorted list
1, 2, 3, 4, 5 
3 is the median
Mode – number that occurs most often
1, 1, 1, 2, 3, 3, 4, 5
1 is the mode

Labels: