Sorting
Sorting
ICT2101
Dr. Mohammad Abu Yousuf
[email protected]
1
Some Sorting Algorithm
2
Insertion sort (1)
3
Insertion sort (2)
5
Insertion sort (4)
6
Insertion sort (5)
7
Analyzing algorithms(1)
Analysis of insertion sort:
• The time taken by the INSERTION-SORT procedure
depends on the input: sorting a thousand numbers takes
longer than sorting three numbers.
9
Analyzing algorithms(3)
10
Analyzing algorithms(4)
12
Analyzing algorithms(6)
13
Analyzing algorithms(7)
14
15
Order of growth
• We used some simplifying abstractions to ease our analysis of the
INSERTIONSORT procedure.
• First, we ignored the actual cost of each statement, using the constants ci
to represent these costs.
• Then, we observed that even these constants give us more detail than we
really need: we expressed the worst-case running time as an2 + bn + c for
some constants a, b, and c that depend on the statement costs ci . We
thus ignored not only the actual statement costs, but also the abstract
costs ci .
17
The divide-and-conquer approach
18
The divide-and-conquer approach
19
Merge sort algorithm
20
Merge sort algorithm
21
22
23
24
25
Merge sort algorithm
26
Merge sort algorithm
27
Thank you
28