CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Discrete Structures CISC 2315
 The running time of an algorithm as input size approaches infinity is called the asymptotic running time  We study different notations for asymptotic.
CSE 373 Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
Asymptotic Growth Rate
Cutler/HeadGrowth of Functions 1 Asymptotic Growth Rate.
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
1 TCSS 342, Winter 2005 Lecture Notes Course Overview, Review of Math Concepts, Algorithm Analysis and Big-Oh Notation Weiss book, Chapter 5, pp
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Chapter 2: Algorithm Analysis Big-Oh and Other Notations in Algorithm Analysis Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Algorithm analysis and design Introduction to Algorithms week1
TCSS 342 Lecture Notes Course Overview, Review of Math Concepts,
Asymptotic Notations Iterative Algorithms and their analysis
CSE 373: Data Structures and Algorithms Lecture 4: Math Review/Asymptotic Analysis II 1.
Growth Rates of Functions 3/26/12. Asymptotic Equivalence Def: For example, Note that n 2 +1 is being used to name the function f such that f(n) = n 2.
1 Big-Oh Notation CS 105 Introduction to Data Structures and Algorithms.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Design and Analysis Algorithm Drs. Achmad Ridok M.Kom Fitra A. Bachtiar, S.T., M. Eng Imam Cholissodin, S.Si., M.Kom Aryo Pinandito, MT Pertemuan 04.
CS 3343: Analysis of Algorithms
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Asymptotic Analysis-Ch. 3
Coursenotes CS3114: Data Structures and Algorithms Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright ©
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.
Design and Analysis of Algorithms Chapter Asymptotic Notations* Dr. Ying Lu August 30, RAIK.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
Introduction to Analysis of Algorithms CS342 S2004.
Time Complexity of Algorithms
Time Complexity of Algorithms (Asymptotic Notations)
General rules: Find big-O f(n) = k = O(1) f(n) = a k n k + a k-1 n k a 1 n 1 + a 0 = O(n k ) Other functions, try to find the dominant term according.
Algorithm Analysis Part of slides are borrowed from UST.
Big-O. Algorithm Analysis Exact analysis: produce a function f(n) measuring how many basic steps are needed for a given inputs n On any input of size.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
CSE 373: Data Structures and Algorithms
Algorithm Complexity L. Grewe 1. Algorithm Efficiency There are often many approaches (algorithms) to solve a problem. How do we choose between them?
CSE 373: Data Structures and Algorithms Lecture 4: Math Review/Asymptotic Analysis II 1.
Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures.
1 CSE 373 Algorithm Analysis and Runtime Complexity slides created by Marty Stepp ©
Asymptotic Notation Faculty Name: Ruhi Fatima
Kompleksitas Waktu Asimptotik CSG3F3 Lecture 5. 2 Intro to asymptotic f(n)=an 2 + bn + c RMB/CSG3F3.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
Algorithms Lecture #05 Uzair Ishtiaq. Asymptotic Notation.
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
Chapter 3 Growth of Functions Lee, Hsiu-Hui
Asymptotic Analysis.
Introduction to Algorithms Analysis
Asymptotic Growth Rate
Asymptotic Analysis.
Fundamentals of Algorithms MCS - 2 Lecture # 9
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Advanced Analysis of Algorithms
CSE 373 Optional Section Led by Yuanwei, Luyi Apr
Performance Evaluation
CSC 380: Design and Analysis of Algorithms
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
Advanced Analysis of Algorithms
Estimating Algorithm Performance
Big Omega, Theta Defn: T(N) = (g(N)) if there are positive constants c and n0 such that T(N)  c g(N) for all N  n0 . Lingo: “T(N) grows no slower than.
Algorithm Course Dr. Aref Rashad
Presentation transcript:

CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review

Big-Oh notation 2  Defn: f(n) = O(g(n)), if there exists positive constants c and n 0 such that: f(n)  c· g(n) for all n  n 0  Asymptotic upper bound  Idea: We are concerned with how the function grows when N is large.  We are not concerned with constant factors  Lingo: "f(n) grows no faster than g(n)." c *

Functions in Algorithm Analysis 3  f(n) : {0, 1,  }   +  domain of f is the nonnegative integers (count of data)  range of f is the nonnegative reals (time)  We use many functions with other domains and ranges.  Example: f(n) = 5 n log 2 (n/3)  Although the domain of f is nonnegative integers, the domain of log 2 is all positive reals.

Big-Oh example problems 4  n = O(2n) ?  2n = O(n) ?  n = O(n 2 ) ?  n 2 = O(n) ?  n = O(1)?  100 = O(n) ?  214n + 34 = O(2n 2 + 8n) ?

Preferred Big-Oh usage 5  P ick tightest bound. If f(n) = 5n, then: f(n) = O(n 5 ) f(n) = O(n 3 ) f(n) = O(n log n) f(n) = O(n)  preferred  Ignore constant factors and low order terms f(n) = O(n), not f(n) = O(5n) f(n) = O(n 3 ), not f(n) = O(n 3 + n 2 + n log n)  Wrong: f(n)  O(g(n))  Wrong: f(n)  O(g(n))

Show f(n) = O(n) 6  Claim: 2n + 6 = O(n)  Proof: Must find c, n 0 such that for all n > n 0, 2n + 6 <= c * n

Big omega, theta 7  big-Oh Defn: f(n) = O(g(n)) if there exist positive constants c and n 0 such that f(n)  c· g(n) for all n  n 0  big-Omega Defn: f(n) =  (g(n)) if there exist positive constants c and n 0 such that f(n)  c· g(n) for all n  n 0  Lingo: "f(n) grows no slower than g(n)."  big-Theta Defn: f(n) =  (g(n)) if and only if f(n) = O(g(n)) and f(n) =  (g(n)).  Big-Oh, Omega, and Theta establish a relative ordering among all functions of n

notationintuition O (Big-Oh) f(n)  g(n)  (Big-Omega) f(n)  g(n)  (Theta) f(n) = g(n) Intuition about the notations 8

Little Oh  little-Oh Defn: f(n) = o(g(n)) if for all positive constants c there exists an n 0 such that f(n) < c· g(n) for all n  n 0. In other words, f(n) = O(g(n)) and f(n) ≠  (g(n)) 9

Efficiency examples 3 10 sum = 0; for (int i = 1; i <= N * N; i++) { for (int j = 1; j <= N * N * N; j++) { sum++; }  What is the Big-Oh? N N2N2 N3N3

Math background: Exponents 11  Exponents  X Y, or "X to the Y th power"; X multiplied by itself Y times  Some useful identities  X A X B = X A+B  X A / X B = X A-B  (X A ) B = X AB  X N +X N = 2X N  2 N +2 N = 2 N+1

Efficiency examples 4 12 sum = 0; for (int i = 1; i <= N; i += c) { sum++; }  What is the Big-Oh? N/c + 1 N/c

Efficiency examples 5 13 sum = 0; for (int i = 1; i <= N; i *= c) { sum++; }  What is the Big-Oh? Equivalently (running time-wise): i = N; while (i > 1) { i /= c; } log c N + 1 log c N log c N + 1 log c N

Math background: Logarithms 14  Logarithms  definition: X A = B if and only if log X B = A  intuition: log X B means: "the power X must be raised to, to get B”  In this course, a logarithm with no base implies base 2. log B means log 2 B  Examples  log 2 16 = 4(because 2 4 = 16)  log = 3(because 10 3 = 1000)

Logarithm identities  Identities for logs:  log (AB) = log A + log B  log (A/B) = log A – log B  log (A B ) = B log A  Identity for converting bases of a logarithm:  example: log 4 32 = (log 2 32) / (log 2 4) = 5 / 2 15

Techniques: Logarithm problem solving 16  When presented with an expression of the form: log a X = Y and trying to solve for X, raise both sides to the a power. X = a Y  When presented with an expression of the form: log a X = log b Y and trying to solve for X, find a common base between the logarithms using the identity on the last slide. log a X = log a Y / log a b

Prove identity for converting bases 17 Prove log a b = log c b / log c a.

A log is a log… 18  We will assume all logs are to base 2  Fine for Big Oh analysis because the log to one base is equivalent to the log of another base within a constant factor  E.g., log 10 x is equivalent to log 2 x within what constant factor?

Efficiency examples 6 19 int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i / 2; j += 2) { sum++; }

Math background: Arithmetic series 20  Series  for some expression Expr (possibly containing i), means the sum of all values of Expr with each value of i between j and k inclusive Example: = (2(0) + 1) + (2(1) + 1) + (2(2) + 1) + (2(3) + 1) + (2(4) + 1) = = 25

Series Identities  Sum from 1 through N inclusive  Is there an intuition for this identity? Sum of all numbers from 1 to N (N-2) + (N-1) + N  How many terms are in this sum? Can we rearrange them? 21