250 likes | 343 Views
Introduction. What is an algorithm?. A precise instruction based on elementary operation Which takes something as input and process it into output to solve some problems. What is a Problem?. A task with precise description of admissible input and the “property” of the desired output
E N D
What is an algorithm? • A precise instruction based on elementary operation • Which takes something as input and process it into output • to solve some problems
What is a Problem? • A task with precise description of admissible input • and the “property” of the desired output • E.g., GCD • Given two positive integers (input) • Determine GCD of the given integers • (express the property of the desired output) • GCD is well defined
Problem Instance • Determining GCD is a problem • How many actual problems? • GCD of 1 and 2 ? • GCD of 234 and 42? • More? Obviously yes. • Problem instance • A problem with a specific input • E.g., find a GCD of 42 and 14
Purpose of this class • “how to design algorithms for given problems, and beyond” • Analysis • Synthesis emphasized in this class • Algorithm should be • Correct • For any instances, it must produce appropriate output • Efficient • Use not too much resource
Calculating Fibonacci Sequence • Fibonacci sequence • 1, 1, 2, 3, 5, 7, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584
The Problem • Input: • a positive number N • Output: • Fn (the nth Fibonacci Number) • Example instances • Ex. 1: N = 10 • Ex. 2: N = 15 • Ex. 3: N = 0 N = -4 is not an instances of this problem!!!
Approach 1 • Array based • method: dynamic programming on linear structure (linear time)
Approach 2 • method: Recursive (exponential time) F(9) F(8) F(7) F(7) F(6) F(6) F(5) … … … …
Approach 3 • Method: Divide and Conquer (logarithmic)
Approach 3 • Find exponential • Method: Divide and Conquer (logarithmic)
Approach 4 • Method: Closed form solution Golden Ratio
Conclusion • Difference Design Difference Performance • This class emphasizes on designing “efficient algorithm”
Algorithm Again • It is the essence of the computation
Side Note on Algorithm • Named after a Persian mathematician “AbūʿAbdallāhMuḥammadibnMūsā al-Khwārizmī” • Wrote book on linear equation • Introduce number 0
TOPICS Overview Analysis part
Asymptotic Notation • Measurement of “efficiency” of algorithms • How to compare two algorithms • How to predict behavior of the algorithm
Big O analysis • How to determine Big O of some code • Recurrent Relation
NP-Complete • What computer could solve • Efficiently • Inefficiently • The difference between “Efficiency” and “Inefficiency”
Topics Overview Synthesis part
Divide and Conquer • Solve an instance of the problem by dividing it into smaller instances • Based on induction • Example Problems: • Sorting (Quick Sort & Merge Sort) • Maximum Contiguous Sum of Subsequence • Modulo Exponential • Closest Pair
Dynamic Programming • Aim to reduce redundancy in computation • For the case when there are several overlapping sub-problems • Example Problems: • Fibonacci Number • Binomial Coefficient • Matrix Chain Multiplication • Longest Common Subsequence • Largest Square in Binary Picture (Island problem)
Greedy Algorithm • Solve the problem by doing the best for the current step • Proof of correctness • Example Problems: • Minimum Spanning Tree • Prim’s Algorithm • Kruskal’s Algorithm
Graph Algorithm • Algorithm related to graph structure • Breadth First Search • Depth First Search • Shortest Path
Search • Solve the problem by enumeration • Systematical enumeration • Performance improvement • Branch and Bound • Backtracking