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

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Discrete Structures CISC 2315
CSE 373 Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III.
Analysis of Algorithms Review COMP171 Fall 2005 Adapted from Notes of S. Sarkar of UPenn, Skiena of Stony Brook, etc.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1 TCSS 342, Winter 2005 Lecture Notes Course Overview, Review of Math Concepts, Algorithm Analysis and Big-Oh Notation Weiss book, Chapter 5, pp
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
Chapter 2: Algorithm Analysis Big-Oh and Other Notations in Algorithm Analysis Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm.
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
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.
CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.
Algorithm analysis and design Introduction to Algorithms week1
1 i206: Lecture 6: Math Review, Begin Analysis of Algorithms Marti Hearst Spring 2012.
TCSS 342 Lecture Notes Course Overview, Review of Math Concepts,
Asymptotic Notations Iterative Algorithms and their analysis
MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
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.
Analysis of Algorithms1 The Goal of the Course Design “good” data structures and algorithms Data structure is a systematic way of organizing and accessing.
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.
Iterative Algorithm Analysis & Asymptotic Notations
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.
Divide & Conquer  Themes  Reasoning about code (correctness and cost)  recursion, induction, and recurrence relations  Divide and Conquer  Examples.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
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
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
Time Complexity of Algorithms (Asymptotic Notations)
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
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.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
2-0 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 2 Theoretical.
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?
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 2 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
CSE 373: Data Structures and Algorithms Lecture 4: Math Review/Asymptotic Analysis II 1.
1 CMSC 341 Math Review. 2 Exponents Identities (X A ) B = X AB X A * X B = X A+B X A / X B = X A-B X A + X B  X A+B.
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 2.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Introduction to Algorithms Analysis
Fundamentals of Algorithms MCS - 2 Lecture # 9
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Advanced Analysis of Algorithms
Chapter 2.
Fundamentals of the Analysis of Algorithm Efficiency
CSE 373 Optional Section Led by Yuanwei, Luyi Apr
CSC 380: Design and Analysis of Algorithms
At the end of this session, learner will be able to:
CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
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: Math Review/Asymptotic Analysis II 1

Functions in Algorithm Analysis f(n) : {0, 1,  }   + – domain of f is the nonnegative integers – range of f is the nonnegative reals Unless otherwise indicated, the symbols f, g, h, and T refer to functions with this domain and range. 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. 2

Efficiency examples 5 sum = 0; for (int i = 1; i <= N; i *= c) { sum++; } log c N + 1 log c N 3

Math background: Logarithms 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) 4

Identities for logs with addition, multiplication, powers: 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 Logarithm identities 5

Techniques: Logarithm problem solving 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 6

Logarithm practice problems Determine the value of x in the following equation. – log 7 x + log 7 13 = 3 Determine the value of x in the following equation. – log log 8 x = log log

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

A log is a log… 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? 9

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

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 Math background: Arithmetic series Example: = (2(0) + 1) + (2(1) + 1) + (2(2) + 1) + (2(3) + 1) + (2(4) + 1) = = 25 11

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? 12

More series identities sum from a through N inclusive (when the series doesn't start at 1) is there an intuition for this identity? 13

Series of constants sum of constants (when the body of the series doesn't contain the counter variable such as i) example: 14

Splitting series for any constant k, splitting a sum with addition moving out a constant multiple 15

Series of powers sum of powers of 2 – = = 63 – think about binary representation of numbers (63) + 1 (1) (64) when the series doesn't start at 0: 16

Series practice problems Give a closed form expression for the following summation. – A closed form expression is one without the  or "…". Give a closed form expression for the following summation. 17

Efficiency examples 6 (revisited) int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i / 2; j += 2) { sum++; } Compute the value of the variable sum after the following code fragment, as a closed-form expression in terms of input size n. – Ignore small errors caused by i not being evenly divisible by 2 and 4. 18

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

notationintuition O (Big-Oh) T(N)  g(n)  (Big-Omega) T(N)  g(n)  (Theta) T(N) = g(n) o (little-Oh) T(N) < g(n) Intuition about the notations 20