Analysis of Algorithms: Methods and Examples CSE 2320 – Algorithms and Data Structures Vassilis Athitsos Modified by Alexandra Stefan University of Texas.

Slides:



Advertisements
Similar presentations
Discrete Structures CISC 2315
Advertisements

CSCE 2100: Computing Foundations 1 Running Time of Programs
ALG0183 Algorithms & Data Structures Lecture 7 Big-Oh, Big-Omega, Big-Theta, Little-Oh 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 3 Growth of Functions
Introduction to Analysis of Algorithms
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
CSE 830: Design and Theory of Algorithms
CSE 830: Design and Theory of Algorithms Dr. Eric Torng.
CSE 421 Algorithms Richard Anderson Lecture 4. What does it mean for an algorithm to be efficient?
The Efficiency of Algorithms
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
The Efficiency of Algorithms
1 Discrete Mathematics Summer 2004 By Dan Barrish-Flood originally for Fundamental Algorithms For use by Harper Langston in D.M.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
CSE 421 Algorithms Richard Anderson Lecture 3. Classroom Presenter Project Understand how to use Pen Computing to support classroom instruction Writing.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
Chapter 6 Algorithm Analysis Bernard Chen Spring 2006.
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
1 Big-Oh Notation CS 105 Introduction to Data Structures and Algorithms.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Iterative Algorithm Analysis & Asymptotic Notations
Complexity Analysis Chapter 1.
Analysis of Algorithms
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
CSCI 3160 Design and Analysis of Algorithms Tutorial 1
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
Analysis of Algorithms: Methods and Examples CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 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 CSE 2320 – Algorithms and Data Structures Vassilis Athitsos Modified by Alexandra Stefan University of Texas at Arlington 1.
Asymptotic Growth Rates  Themes  Analyzing the cost of programs  Ignoring constants and Big-Oh  Recurrence Relations & Sums  Divide and Conquer 
CMSC 341 Asymptotic Analysis. 2 Complexity How many resources will it take to solve a problem of a given size? –time –space Expressed as a function of.
Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.
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.
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.
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Analysis CSE 331. Definition of Efficiency An algorithm is efficient if, when implemented, it runs quickly on real instances Implemented where?
COSC 1P03 Data Structures and Abstraction 2.1 Analysis of Algorithms Only Adam had no mother-in-law. That's how we know he lived in paradise.
Data Structures Using C++ 2E
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
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.
Analysis of Algorithms CSE 2320 – Algorithms and Data Structures Vassilis Athitsos Modified by Alexandra Stefan University of Texas at Arlington 1.
Analysis of Algorithms: Methods and Examples CSE 2320 – Algorithms and Data Structures Alexandra Stefan Based on presentations by Vassilis Athitsos and.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 4.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Algorithm Complexity Analysis (Chapter 10.4) Dr. Yingwu Zhu.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Algorithm Analysis 1.
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms: Methods and Examples
Time Complexity for Loops
Analysis of Algorithms
Richard Anderson Lecture 3
Recurrences (Method 4) Alexandra Stefan.
Summary Simple runtime problems ‘Counting’ instructions
Richard Anderson Winter 2019 Lecture 4
CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Analysis of Algorithms
Richard Anderson Autumn 2015 Lecture 4
Presentation transcript:

Analysis of Algorithms: Methods and Examples CSE 2320 – Algorithms and Data Structures Vassilis Athitsos Modified by Alexandra Stefan University of Texas at Arlington 1

Counting instructions Count in detail the total number of instructions executed by the each of the following pieces of code: // Example A. Notice the ; at the end of the for loop. for (i = 0; i <N; i++) ; // Example B for (i = 0; i<N; i++) for(j=0; j<N; j++) for(k=0; k<N; k++) printf(“A”); // Example C (source: Dr. Bob Weems) sum = 0; for (i = 0; i<N; i++) for(j=1; j<N; j = j+j) sum = sum + a[i]/a[j];

Estimate runtime Problem: The total number of instructions in a program (or a piece of a program) is and the computer it runs on executes 10 9 instructions per second. How long will it take to run this program? Give the answer in seconds. If it is very large, transform it in larger units (hours, days, years). Summary: – Total instructions: – Speed: 10 9 instructions per second Answer: – Time = (total instructions)/speed = (10 12 instructions) / (10 9 instr/sec) = 10 3 seconds ~ 15 minutes Note that this computation is similar to computing the time it takes to travel a certain distance ( e.g. 120miles) given the speed (e.g. 60 miles/hour). 3

Estimate runtime A slightly different way to formulate the same problem: – total number of instructions in a program (or a piece of a program) is and – the computer it runs on executes one instruction in one nanosecond (10 -9 seconds) – How long will it take to run this program? Give the answer in seconds. If it is very large, transform it in larger units (hours, days, years) Summary: – total instructions – seconds per instruction Answer: – Time = (total instructions) * (seconds per instruction) = (10 12 instructions)* (10 -9 sec/instr) = 10 3 seconds ~ 15 minutes 4

5

Big-Oh Notation A function g(N) is said to be O(f(N)) if there exist constants c 0 and N 0 such that: g(N) ≤ c 0 f(N) for all N ≥ N 0. Typically, g(N) is the running time of an algorithm, in your favorite units, implementation, and machine. This can be a rather complicated function. In algorithmic analysis, we try to find a f(N) that is simple, and such that g(N) = O(f(N)). 6

Big-Oh Notation Upper bound: A function g(N) is said to be O(f(N)) if there exist constants c 0 and N 0 such that: g(N) ≤ c 0 f(N) for all N ≥ N 0. Lower bound: A function g(N) is said to be Ω(f(N)) if there exist constants c 0 and N 0 such that: c 0 f(N) ≤ g(N) for all N ≥ N 0. Tight bound: A function g(N) is said to be Θ(f(N)) if there exist constants c 0, c 1 and N 0 such that: c 0 f(N) ≤ g(N) ≤ c 1 f(N) for all N ≥ N 0. 7

Simplifying Big-Oh Notation Suppose that we are given this running time: g(N) = 35N N + lg(N) How can we express g(N) in Big-Oh notation? 8

Simplifying Big-Oh Notation Suppose that we are given this running time: g(N) = 35N N + lg(N) How can we express g(N) in Big-Oh notation? Typically we say that g(N) = O(N 2 ). The following are also correct, but unnecessarily complicated, and thus less useful, and rarely used. – g(N) = O(N 2 ) + O(N). – g(N) = O(N 2 ) + O(N) + O(lgN) + O(1). – g(N) = O(35N N + lg(N) ). 9

Simplifying Big-Oh Notation Suppose that we are given this running time: g(N) = 35N N + lg(N) We say that g(N) = O(N 2 ). Why is this mathematically correct? – Why can we ignore the non-quadratic terms? Ans 1: Using the Big-Oh definition: we can find an N 0 such that, for all N ≥ N 0 : g(N) ≤ 36N 2. – If you don't believe this, do the calculations for practice. 10

Polynomial functions If g(N) is a polynomial function, then it is Θ of the dominant term. 11

Properties of O, Ω and Θ 12

Using Limits 13

Using Limits 14

Using Limits: An Example 15

Using Limits: An Example 16

Using Limits: An Example 17

Big-Oh Transitivity 18

Big-Oh Hierarchy 19

Big-Oh Transitivity 20

Using Substitutions 21

Using Substitutions 22

Big-Oh Notation: Example Problem 23

Big-Oh Notation: Example Problem 24

Useful logarithm properties 25

Summary 26