Introduction to The Design & Analysis of Algorithms Lecture:Hao Wu Email:jt_wh@hnu.cn Mobil:13317315137
Contents Introduction Fundamentals of the Analysis of Algorithm Efficiency Brute Force Divide-and-Conquer Decrease-and-conquer Transform-and-conquer
Contents(continuous) Space and Time Tradeoffs Dynamic Programming Greedy Technique Limitations of Algorithm Power Coping with Limitations of Algorithm Power
Introduction Notion of Algorithm Fundamentals of Algorithmic Problem Solving Important Problem Types Fundamental Data Structures
Notion of Algorithm An algorithm is a sequence unambiguous instructions for solving problem,i.e.,for obtaining a required output for any legitimate input in a finite amount of time.
Euclid algorithm Step 1: If n=0,return the value of m. otherwise proceed to Step 2. Step 2: r=m%n Step 3:m← n,n← r. Go to step 1; m,n,r1,r2,……rk,0 m,n>r1 >r2,……>rk>0 rk = GCD(m,n)=GCD(n,r1)=….
Consecutive integer checking algorithm(pseudocode) t ←min(m,n) While(m%t||n%t) --t; Return t;
Middle school procedure for computing gcd(m,n) Step 1:Find the prime factors of m; Step 2:Find the prime factors of n; Step 3:Find the common factor(s). p1≤p2≤p3≤p4… Gcd(m,n)= p1*p2*p3*p4…
Algorithm for finding the list of primes not exceeding n p is a prime,2p,3p,…,kp are not primes. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 … 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …(p=2) 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …(p=3) If n<p2,and is not a prime,not remain on the list on the earlier passes.
Algorithm Sieve(n) //Implements the sieve of Eratosthenes //Input :A positive integer //Output:Array L of all prime numbers ≤n For p=2 to n do a[p]=p For p=2 to sqrt(n) do if a[p] is a prime j=p*p while j ≤n do a[j]=0 j=j+p for p=2 to n do l[i]=p i=i+1 Return L
Fundamentals of Algorithmic Problem Solving Choosing between exact and approximate problem solving Deciding on appropriate data structure Algorithm design techniques Method of specifying an algorithm Proving an algorithm’s correctness Analyzing an algorithm Coding an algorithm
Important Problem Types Sorting Searching String processing Graph problems Combinatorial problem Geometric problems Numerical problems
Fundamental Data Structures Linear Data Structures Graphs Trees Sets and Dictionaries