Академический Документы
Профессиональный Документы
Культура Документы
3.1 Introduction
Precision: steps are precisely stated Uniqueness: Results of each step of execution are uniquely defined. They depend only on inputs and results of preceding steps Finiteness: the algorithm stops after finitely many steps
Input: the algorithm receives input Output: the algorithm produces output Generality: the algorithm applies to various sets of inputs
1. x:= a 2. If b > x then x:= b 3. If c > x then x:= c A trace is a check of the algorithm for specific values of a, b and c
Euclidean Algorithm
Given two integers m and n, the gcd(m,n) or greatest common divisor of m and n is a common divisor k > 1 such that k is the largest of all common divisors of m and n. The Euclidean algorithm finds the gcd(m, n). Theorem 3.3.6: If a & b are positive integers, and r = a mod b, then gcd(a,b) = gcd(b,r)
Example: if a = 120, b = 80, then r = 40 = 120 mod 80. Thus, gcd(120,80) = gcd(80,40)
Example: given a positive integer n, factorial of n is defined as the product of n by all numbers less than n and greater than 0. Notation: n! = n(n-1)(n-2)3.2.1
Observe that n! = n(n-1)! = n(n-1)(n-2)!, etc. A recursive algorithm is an algorithm that contains a recursive procedure
Fibonacci sequence
Leonardo Fibonacci (Pisa, Italy, ca. 1170-1250) Fibonacci sequence f1, f2, defined recursively as follows: f1 = 1 f2 = 2 fn = fn-1 + fn-2 for n > 3 First terms of the sequence are: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
Complexity: the amount of time and/or space needed to execute the algorithm. Complexity depends on many factors: data representation type, kind of computer, computer language used, etc.
Types of complexity
Best-case time = minimum time needed to execute the algorithm for inputs of size n Worst-case time = maximum time needed to execute the algorithm for inputs of size n Average-case time = average time needed
Order of an algorithm
Let f and g be functions with domain Z+ = {1, 2, 3,} f(n) = O(g(n)): f(n) is of order at most g(n)
if there exists a positive constant C1 such that |f(n)| < C1|g(n)| for all but finitely many n
if there exists a positive constant C2 such that |f(n)| > C2|g(n)| for all but finitely many n
Fibonacci sequence.
Number of operations
Theorem 3.6.2: If integers in the range 0 to m, m > 8, not both zero, are input to the Euclidean algorithm, then the number of modulus operations required is at most
log 3/2 (2m/3)
Sender encrypts a message Receiver decripts the message RSA (Rivest, Shamir, Adleman) system
Messages are represented as numbers Based on the fact that no efficient algorithm exists for factoring large digit integers in polynomial time O(nk).