Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : 1.Start at the beginning of the data set....
6
Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : www.2july- maths.co.uk 1. Start at the beginning of the data set. 2. Compare the first two elements, and if the first is greater than the second, swaps them. 3. Continue doing this for each pair of adjacent elements to the end of the data set. 4. Start again with the first two elements, repeating until no swaps have occurred on the last pass.
-
Upload
isabell-templer -
Category
Documents
-
view
214 -
download
1
Transcript of Decision Maths 1 Sorting Algorithms Bubble Sort A V Ali : 1.Start at the beginning of the data set....
Decision Maths 1
Sorting AlgorithmsBubble Sort
A V Ali : www.2july-maths.co.uk
1. Start at the beginning of the data set.
2. Compare the first two elements, and if the first is greater than the second, swaps them.
3. Continue doing this for each pair of adjacent elements to the end of the data set.
4. Start again with the first two elements, repeating until no swaps have occurred on the last pass.
5 7 312
95
Bubble SortBubble Sort
Pass 1 5 7 312
95
5 7 312
95
5 5 312
97
5 5 312
97
5 5 12
3 97
5 5 97 12
3
Pass 2 5 5 93 12
7
5 5 93 12
7
5 5 93 12
7
5 5 97 12
3
5 5 93 12
7
Pass 3 5 5 97 12
3
5 5 97 12
3
5 3 97 12
5
5 3 95 12
7
Pass 4 5 3 97 12
5
3 5 97 12
5
3 5 95 12
7
Pass 5 3 5 97 12
5
3 5 97 12
5 Sorted !!!