300 likes | 514 Views
高等計算機演算法 Advanced Computer Algorithms. 伍麗樵 (Lih-Chyau Wuu) 雲林科技大學電資所. 課程內容 :. Design Methods Analysis Methods The theory of NP-completeness. Design Methods. The Greedy Method The Divide-and-Conquer strategy Prune-and-Search Tree Searching strategy Dynamic Programming
E N D
高等計算機演算法Advanced Computer Algorithms 伍麗樵(Lih-Chyau Wuu) 雲林科技大學電資所
課程內容: • Design Methods • Analysis Methods • The theory of NP-completeness
Design Methods • The Greedy Method • The Divide-and-Conquer strategy • Prune-and-Search • Tree Searching strategy • Dynamic Programming • Approximation Algorithms • Randomized Algorithms • On-Line Algorithms
Analysis Methods • Complexity of algorithms Best, Average and Worst Case Analyses • The Lower Bounds of Problems • Amortized Analysis
教科書 Introduction to the Design and Analysis of Algorithms R.C.T Lee R.C. Chang S.S. Tseng Y.T. Tsai Second Edition 旗標代理
分數 期中考 35% 期末考 35% 報告 30%
Algorithm • A number of rules, which are to be followed in a prescribed order, for solving a specific type of problems • A method that can be used by a computer to solve a problem.
Computer Algorithm – Five Criteria • Input • Output • Finiteness • Definiteness • Effectiveness
Motivations of studying Algorithms • Algorithm is everywhere • Use computers efficiently • Optimal solution • NP-complete problems(Decision problems) • NP-hard problems(Optimization problems) next
Use computers efficiently • Sorting algorithms 11, 7, 14, 1, 5, 9, 10 ↓sort 1, 5, 7, 9, 10, 11, 14 • Insertion sort • Quick sort
The study of Algorithms: • How to design algorithms • How to validate algorithms • How to analyze algorithms • How to test a program
How to design algorithm The study of algorithm design is almost a study of strategies
How to analyze algorithm • Measure the goodness of algorithms • efficiency?(time/space) • asymptotic notations: O( ) • worst case • average case • amortized • Measure the difficulty of problems • NP-complete • undecidable • lower bound • Is the algorithm optimal?
時間複雜度(time complexity)-worst case executing time 輸入量為n時,演算法的最大執行時間 • O(1):常數時間(constant time) • O(n):線性時間(linear time) • O(log2n):次線性時間(sub-linear time) • O(n2):平方時間(quadratic time) • O(n3):立方時間(cubic time) • O(2n):指數時間(exponential time) O(1)<O(log2n)<O(n)<O(nlog2n)<O(n2)<O(n3)<O(2n)
Algorithm vs. Program • Algorithm的表示方法 *虛擬碼(Pseudo Code) SPARKS, PASCAL-like, Nature Language *流程圖表示法(Flow-chart representation) • A program is the expression of an algorithm in a programming language
Background for Learning Algorithms • Clear brain • Data structure • Discrete mathematics
NP-complete problems:No efficient algorithms • Easy problem: polynomial-time algorithm • Difficult problem: exponential-time algorithm Garey & Johnson “Computers & Intracability”
N1: Satisfiability Problem Given a Boolean formula S, is there an assignment to make S true? &: and !: or ~: not S=A& (~B !C) &~C S=A& ~A Worst case: n variables --> 2n combinations
N2: Bin Packing Problem C1 C2 C3 C4 C5 C6 C7 C8 7 1 3 4 1 3 3 8 B=15 How many bags are necessary?
N3: 0/1 Knapsack Problem M(weight limit)=14 best solution: P1, P2, P3, P5(optimal) This problem is NP-complete.
N4: Traveling Salesperson Problem • Given a graph (vertex-city, edge-flying cost between two cities), the salesperson travels to every city once and only once, and the cost should also be minimal. • Given a set of n planar points Find: A closed tour which includes all points exactly once such that its total length is minimized. • This problem is NP-complete.
N5: Partition Problem • Given: A set of positive integers S Find: S1 and S2 such that S1S2=, S1S2=S, iS1i=iS2 i (partition into S1 and S2 such that the sum of S1 is equal to S2) • e.g. S={1, 7, 10, 9, 5, 8, 3, 13} • S1={1, 10, 9, 8} • S2={7, 5, 3, 13} • This problem is NP-complete.
N6: Art Gallery Problem • Given an art gallery in the form of a polygon, determine the minimum number of guards and their placements such that the entire art gallery can be monitored by these guards.
P1: Minimal Spanning Tree Problem • Given a graph, find a spanning tree (a graph without cycle) with the minimum total edges length.
P1: Minimal Spanning Tree Problem • graph: greedy method • geometry(on a plane): divide-and-conquer • # of possible spanning trees for n points: nn-2 • n=10→108, n=100→10196
P1: Minimal Spanning Tree Problem • graph: greedy method • geometry(on a plane): divide-and-conquer • # of possible spanning trees for n points: nn-2 (Cayley’s theorem) • n=10→108, n=100→10196
P2: Convex Hull Problem • Given a set of 2-dimensional points, find a smallest convex polygon to contain all of these points. • Convex Polygon: any line connecting any two points inside the polygon must itself lie inside the polygon.
P2: Convex Hull Problem • It is not obvious to find a convex hull by examining all possible solutions • divide-and-conquer
P3: One-Center Problem • Given a set of points, find a smallest circle covering all of these points. prune-and-search !!