Foundations of Algorithm 유관우

Slides:



Advertisements
Similar presentations
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
Advertisements

Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
I Advanced Algorithms Analysis. What is Algorithm?  A computer algorithm is a detailed step-by-step method for solving a problem by using a computer.
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
CS Algorithm Analysis1 Algorithm Analysis - CS 312 Professor Tony Martinez.
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
Analysis of Algorithms
Jessie Zhao Course page: 1.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
MS 101: Algorithms Instructor Neelima Gupta
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Asymptotic Behavior Algorithm : Design & Analysis [2]
Foundations of Algorithms, Fourth Edition
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
Questions 4) What type of algorithmic problem-solving technique (greedy, divide-and-conquer, dynamic programming)
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
CMPT 438 Algorithms.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Design and Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Introduction to the Design and Analysis of Algorithms
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Introduction to Algorithms
Introduction Algorithms Order Analysis of Algorithm
GC 211:Data Structures Algorithm Analysis Tools
CS 3343: Analysis of Algorithms
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Design and Analysis of Computer Algorithm (CS575-01)
CS 2210 Discrete Structures Algorithms and Complexity
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Objective of This Course
GC 211:Data Structures Algorithm Analysis Tools
Introduction to Algorithms Analysis
Asymptotic Growth Rate
CS 201 Fundamental Structures of Computer Science
Analysis of Algorithms
Chapter 2.
Programming and Data Structure
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Math/CSE 1019N: Discrete Mathematics for Computer Science Winter 2007
At the end of this session, learner will be able to:
Introduction To Algorithms
David Kauchak cs161 Summer 2009
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
Estimating Algorithm Performance
Analysis of Algorithms
CS 2210 Discrete Structures Algorithms and Complexity
Algorithms and Data Structures Lecture II
Presentation transcript:

Foundations of Algorithm 유관우 알고리즘 설계 및 분석 Foundations of Algorithm 유관우

Chap1. 알고리즘 설계 및 분석 (Design & Analysis of Computer Algorithms) Motivations “The most important course for CS students.” Goal - “생각” Problem solving techniques Scientific approach Observation, Analysis, Organization → Conclusion Correct thinking habits Logical writing (“The Golden Rule”) Big know-How’s (NP-Completeness …) Presentation techniques “그러므로 무엇이든지 남에게 대접을 받고자 하는 대로 너희도 남들 대접하라. 이것이 율법이요 선지자니라.” – 마태7:12 Digital Media Lab.

Problem : A question to which we seek an answer. Answer Algorithm_Lecture Problem : A question to which we seek an answer. Answer Solution for CS problems : A step-by-step procedure → Algorithm (Eg) problem : Determine whether instance : answer → yes Algorithm1 : Sequential Search Procedure seqsearch ( n : integer; S : array[1..n] of keytype x : keytype; var location : index); begin location := 1; while location ≤ n and S[location] ≠ x do location := location + 1; if location > n then location := 0; end; Digital Media Lab. Digital Media Lab.

Algorithm2 : Binary Search Procedure binsearch ( n : integer; S : array[1..n] of keytype; x : keytype; var location : index); var low, high, mid : index; begin low = 1; high = n; location = 0; while low ≤ high and location = 0 do mid = ( low + high ) / 2; if x = S[mid] then location = mid; else if x < S[mid] then high = mid – 1; else low = mid + 1; end; 2 different techniques for same problem → Efficiency? time : space : Digital Media Lab.

Fibonacci Sequence Algorithm 1 (Recursion) function fib (n : integer) : integer; begin if n ≤ 1 then fib=n else fib = fib(n-1) + fib(n-2); end; n #comp(Seq. Srch) #comp(Bin. Srch) 128 8 1,024 11 1,048,576 21 4,294,967,296 33 Digital Media Lab.

Divide-and-conquer approach Binary Search : no overlap Fibonacci sequence : full of overlapping ƒ(5) ƒ(3) ƒ(4) ƒ(1) ƒ(2) ƒ(2) ƒ(3) ƒ(0) ƒ(1) ƒ(0) ƒ(1) ƒ(1) ƒ(2) ƒ(0) ƒ(1) Digital Media Lab.

proof : Induction on n Theorem <Induction Basis> n = 2 & n = 3 <Induction Hypothesis> Suppose for all m such that 2 ≤ m < n T(m) > 2m/2 <Induction Step> T(n) = T(n-1) + T(n-2) + 1 > 2(n-1)/2 + 2(n-2)/2 + 1 > 2(n-2)/2 + 2(n-2)/2 = 2·2(n-2)/2 = 2n/2 Digital Media Lab.

Algorithm 2 (Iteration) function fib2 (n : integer) : integer; var f : array[0..n] of integer; i : index; begin (n+1) terms for fib2(n) f[0] = 0; if n > 0 then f[1] = 1; for i = 2 to n do f[i] = f[I – 1] + f[I – 2] fib2 = f[n] end; n (n+1) Iterative Alg Recursive Alg 40 41 ns 1048 micro s. 60 61 ns 1 s 80 81 ns 18 min 100 101 ns 13 days 120 121 ns 36 years 160 161 ns 3.8 ×107 years 200 201 ns 4 ×1013 years Digital Media Lab.

Algorithm Design : techniques (D-&-C, Dynamic Programming, Greedy, Backtracking, Branch-&-Bound, … ) Several algorithms for the same problem. “Which is the most Efficient algorithm?” => Algorithm Analysis ♧ Note : problem analysis (solvable, unsolvable, NP-Complete, … ) Digital Media Lab.

Time complexity Analysis Actual CPU time × # instructions × (programmers, languages, …) → some independent measure ! # op’s : a function of input size n n+1, 2n/2, log n … Input size? (Eg) Graph 문제들: O(n+e), 소수결정문제: O(log n), 행렬곱: O(n2)… Time complexity analysis Determine input size Choose the basic operation Determine how many time the B.O. is done for each value of the input size Digital Media Lab.

Example Add array Members T(n) = n (n : array size) Matrix multiplication T(n) = n3 (n : # rows) “every-case time complexity” Sequential Search Worst-case t.c. T(n) = n = W(n) Best-case t.c B(n) = 1 × Average-case t.c. A(n) Digital Media Lab.

(Eg) Sorting n elements Insertion Sort every-case complexity × best-case : worst-case : average-case : Quick Sort best-case, avg-case : “practically best but not appropriate for real time applications.” Merge Sort, Heap Sort every-case t.c. : Digital Media Lab.

Space complexity (memory) Complexity function Time complexity Space complexity (memory) Complexity function Note : 2 algorithms for the same prob. 1000·n , n2 Which one is faster? (or better? ) n2 > 1000·n if n > 1000 Threshold : 1000 But, theoretically 1000·n is better Correctness analysis, Correctness proof Digital Media Lab.

Order 1000·n is better than 0.01·n2 if n > 100,000 Linear-time algorithm quadratic-time algorithm Quadratic term eventually dominates “Throw away” low-order terms “ algorithm” or “quadratic algorithm.” Fig 1.3 & Table 1.4 p.28 & p.29 n 0.1n2 0.1n2+n+100 10 120 20 40 160 50 250 400 100 1000 1200 100000 101100 Digital Media Lab.

Digital Media Lab.

Digital Media Lab.

Digital Media Lab.

Def) (“Big-Oh of ƒ of n”) but “asymptotic upper bound” : big-Oh O(n2) “at least as good as” 3lgn+8, 4n2 5n+7, 6n2+9 2nlgn, 5n2+2 Digital Media Lab.

Def) (“Omega of ƒ(n)”) but Ω(n2) “at least as bad as” 4n2 4n3+3n2 5n2+2n 2n+4n Digital Media Lab.

Def) (“Theta of ƒ(n)”, “order of ƒ(n)”) (Eg) Prove that (proof by contradiction) Assume that Then This implies Since is a constant, this can never be True. → Contradiction 3lgn+8 4n2 5n+7 6n2+9 2nlgn 5n2+2n 4n3+3n2 6n6+n4 2n+4n Digital Media Lab.

Def) (Small Oh of ƒ(n)) (Eg) Let be given Choose Then (By contradiction) Assume Let Then must exist Digital Media Lab.

Theorem : if , then (proof) Because Next, we prove by contradiction. Digital Media Lab.

Properties of Order : (Eg) 1. 2. 3. 상수 4. 5. 6. 3. 상수 4. 5. 6. strictly growing functions 7. (Eg) Digital Media Lab.

In practice, exact time comp. → not easy or : enough Note : instead of Theorem (Eg) , because Digital Media Lab.

(Eg) , because (Eg) (i) , Trivial (ii) , Let be big enough Digital Media Lab.

Theorem (L’Hôpital Rule) (Eg) Digital Media Lab.