Introduction To The Design and Analysis of Algorithms By: Anany Levitin
Introduction To The Design and Analysis of Algorithms By: Anany Levitin
com/info/levitin/
http://delab.csd.auth.gr/courses.html , ,
, , 2005.
Theoretical
importance
importance
A practitioners toolkit of known algorithms Framework for designing and analyzing algorithms for new problems
Design and Analysis of Algorithms - Chapter 1 3
Algorithm
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.
Design and Analysis of Algorithms - Chapter 1 4
Algorithm
Besides merely being a finite set of rules that gives a sequence of operations for solving a specific type of problem, an algorithm has the five important features [Knuth]
finiteness (otherwise: computational method) termination definiteness precise definition of each step input (zero or more) output (one or more) effectiveness Its operations must all be sufficiently basic that they can in principle be done exactly and in a finite length of time by someone using pencil and paper
Design and Analysis of Algorithms - Chapter 1 5
Historical Perspective
Euclids algorithm for finding the greatest common divisor http://en.wikipedia.org/wiki/Al-Khwarizmi Ab Abd Allh Muammad ibn Ms al-Khwrizm ( ) was a Muslim mathematician, astronomer, astrologer, geographer and author. He was born in Persia around 780, and died around 850. Because of his book on the systematic solution of linear and quadratic equations, al-Kitb al-mukhtaar f hsb al-abr wal-muqbala, together with Diophantus, he is considered to be the father of algebra. The word algebra is derived from al-abr, one of the two operations used to solve quadratic equations, as described in his book. Algoritmi de numero Indorum, the Latin translation of his other major work, on the Indian numerals, introduced the positional number system and the number zero to the Western world in the 12th century. The words algorism and algorithm stem from Algoritmi, the Latinization of his name
Design and Analysis of Algorithms - Chapter 1 6
Notion of algorithm
problem algorithm input
computer
output
??
11
12
second number of the pair gets smaller with each iteration and cannot become negative: indeed, the new value of n is r = m mod n, which is always smaller than n. Eventually, r becomes zero, and the algorithms stops.
13
After step E1, we have m=qn+r, for some integer q. If r=0, then m is a multiple of n, and clearly in such a case n is the GCD of m and n. If r0, note that any number that divides both m and n must divide mqn=r, and any number that divides both n and r must divide qn+r=m; so the set of divisors of {m,n} is the same as the set of divisors of {n,r}. In particular, the GCD of {m,n} is the same as the GCD of {n,r}. Therefore, E3 does not change the answer to the original problem.
Design and Analysis of Algorithms - Chapter 1 14
16
of problem:
Input: A sequence of n numbers <a1,a2,,an> Output: A reordering of the input sequence <a1,a2,,an> so that aiaj whenever i<j
Instance:
Selection Sort
array a[1],...,a[n] Output: array a sorted in non-decreasing order Algorithm:
Input:
for i=1 to n swap a[i] with smallest of a[i],a[n] (In place sorting, stable sorting)
Design and Analysis of Algorithms - Chapter 1
18
Understanding the problem (instances, ranges) Ascertaining the capabilities of a computational device (RAM and parallel machines, speed and amount of memory) Choosing between exact and approximate algorithms Deciding the correct data structure Algorithm design techniques Methods of specifying an algorithm (free language, pseudocode, flowchart) Proving an algorithms correctness Analyzing an algorithm (efficiency, theoretical and empirical analysis, optimality) Coding an algorithm
Design and Analysis of Algorithms - Chapter 1 20
Greedy approach Dynamic programming Backtracking and Branch and bound Space and time tradeoffs
21
Analysis of Algorithms