1 / 31

Algorithm Design and Analysis

Algorithm Design and Analysis. Liao Minghong School of Computer Science and Technology of HIT July, 2003. Course Description. Course Name: Algorithm Design and Analysis Course Type: Selected Undergraduate Course Teaching hours: 30

wingert
Télécharger la présentation

Algorithm Design and Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithm Design and Analysis Liao Minghong School of Computer Science and Technology of HIT July, 2003

  2. Course Description • Course Name: Algorithm Design and Analysis • Course Type: Selected Undergraduate Course • Teaching hours: 30 • Teaching materials: Algorithms Design Techniques and Analysis, M. H. Alsuwaiyel, Publishing House of Electronics Industry, 2003

  3. Reference Materials • Thomas H.Cormen, et al., Introduction to Algorithms, Higher Education Press, The MIT Press, 2002 • 王晓东,算法设计与分析,清华大学出版社,2003.1

  4. Course Contents • Part 1: Basic Concepts and Introduction to Algorithms • Part 2: Techniques Based on Recursion • Part 3: First-Cut Techniques • Part 4: Complexity of Problems • Part 5: Coping with Hardness

  5. Course Contents_Part 1 • Chapter 1:Basic Concepts in Algorithmic Analysis • Chapter 2: Mathematical Preliminaries • Chapter 3: Data Structure • Chapter 4: Heaps and the Disjoint Sets Structures

  6. Course Contents_Part 2 • Chapter 5: Introduction • Chapter 6: Divide and Conquer • Chapter 7: Dynamic Programming

  7. Course Contents_Part 3 • Chapter 8: The Greedy Approach • Chapter 9: Graph Traversal

  8. Course Contents_Part 4 • Chapter 10: NP-Complete Problems • Chapter 11: Introduction to computational complexity • Chapter 12: Lower Bounds

  9. Course Contents_Part 5 • Chapter 13: Backtracking • Chapter 14: Randomized Algorithms • Chapter 15: Approximation Algorithms

  10. Chapter 1: Basic Concepts in Algorithmic Analysis • Basic Concepts of Algorithms • Time Complexity • How to Estimate the running Time of an Algorithm • Worst case and average case analysis • Amortized analysis

  11. 1.1 Basic Concepts of Algorithms • Architecture of Computational Science

  12. Process of solving problem problem computability complexity Algorithms programming Software system Architecture Computability theory Computable & non computable Computational model Equivalence of model Complexity theory Worst case Best case Average case P =? NP Algorithms design & analysis Design algorithms Analysis technique Optimal algorithms C language Java language …

  13. 1.1 Basic Concepts of Algorithms • Algorithm: is a procedure that consists of a finite set of instructions which, given an input from some set of possible inputs,enables us to obtain an output if such an output exists or else obtain nothing at all if there is no output for that particular input through a systematic execution of the instructions.

  14. 1.1 Basic Concepts of Algorithms • Characteristics of Algorithms • Corrective • Concrete steps • Determinative • Limited • Halted

  15. 1.1 Basic Concepts of Algorithms_some algorithms • Linear Search • Binary Search • Selection sort • Insertion sort • Merge Sort • Quick sort • Etc.

  16. 1.2 Time Complexity • Order of growth • The O-notation • The Ω-notation • The Θ-notation • The o-notation

  17. 1.2 Time Complexity _Order of growth • Definition1.1 elementary operation We denote by an “elementary operation” any computational step whose cost is always upperbounded by a constant amount of time regardless of the input data or the algorithm used.

  18. 1.2 Time Complexity _Order of growth Fig. 1.5 growth of some typical functions that represent running times

  19. Definition 1.2 The O-notation Let f(n) and g(n) be the functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be O(g(n)) if there exists a natural number n0 and a constant c>0 such that n>=n0, f(n)<=cg(n). Consequently, if lim f(n)/g(n) exists, then lim , implies f(n)=O(g(n))

  20. Definition 1.3 The Ω-notation Let f(n) and g(n) be two functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be Ω(g(n)) if there exists a natural number n0 and a constant c>0 such that n>=n0, f(n)>=cg(n). Consequently, if lim f(n)/g(n) exists, then lim , implies f(n)= Ω(g(n))

  21. Definition 1.4 The Θ-notation Let f(n) and g(n) be two functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be Θ(g(n)) if there exists a natural number n0 and two positive constants c1 and c2 such that n>=n0, c1g(n)<=f(n)<=c2g(n). Consequently, if lim f(n)/g(n) exists, then Lim , implies f(n)= Θ(g(n)) Where c is a constant strictly greater than 0.

  22. Definition 1.5 The o-notation Let f(n) and g(n) be the functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be o(g(n)) if for every constant c>0 there exists a positive integer n0 such that f(n)<=cg(n) for all n>=n0. Consequently, if lim f(n)/g(n) exists, then Lim , implies f(n)=o(g(n))

  23. Definition 1.6 Complexity Classes Let R be the relation on the set of complexity functions defined by f R g if and only if f(n)= Θ(g(n)). It is easy to see that R is reflexive, symmetric and transitive, i.e., an equivalence relation. The equivalence classes induced by this relation are called complexity classes. e.g. all polynomials of degree 2 belong to the same complexity class n2 .

  24. Definition 1.7 Space Complexity We define the space used by an algorithm to be the number of memory cells needed to carry out the computational steps required to solve an instance of the problem excluding the space allocated to hold the input. All definition of order of growth and asymptotic bounds pertaining to time complexity carry over to space complexity. Let T(n) and S(n) denote, respectively, the time and space complexity of an algorithm, then S(n)=O(T(n))

  25. 1.3 Worst case analysis • In worst case analysis of time complexity we select the maximum cost among all possible inputs of size n. • Under the worst case assumption, the notions of upper and lower bounds in many algorithms coincide and, consequently, we may say that an algorithm runs in time Θ(f(n)) in the worst case. But the upper and lower bounds are not always coincide.

  26. 1.4 Average case analysis • The running time is taken to be the average time over all inputs of size n. • It is necessary to know the probabilities of all input occurrences. • The analysis is in many cases complex and lengthy

  27. 1.5 Amortized analysis • Unable to express the time complexity in terms of the Θ-notation,we will be content with the O-notation, but the algorithm may be much faster than our estimate even in the worst case. • If the operation takes a large amount of time occasionally and runs much faster most of the time, then this is an indication that amortized analysis should be employed.

  28. 1.5 Amortized analysis • In amortized analysis, we average out the time taken by the operation throughout the execution of the algorithm, and refer to this average as the amortized running time of that operation. • Different with average case analysis: • The average is taken over all instances of the same size. • The average need to assume that the probability distribution of the input.

  29. 1.5 Amortized analysis • Example 1.32 We have a doubly linked list that initially consists of one node which contains the integer 0. We have as input an array A[1..n] of n positive integers that are to be processed in the following way. If the current integer x is odd, then append x to the list. If it is even, then first append x and then remove all odd elements before x in the list. Let us analyze the running time of this algorithm.

  30. The algorithm: for j = 1 to n x=a[j] append x to the list if x is even then while pred(x) is odd delete pred(x) end while end if end for

  31. 1.5 Amortized analysis • Time complexity analysis: • General analysis: O(n2) • Amortized analysis: Θ(n) (number of insertions: n, and the number of deletions: 0~n-1, so the total operations: n~2n-1)

More Related