Efficiency (Chapter 2).

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

MATH 224 – Discrete Mathematics
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
Algorithm Analysis.
Lecture: Algorithmic complexity
COS 312 DAY 16 Tony Gauvin. Ch 1 -2 Agenda Questions? Next progress report is March 26 Assignment 4 Corrected – 3 A’s, 1 C, 1 D, 1 F and 1 MIA Assignment.
Chapter 11 Analysis of Algorithms. Chapter Scope Efficiency goals The concept of algorithm analysis Big-Oh notation The concept of asymptotic complexity.
Introduction to Analysis of Algorithms
Cmpt-225 Algorithm Efficiency.
Loops, Summations, Order Reduction Chapter 2 Highlights.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
1 ©2008 DEEDS Group Introduction to Computer Science 2 - SS 08 Asymptotic Complexity Introduction in Computer Science 2 Asymptotic Complexity DEEDS Group.
Iterative Algorithm Analysis & Asymptotic Notations
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
Complexity Analysis Chapter 1.
COMP 232 Intro Lecture. Introduction to Course Me – Dr. John Sigle Purpose/goals of the course Purpose/goals Prerequisites - COMP 132 (Java skill & Eclipse)
COS 312 DAY 16 Tony Gauvin. Ch 1 -2 Agenda Questions? Next Capstone progress report is March 26 Assignment 4 Corrected – 3 A’s, 1 C, 1 D, 1 F and 1 MIA.
Analysis of Algorithms
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
The Growth of Functions Rosen 3.2. What affects runtime of a program? the machine it runs on the programming language the efficiency of the compiler the.
Searching Topics Sequential Search Binary Search.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Analysis of Algorithms. Algorithm Efficiency The efficiency of an algorithm is usually expressed in terms of its use of CPU time The analysis of algorithms.
Algorithm Analysis 1.
CS 302 Data Structures Algorithm Efficiency.
19 Searching and Sorting.
Introduction to Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
Introduction to Analysis of Algorithms
Introduction to complexity
Analysis of Algorithms
Introduction to Algorithms
Big O notation Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case.
Introduction to Analysis of Algorithms
Chapter 11 Analysis of Algorithms
Introduction to Algorithms
Algorithm Analysis CSE 2011 Winter September 2018.
Program Efficiency Interested in “order of magnitude”
Enough Mathematical Appetizers!
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
CHAPTER 2: Analysis of Algorithms
Lab 03 - Iterator.
Chapter 12: Analysis of Algorithms
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Chapter 2 Analysis of Algorithms
Chapter 2 Analysis of Algorithms
Big O Notation.
Comparing Algorithms Unit 1.2.
CS 201 Fundamental Structures of Computer Science
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Algorithmic Complexity
Performance Evaluation
CHAPTER 2: Analysis of Algorithms
8. Comparison of Algorithms
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Data Structures & Programming
Presentation transcript:

Efficiency (Chapter 2)

Efficiency of Algorithms Difficult to get a precise measure of the performance of an algorithm or program Can characterize a program by how the execution time or memory requirements increase as a function of increasing input size Big-O notation A simple way to determine the big-O of an algorithm or program is to look at the loops and to see whether the loops are nested

Counting Executions Generally, A statement counts as “1” Sequential statements add: Statement; statement 2 Loops multiply based on how many times they run

Counting Example Consider: First time through outer loop, inner loop is executed n-1 times; next time n-2, and the last time once. So we have T(n) = 3(n – 1) + 3(n – 2) + … + 3 or T(n) = 3(n – 1 + n – 2 + … + 1)

Counting Example (continued) We can reduce the expression in parentheses to: n x (n – 1) 2 So, T(n) = 1.5n2 – 1.5n This polynomial is zero when n is 1. For values greater than 1, 1.5n2 is always greater than 1.5n2 – 1.5n Therefore, we can use 1 for n0 and 1.5 for c to conclude that T(n) is O(n2)

Big-O Growth

Importance of Big-O Doesn’t matter for small values of N Shows how time grows with size Regardless of comparative performance for small N, smaller big-O will eventually win Technically, what we usually use when we say big-O, is really big-Theta

Some Rules If you have to read or write N items of data, your program is at least O(N) Search programs range from O(log N) to O(N) Sort programs range from O(N log N) to O(N2)

Cases Different data might take different times to run Best case Worst case Average case Example: consider sequential search…