Complexity Advanced Programming
Algorithms and Complexity
2
Example The sorting problems is defined as follows: n Input set: - - PDF document
Advanced Programming Complexity Algorithms and Complexity Algorithm An algorithm is a calculation procedure (composed by a finite number of steps) which solves a certain problem, working on a set of input values and producing a set of output
2
3
n Input set: sequence of numbers <a1, a2,…,an> n Output set: permutation <a’ 1, a’ 2, …, a’ n> of
4
Insert A[ j ] in the sorted sequence A[1.. j --1]
5
6
7
n In the sorting algorithm such parameter is the
n In the multiplication between integer numbers,
8
n Each statement in the pseudo-code requires a
n Each statement has a different execution time.
9
times
tj is the number of times the statement is repeated, for a certain value of j
Insert A[ j ] in the ordered sequence A[1 .. j -1 ]
10
11
12
13
14
15
16
n One with complexity T(n) = 2n2 n The other with complexity T(n) = 50n log2 n
n Intel Core i7 Extreme 965EE performing 76000 MIPS at 3.2 GHz
n AMD Athlon FX-60 performing 18000 MIPS at 2.6 GHz for the
n MIPS = Millions of Instructions Per Second
17
n When n = 1 K ( 103)
n When n = 1 M ( 106)
n When n = 1 G ( 109)
18
n Theta Notation Θ n “Big O” Notation O n Omega Notation Ω.
19
20
21
22
23
n T(n) = O( g(n) ) and T(n) = Ω( g(n) )
24
25
26
27
28
29
y = 0.1498x R² = 0.95331 y = 1.5644x2 - 47.556x R² = 0.99922 2000000 4000000 6000000 8000000 10000000 12000000 14000000 16000000 500 1000 1500 2000 2500 3000 strcpy() mycpy()