Loops, Summations, Order Reduction Chapter 2 Highlights.

Slides:



Advertisements
Similar presentations
Chapter 20 Computational complexity. This chapter discusses n Algorithmic efficiency n A commonly used measure: computational complexity n The effects.
Advertisements

Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
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.
© 2004 Goodrich, Tamassia 1 Lecture 01 Algorithm Analysis Topics Basic concepts Theoretical Analysis Concept of big-oh Choose lower order algorithms Relatives.
Analysis of Algorithms Algorithm Input Output. Analysis of Algorithms2 Outline and Reading Running time (§1.1) Pseudo-code (§1.1) Counting primitive operations.
Complexity Analysis (Part I)
Loops, Summations, Order Reduction Chapter 2 Highlights.
Analysis of Algorithms (Chapter 4)
Analysis of Algorithms
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
Fall 2006CSC311: Data Structures1 Chapter 4 Analysis Tools Objectives –Experiment analysis of algorithms and limitations –Theoretical Analysis of algorithms.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
The Seven Functions. Analysis of Algorithms. Simple Justification Techniques. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer Goodrich,
Bigointro1 Algorithm Analysis & Program Testing An introduction.
Loops, Summations, Order Reduction Chapter 2 Highlights.
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
Analysis of Algorithms Lecture 2
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Running Time Big O Notation.
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.
Analysis of Algorithms
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
Analysis Tools Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Analysis of Algorithms
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time. Chapter 4. Algorithm Analysis (complexity)
Complexity Analysis Chapter 1.
Analysis of Algorithms Algorithm Input Output Last Update: Aug 21, 2014 EECS2011: Analysis of Algorithms1.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
Extracting Performance Functions. Basic Operations n The number of Basic Operations performed must be proportional to the run time n Counting techniques.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
Grading Exams 60 % Lab 20 % Participation 5% Quizes 15%
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
Chapter 9 Efficiency of Algorithms. 9.3 Efficiency of Algorithms.
Recitation on analysis of algorithms. Formal definition of O(n) We give a formal definition and show how it is used: f(n) is O(g(n)) iff There is a positive.
Analysis of algorithms. What are we going to learn? Need to say that some algorithms are “better” than others Criteria for evaluation Structure of programs.
7.1 Polynomial Functions Evaluate Polynomials
UNIT 2, LESSON 1 POLYNOMIAL FUNCTIONS. WHAT IS A POLYNOMIAL FUNCTION? Coefficients must be real numbers. Exponents must be whole numbers.
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.
تصميم وتحليل الخوارزميات عال311 Chapter 3 Growth of Functions
Searching Topics Sequential Search Binary Search.
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.
Introduction to Algorithm Analysis Concepts Fundamental Data Structures and Algorithms Aleks Nanevski and Margaret Reid-Miller January 15, 2003.
Lecture 4 Jianjun Hu Department of Computer Science and Engineerintg University of South Carolina CSCE350 Algorithms and Data Structure.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
1 COMP9024: Data Structures and Algorithms Week Two: Analysis of Algorithms Hui Wu Session 2, 2014
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
COMP9024: Data Structures and Algorithms
Algorithms Algorithm Analysis.
COMP9024: Data Structures and Algorithms
Analysis of Algorithms
Program Efficiency Interested in “order of magnitude”
5.2 Evaluate and Graph Polynomial Functions
Multiplying Polynomials
Efficiency (Chapter 2).
Big-Oh and Execution Time: A Review
Analysis of Bubble Sort and Loop Invariant
Analysis of Algorithms
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
8. Comparison of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Data Structures & Programming
Presentation transcript:

Loops, Summations, Order Reduction Chapter 2 Highlights

Constant times Linear for x = 1 to n { operation 1; operation 2; operation 3; } for x = 1 to n constant time operation Note: Constants are not a factor in evaluating algorithms. Why?

Linear-time Loop for x = 1 to n { constant-time operation } Note: Constant-time mean independent of the input size.

Linear-time Loop for x = 0 to n-1 constant-time operation Note: Don’t let starting at zero throw you off. Brackets not necessary for one statement.

2-Nested Loops  Quadratic for x = 0 to n-1 for y = 0 to n-1 constant-time operation The outer loop restarts the inner loop

3-Nested Loops  Cubic for x = 0 to n-1 for y = 0 to n-1 for z = 0 to n-1 constant-time operation f(n) = n 3 The number of nested loops determines the exponent

4-Nested Loops  n 4 for x = 0 to n-1 for y = 0 to n-1 for z = 0 to n-1 for w = 0 to n-1 constant-time operation f(n) = n 4

Add independent loops for x = 0 to n-1 constant-time op for y = 0 to n-1 for z = 0 to n-1 constant-time op for w = 0 to n-1 constant-time op f(n) = n + n 2 + n = n 2 + 2n

Non-trivial loops for x = 1 to n for y = 1 to x constant-time operation Note: x is controlling the inner loop.

Equivalent Loops for x = 1 to n for y = 1 to x constant-time op for x = 1 to n for y = x to n constant-time op Note: These two loops behave differently, but They perform the same number of basic operations.

Order reduction Given the following function Constants don’t matter Only the leading exponent matters Thus

Order reduction Given the following function Constants don’t matter Only the leading exponent matters

Example for z = 1 to n for y = 1 to z for x = 1 to y constant-op

Example for z = 1 to n for y = 1 to z for x = 1 to y constant-op

Example for z = 1 to n for y = 1 to z for x = 1 to y constant-op for z = 1 to n for y = 1 to z y operations

Example for z = 1 to n for y = 1 to z y operations

Example for z = 1 to n for y = 1 to z y operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Example for z = 1 to n z(z+1)/2 operations

Proof By Induction Prove the following:

Another Example if (n is odd) { for x = 1 to n for y = x to n 1 operation } else { for x = 1 to n/2 for y = 1 to n/2 1 operation }

Another Example if (n is odd) { for x = 1 to n for y = x to n 1 operation } else { for x = 1 to n/2 for y = 1 to n/2 for z = 1 to n/2 1 operation }

Another Example if (n is odd) { for x = 1 to n for y = x to n 1 operation } else { for x = 1 to n/2 for y = 1 to n/2 for z = 1 to n/2 1 operation } Best Case Worst Case Average Case

Algorithm Analysis Overview Counting loops leads to summations Summations lead to polynomials N (or n) used to to characterize input size Constants are not a factor Only the leading exponent matters Depending on input, algorithm can have different running times.

Average Case Depending on input algorithm could have a... Best case: Fastest running time possible Worst Case: Slowest running time possible To compute the average case, you need to know how often the best and worst case occur. This is not always known.

Worst Case Worst Case is more important. –This is how long you could be waiting –Always best to prepare for the worst There are always easy input