INTRODUCTION
What is an algorithm?
What is a Problem?
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
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: – F n (the n th 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(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āh Muḥammad ibn Mū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