Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 2.

Slides:



Advertisements
Similar presentations
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Advertisements

한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Analysis of Algorithms
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
Discrete Structures & Algorithms Functions & Asymptotic Complexity.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Chapter 3 Growth of Functions
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
Growth of Functions CIS 606 Spring 2010.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Analysis of Algorithms CS 477/677 Recurrences Instructor: George Bebis (Appendix A, Chapter 4)
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
CSE 5311 DESIGN AND ANALYSIS OF ALGORITHMS. Definitions of Algorithm A mathematical relation between an observed quantity and a variable used in a step-by-step.
Instructor Neelima Gupta
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 3: Growth of Functions (slides enhanced by N. Adlai A. DePano)
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Asymptotic Notations Iterative Algorithms and their analysis
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Mathematics Review and Asymptotic Notation
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
The Growth of Functions Rosen 2.2 Basic Rules of Logarithms log z (xy) log z (x/y) log z (x y ) If x = y If x < y log z (-|x|) is undefined = log z (x)
CS 3343: Analysis of Algorithms
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
BY Lecturer: Aisha Dawood.  stands alone on the right-hand side of an equation (or inequality), example : n = O(n 2 ). means set membership :n ∈ O(n.
CMPT 438 Algorithms Chapter 3 Asymptotic Notations.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
CSC401 – Analysis of Algorithms Lecture Notes 2 Asymptotic Analysis Objectives: Mathematics foundation for algorithm analysis Amortization analysis techniques.
Growth of Functions. 2 Analysis of Bubble Sort 3 Time Analysis – Best Case The array is already sorted – no swap operations are required.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 3.
Introduction to Analysis of Algorithms CS342 S2004.
Time Complexity of Algorithms (Asymptotic Notations)
COSC 3101A - Design and Analysis of Algorithms 2 Asymptotic Notations Continued Proof of Correctness: Loop Invariant Designing Algorithms: Divide and Conquer.
Introduction to Algorithms Lecture 2 Chapter 3: Growth of Functions.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
13 February 2016 Asymptotic Notation, Review of Functions & Summations.
Asymptotic Notation Faculty Name: Ruhi Fatima
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
September 18, Algorithms and Data Structures Lecture II Simonas Šaltenis Aalborg University
Data Structures & Algorithm CS-102 Lecture 12 Asymptotic Analysis Lecturer: Syeda Nazia Ashraf 1.
Asymptotic Complexity
Analysis of Algorithms CS 477/677
Introduction to Algorithms: Asymptotic Notation
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Asymptotic Analysis.
Introduction to Algorithms
Introduction to Algorithms (2nd edition)
CS 3343: Analysis of Algorithms
Algorithms Algorithm Analysis.
Growth of functions CSC317.
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Asymptotic Notations Algorithms Lecture 9.
Introduction to Algorithms Analysis
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Asymptotic Growth Rate
Asymptotic Analysis.
CS 3343: Analysis of Algorithms
Introduction to Algorithms
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Chapter 11: Further Topics in Algebra
At the end of this session, learner will be able to:
Algorithms Recurrences.
Presentation transcript:

Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 2

CS 477/677 - Lecture 22 Algorithm Analysis The amount of resources used by the algorithm –Space –Computational time Running time: –The number of primitive operations (steps) executed before termination Order of growth –The leading term of a formula –Expresses the behavior of a function toward infinity

CS 477/677 - Lecture 23 Asymptotic Notations A way to describe behavior of functions in the limit –How we indicate running times of algorithms –Describe the running time of an algorithm as n grows to  O notation: asymptotic “less than”: f(n) “≤” g(n)  notation: asymptotic “greater than”: f(n) “≥” g(n)  notation: asymptotic “equality”: f(n) “=” g(n)

CS 477/677 - Lecture 24 Logarithms In algorithm analysis we often use the notation “ log n ” without specifying the base Binary logarithm Natural logarithm

CS 477/677 - Lecture 25 Asymptotic Notations - Examples For each of the following pairs of functions, either f(n) is O(g(n)), f(n) is Ω(g(n)), or f(n) is Θ(g(n)). Determine which relationship is correct. –f(n) = log n 2 ; g(n) = log n + 5 –f(n) = n; g(n) = log n 2 –f(n) = log log n; g(n) = log n –f(n) = n; g(n) = log 2 n –f(n) = n log n + n; g(n) = log n –f(n) = 10; g(n) = log 10 –f(n) = 2 n ; g(n) = 10n 2 –f(n) = 2 n ; g(n) = 3 n f(n) =  (g(n)) f(n) =  (g(n)) f(n) = O(g(n)) f(n) =  (g(n)) f(n) =  (g(n)) f(n) =  (g(n)) f(n) = O(g(n))

CS 477/677 - Lecture 26 Asymptotic notations O-notation Intuitively: O(g(n)) = the set of functions with a smaller or same order of growth as g(n)

CS 477/677 - Lecture 27 Examples –2n 2 = O(n 3 ): – n 2 = O(n 2 ): – 1000n n = O(n 2 ): –n = O(n 2 ): 2n 2 ≤ cn 3  2 ≤ cn  c = 1 and n 0 = 2 n 2 ≤ cn 2  c ≥ 1  c = 1 and n 0 = n n ≤ 1000n n 2 = 2000n 2  c=2000 and n 0 = 1 n ≤ cn 2  cn ≥ 1  c = 1 and n 0 = 1

CS 477/677 - Lecture 28 Asymptotic notations (cont.)  - notation Intuitively:  (g(n)) = the set of functions with a larger or same order of growth as g(n)

CS 477/677 - Lecture 29 Examples – 5n 2 =  (n) –100n + 5 ≠  (n 2 ) –n =  (2n), n 3 =  (n 2 ), n =  (logn)  c, n 0 such that: 0  cn  5n 2  cn  5n 2  c = 1 and n 0 = 1  c, n 0 such that: 0  cn 2  100n n + 5  100n + 5n (  n  1) = 105n cn 2  105n  n(cn – 105)  0 Since n is positive  cn – 105  0  n  105/c  contradiction: n cannot be smaller than a constant

CS 477/677 - Lecture 210 Asymptotic notations (cont.)  -notation Intuitively  (g(n)) = the set of functions with the same order of growth as g(n)

CS 477/677 - Lecture 211 Examples –n 2 /2 –n/2 =  (n 2 ) ½ n 2 - ½ n ≤ ½ n 2  n ≥ 0  c 2 = ½ ½ n 2 - ½ n ≥ ½ n 2 - ½ n * ½ n (  n ≥ 2 ) = ¼ n 2  c 1 = ¼ –n ≠  (n 2 ): c 1 n 2 ≤ n ≤ c 2 n 2  only holds for: n ≤ 1/ c 1

CS 477/677 - Lecture 212 Examples –6n 3 ≠  (n 2 ): c 1 n 2 ≤ 6n 3 ≤ c 2 n 2  only holds for: n ≤ c 2 /6 –n ≠  (logn): c 1 logn ≤ n ≤ c 2 logn  c 2 ≥ n/logn,  n≥ n 0 – impossible

CS 477/677 - Lecture 213 More on Asymptotic Notations There is no unique set of values for n 0 and c in proving the asymptotic bounds Prove that 100n + 5 = O(n 2 ) –100n + 5 ≤ 100n + n = 101n ≤ 101n 2 for all n ≥ 5 n 0 = 5 and c = 101 is a solution –100n + 5 ≤ 100n + 5n = 105n ≤ 105n 2 for all n ≥ 1 n 0 = 1 and c = 105 is also a solution Must find SOME constants c and n 0 that satisfy the asymptotic notation relation

CS 477/677 - Lecture 214 Comparisons of Functions Theorem: f(n) =  (g(n))  f = O(g(n)) and f =  (g(n)) Transitivity: –f(n) =  (g(n)) and g(n) =  (h(n))  f(n) =  (h(n)) –Same for O and  Reflexivity: –f(n) =  (f(n)) –Same for O and  Symmetry: –f(n) =  (g(n)) if and only if g(n) =  (f(n)) Transpose symmetry: –f(n) = O(g(n)) if and only if g(n) =  (f(n))

CS 477/677 - Lecture 215 Asymptotic Notations in Equations On the right-hand side –  (n 2 ) stands for some anonymous function in  (n 2 ) 2n 2 + 3n + 1 = 2n 2 +  (n) means: There exists a function f(n)   (n) such that 2n 2 + 3n + 1 = 2n 2 + f(n) On the left-hand side 2n 2 +  (n) =  (n 2 ) No matter how the anonymous function is chosen on the left-hand side, there is a way to choose the anonymous function on the right-hand side to make the equation valid.

CS 477/677 - Lecture 216 Some Simple Summation Formulas Arithmetic series: Geometric series: –Special case: x < 1: Harmonic series: Other important formulas:

CS 477/677 - Lecture 217 Mathematical Induction Used to prove a sequence of statements ( S(1), S(2), … S(n) ) indexed by positive integers Proof: –Basis step: prove that the statement is true for n = 1 –Inductive step: assume that S(n) is true and prove that S(n+1) is true for all n ≥ 1 Find case n “within” case n+1

CS 477/677 - Lecture 218 Example Prove that: 2n + 1 ≤ 2 n for all n ≥ 3 Basis step: –n = 3: 2  ≤ 2 3  7 ≤ 8 TRUE Inductive step: –Assume inequality is true for n, and prove it for (n+1) Assume: 2n + 1 ≤ 2 n Must prove: 2(n + 1) + 1 ≤ 2 n+1 2(n + 1) + 1 = (2n + 1 ) + 2 ≤ 2 n + 2 ≤  2 n + 2 n = 2 n+1, since 2 ≤ 2 n for n ≥ 1

CS 477/677 - Lecture 219 Readings Chapter 3 Apendix A