4. Algorithm A sequence of computational of steps for solving a well-specified computational problem The statement of the problem specifies in general terms the desired input/output relationship The algorithm describes a specific computational procedure for achieving that input/ouput relationship
5.
6. INPUT: A sequence of numbers <a 1 ,a 2 ,a 3 ,...,a n > OUTPUT: A permutation <a’ 1 ,a’ 2 ,a’ 3 ,...a’ n > such that a’ 1 a i2 a i3 ... a in Sorting problem
7. A possible input sequence is a instance of the sorting problem <31,41,59,26,41,58> A sorting algorithms must return: <26,31,41,41,58,59> Instance of the sorting problem
8. Analysis of algorithms Complexity Time complexity Space complexity Analysis Semantic Analysis Correctness
9.
10.
11. mistery( 0) = 0 mistery( 1) = 1 mistery( n ) = mistery( n - 1 ) + mistery( n - 2), for n > 2 . “ mistery( n ) computess the n-th Fibonacci’s number” mistery( n ) =( n - n ) / 5 with =(1 + 5)/2 [Golden ratio] =(1 - 5)/2
12.
13. Correctness Is an algorithm correct for a problem? (Does it do a given function?) Given a computational problem f : I O { } and a algorithm A . The algorithm A is correct for the problem f if the function that A calculates is f .
14. Problem: Finding the minumun element in an array of n reals Input : T[1..n] : array of real Output : x min{T[i] | 1 i n } min : N x R N R (n, T[1..n] ) min{T[i] | 1 i n} “ In order to prove that a program or algorithm is correct, we need to show that the program gives the correct answer for every possible input.”
15.
16.
17.
18.
19.
20.
21.
22. Best case t b (n) Minimum execution time for any input of size n Worst case t w (n) Maximum execution time over all the inputs of size n Average case t a (n) Average execution time over all the inputs of size n Time Complexity t(n) Number of computational steps
23.
24. An operation whose execution time can be bounded above by a constant depending only on the particular implementation used ( machine, programming language etc ). In general we use RAM elementary instructions as the model. Elementary Operation
25.
26.
27.
28.
29. “ Two different implementations of the same algorithm will not differ in efficiency by more than some multiplicative constant” Principle of Invariance
30. El orden de complejidad de un algoritmo Es una expresion matematica que indica como los recursos necesitados para correr un algoritmo se incrementan como se incrementa el tamaño del problema (que el resuelve). Orden de complejidad de un algoritmo
31. Complejidad Lineal La complejidad de un algoritmo se dice que es lineal si: Con a y b son constantes t(n)=a * n + b
32.
33. By the invariance principle we if we have two different implementations (computer + language + compiler +code optimizations) with worst case time complexity t w1 (n) and t w2 (n) then t w1 (n) = c t w2 (n) Worst case time complexity t w (n) = a*n + b