CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Lecture: Algorithmic complexity
CSE 373 Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III.
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
CSE332: Data Abstractions Lecture 3: Asymptotic Analysis Dan Grossman Spring 2010.
CSE 143 Lecture 4: testing and complexity reading:
Introduction to Analysis of Algorithms
CSE 326: Data Structures Lecture #2 Analysis of Algorithms Alon Halevy Fall Quarter 2000.
1 TCSS 342, Winter 2005 Lecture Notes Course Overview, Review of Math Concepts, Algorithm Analysis and Big-Oh Notation Weiss book, Chapter 5, pp
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
CS2420: Lecture 4 Vladimir Kulyukin Computer Science Department Utah State University.
TTIT33 Algorithms and Optimization – Lecture 1 Jan Maluszynski - HT Analysis of Algorithms Introductory Example Principles of Analysis Big-Oh notation.
Elementary Data Structures and Algorithms
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
CSE332: Data Abstractions Lecture 3: Asymptotic Analysis Dan Grossman Spring 2012.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Algorithm Analysis (Big O)
CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014.
CSE 143 Lecture 5 Binary search; complexity reading: slides created by Marty Stepp and Hélène Martin
Asymptotic Growth Rates Themes –Analyzing the cost of programs –Ignoring constants and Big-Oh –Recurrence Relations & Sums –Divide and Conquer Examples.
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
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.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
Iterative Algorithm Analysis & Asymptotic Notations
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Catie Baker Spring 2015.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
1 CSE 326 Data Structures: Complexity Lecture 2: Wednesday, Jan 8, 2003.
Asymptotic Growth Rates  Themes  Analyzing the cost of programs  Ignoring constants and Big-Oh  Recurrence Relations & Sums  Divide and Conquer 
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Lauren Milne Summer 2015.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
Algorithm Analysis Part of slides are borrowed from UST.
CSE 143 Lecture 6 Interfaces; Complexity (Big-Oh) reading: 9.5, 11.1, slides created by Marty Stepp
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
Binary search and complexity reading:
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
CSE 326: Data Structures Asymptotic Analysis Hannah Tang and Brian Tjaden Summer Quarter 2002.
CSE 373: Data Structures and Algorithms Lecture 4: Math Review/Asymptotic Analysis II 1.
DS.A.1 Algorithm Analysis Chapter 2 Overview Definitions of Big-Oh and Other Notations Common Functions and Growth Rates Simple Model of Computation Worst.
A Introduction to Computing II Lecture 5: Complexity of Algorithms Fall Session 2000.
1 CSE 373 Algorithm Analysis and Runtime Complexity slides created by Marty Stepp ©
CSE 326: Data Structures Lecture #3 Asymptotic Analysis Steve Wolfman Winter Quarter 2000.
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Linda Shapiro Winter 2015.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 4.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Building Java Programs Chapter 13 Lecture 13-1: binary search and complexity reading:
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Introduction to Algorithms
Time Complexity Analysis Neil Tang 01/19/2010
Algorithm Analysis Neil Tang 01/22/2008
Algorithm Analysis (not included in any exams!)
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis
Chapter 2.
Asst. Dr.Surasak Mungsing
CSE 332: Data Abstractions Leftover Asymptotic Analysis
At the end of this session, learner will be able to:
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
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.
Presentation transcript:

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1

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

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 3

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

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

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

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

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: 8

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. 9

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. 10

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

f(n) = O(g(N)) – g(n) is an upper bound on f(n) – f(n) grows no faster than g(n) f(n) =  (g(N)) – g(N) is a lower bound on f(n) – f(n) grows at least as fast as g(N) f(n) =  (g(N)) – f(n) grows at the same rate as g(N) Growth rate terminology (recap) 12

Facts about big-Oh If T 1 (N) = O(f(N)) and T 2 (N) = O(g(N)), then – T 1 (N) + T 2 (N) = O(f(N) + g(N)) – T 1 (N) * T 2 (N) = O(f(N) * g(N)) If T(N) is a polynomial of degree k, then: T(N) =  (N k ) – example: 17n 3 + 2n 2 + 4n + 1 =  (n 3 ) log k N = O(N), for any constant k 13

Complexity classes complexity class: A category of algorithm efficiency based on the algorithm's relationship to the input size N. ClassBig-OhIf you double N,...Example constantO(1)unchanged10ms logarithmicO(log 2 N)increases slightly175ms linearO(N)doubles3.2 sec log-linearO(N log 2 N) slightly more than doubles6 sec quadraticO(N 2 )quadruples1 min 42 sec cubicO(N 3 )multiplies by 855 min... exponentialO(2 N )multiplies drastically5 * years 14

Complexity cases Worst-case complexity: “most challenging” input of size n Best-case complexity: “easiest” input of size n Average-case complexity: random inputs of size n Amortized complexity: m “most challenging” consecutive inputs of size n, divided by m 15

Bounds vs. Cases Two orthogonal axes: Bound – Upper bound (O) – Lower bound (  ) – Asymptotically tight (  ) Analysis Case – Worst Case (Adversary), T worst (n) – Average Case, T avg (n) – Best Case, T best (n) – Amortized, T amort (n) One can estimate the bounds for any given case. 16

Example List.contains(Object o) returns true if the list contains o ; false otherwise Input size: n (the length of the List ) f(n) = “running time for size n” But f(n) needs clarification: – Worst case f(n): it runs in at most f(n) time – Best case f(n): it takes at least f(n) time – Average case f(n): average time 17

Recursive programming A method in Java can call itself; if written that way, it is called a recursive method The code of a recursive method should be written to handle the problem in one of two ways: – base case: a simple case of the problem that can be answered directly; does not use recursion. – recursive case: a more complicated case of the problem, that isn't easy to answer directly, but can be expressed elegantly with recursion; makes a recursive call to help compute the overall answer 18

Recursive power function Defining powers recursively: pow(x, 0) = 1 pow(x, y) = x * pow(x, y-1), y > 0 // recursive implementation public static int pow(int x, int y) { if (y == 0) { return 1; } else { return x * pow(x, y - 1); } 19