Omputer Cience: Today: Searching and Sorting
Omputer Cience: Today: Searching and Sorting
51 75 6 48 88
0 1 2 3 4
51
6 48
75 51
6 75
48 88
0 1 2 3 4
51 75 6 48 88
17 4 8 24 1
4 17 8 24 1
Bubble Sort (cont’d)
Examine the next two
0 1 2 3 4
4 17 8 24 1
4 8 17 24 1
Bubble Sort (cont’d)
Examine the next two
0 1 2 3 4
4 8 17 24 1
4 8 17 24 1
Bubble Sort (cont’d)
Examine the next two
0 1 2 3 4
4 8 17 24 1
4 8 17 1 24
Bubble Sort (cont’d)
Next pass…
0 1 2 3 4
4 8 17 1 24
0 1 2 3 4
4 8 1 17 24
Bubble Sort (cont’d)
…
0 1 2 3 4
4 8 1 17 24
Bubble Sort (cont’d)
Next pass…
0 1 2 3 4
4 8 1 17 24
0 1 2 3 4
4 1 8 17 24
Bubble Sort (cont’d)
…
0 1 2 3 4
4 1 8 17 24
Bubble Sort (cont’d)
Next pass…
0 1 2 3 4
4 1 8 17 24
0 1 2 3 4
1 4 8 17 24
Bubble Sort (cont’d)
…
0 1 2 3 4
1 4 8 17 24
51 75 6 48 88
Lowest Item is
found and
0 1 2 3 4
moved to the
front of the new
list 6
The Selection Sort (cont’d)
Continued…
The original item is
0 1 2 3 deleted, and this
process continues on
the original list, moving
51 75 48 88 to the new list
0 1 2 3 4
6 48
The Selection Sort (cont’d)
Continued…
0 1 2
51 75 88
0 1 2 3 4
6 48 51
The Selection Sort (cont’d)
Continued…
0 1
75 88
0 1 2 3 4
6 48 51 75
The Selection Sort (cont’d)
Continued…
0
88
0 1 2 3 4
6 48 51 75 88
The Selection Sort (cont’d)
Continued…
0 The original list
is destroyed
0 1 2 3 4
6 48 51 75 88
The Selection Sort (cont’d)
The Selection sort algorithm in pseudo code
1 5 8 9 12 20 34
1 5 8 9 12 20 34
1 5 8 9 12 20 34