SLIDE 1
COMP 204
Algorithm design: Selection and Insertion Sort Mathieu Blanchette based on material from Yue Li, Christopher J.F. Cameron and Carlos G. Oliver
1 / 23
COMP 204 Algorithm design: Selection and Insertion Sort Mathieu - - PowerPoint PPT Presentation
COMP 204 Algorithm design: Selection and Insertion Sort Mathieu Blanchette based on material from Yue Li, Christopher J.F. Cameron and Carlos G. Oliver 1 / 23 Sorting algorithms A sorting algorithm is an algorithm that takes a list/array
1 / 23
2 / 23
3 / 23
4 / 23
5 / 23
6 / 23
7 / 23
8 / 23
9 / 23
10 / 23
11 / 23
1
2
3
4
5
6
7
8
9
10
12 / 23
13 / 23
14 / 23
15 / 23
33 > 10? yes
27 > 10? yes
14 > 10? yes
insert 10 at position 0
16 / 23
17 / 23
35 > 19? yes
33 > 19? yes
27 > 19? yes
14 > 19? no
insert 19 at position 2
18 / 23
35 > 42? no
put back 42
19 / 23
Sorted so far Completely 42 > 44? no
put back 42
20 / 23
21 / 23
1
2
3
4
5
6
7
8
9
10
22 / 23
23 / 23