The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

College of Information Technology & Design
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
An Introduction to Sorting Chapter 8 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Analysys & Complexity of Algorithms Big Oh Notation.
Faster Sorting Methods Chapter 9 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 14 An Overview of Query Optimization. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Figure 14.1 Typical architecture for.
© 2006 Pearson Addison-Wesley. All rights reserved10-1 Chapter 10 Algorithm Efficiency and Sorting CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
The Efficiency of Algorithms
The Efficiency of Algorithms Chapter 9 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Searching Chapter 16 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
The Efficiency of Algorithms
Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Searching Chapter 18 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
An Introduction to Sorting Chapter 11 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Computer Science 2 Data Structures and Algorithms V Intro to “big o” Lists Professor: Evan Korth New York University 1.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Chapter 19 Searching, Sorting and Big O
Data Structures and Abstractions with Java, 4e Frank Carrano
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 9: Algorithm Efficiency and Sorting Data Abstraction &
Algorithm Efficiency Chapter 10 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 10 A Algorithm Efficiency. © 2004 Pearson Addison-Wesley. All rights reserved 10 A-2 Determining the Efficiency of Algorithms Analysis of algorithms.
An Introduction to Sorting Chapter 8 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
A Heap Implementation Chapter 26 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Copyright © 2010 Pearson Education, Inc. All rights reserved Sec Integer Exponents and Scientific Notation.
Iterators (short version) Chapter 15 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
A Bag Implementation that Links Data Chapter 3 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Recursion Chapter 7 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
1 ADT Implementation: Recursion, Algorithm Analysis Chapter 10.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Recursion,
The Efficiency of Algorithms Chapter 9 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights.
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
Algorithm Efficiency and Sorting
Analysis of Algorithms
An Introduction to Sorting
A Bag Implementation that Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
The Efficiency of Algorithms
List Implementations that Use Arrays
A List Implementation That Links Data
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Algorithm Efficiency Chapter 10
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
The Efficiency of Algorithms
The Efficiency of Algorithms
Basic Matrix Operations
The Efficiency of Algorithms
Analysis of Algorithms
A List Implementation That Links Data
Algorithm Efficiency and Sorting
List Implementations that Use Arrays
Presentation transcript:

The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Contents Motivation Measuring an Algorithm’s Efficiency  Counting Basic Operations  Best, Worst, and Average Cases Big Oh Notation  The Complexities of Program Constructs Copyright ©2012 by Pearson Education, Inc. All rights reserved

Contents Picturing Efficiency The Efficiency of Implementations of the ADT Bag  An Array-Based Implementation  A Linked Implementation  Comparing the Implementations Copyright ©2012 by Pearson Education, Inc. All rights reserved

Objectives Assess efficiency of given algorithm Compare expected execution times of two methods  Given efficiencies of algorithms Copyright ©2012 by Pearson Education, Inc. All rights reserved

Motivation Contrast algorithms Figure 4-1 Three algorithms for computing the sum n for an integer n > 0 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Motivation Java code for algorithms Even a simple program can be inefficient Copyright ©2012 by Pearson Education, Inc. All rights reserved

Measuring an Algorithm’s Efficiency Complexity  Space and time requirements Other issues for best solution  Generality of algorithm  Programming effort  Problem size – number of items program will handle  Growth-rate function Copyright ©2012 by Pearson Education, Inc. All rights reserved

Counting Basic Operations Figure 4-2 The number of basic operations required by the algorithms in Figure 4-1 Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-3 The number of basic operations required by the algorithms in Figure 4-1 as a function of n Copyright ©2012 by Pearson Education, Inc. All rights reserved

FIGURE 4-4 Typical growth-rate functions evaluated at increasing values of n Copyright ©2012 by Pearson Education, Inc. All rights reserved

Best, Worst, and Average Cases Some algorithms depend only on size of data set Other algorithms depend on nature of the data  Best case search when item at beginning  Worst case when item at end  Average case somewhere between Copyright ©2012 by Pearson Education, Inc. All rights reserved

Big Oh Notation Notation to describe algorithm complexity Definition A function f(n) is of order at most g(n) that is, f(n) is O(g(n))—if : A positive real number c and positive integer N exist such that or all n ≥ N. That is, is an upper bound on f(n) when n is sufficiently large. Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-5 An illustration of the definition of Big Oh Copyright ©2012 by Pearson Education, Inc. All rights reserved

Big Oh Identities O(k g(n)) = O(g(n)) for a constant k O(g1(n)) + O(g2(n)) = O(g1(n) + g2(n)) O(g1(n)) x O(g2(n)) = O(g1(n) x g2(n)) O(g1(n) + g2(n) gm(n)) = O(max(g1(n), g2(n),..., gm(n)) O(max(g1(n), g2(n),..., gm(n)) = max(O(g1(n)), O(g2(n)),..., O(gm(n))) Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-6 An O(n) algorithm Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-7 An O(n 2 ) algorithm Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-8 Another O(n 2 ) algorithm Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-9 The effect of doubling the problem size on an algorithm’s time requirement Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-10 The time required to process one million items by algorithms of various orders at the rate of one million operations per second Copyright ©2012 by Pearson Education, Inc. All rights reserved

Array Based Implementation Adding an entry to a bag, an O(1) method, Copyright ©2012 by Pearson Education, Inc. All rights reserved

Array Based Implementation Searching for an entry, O(1) best case, O(n) worst or average case Thus an O(n) method overall Copyright ©2012 by Pearson Education, Inc. All rights reserved

A Linked Implementation Adding an entry to a bag, an O(1) method, Copyright ©2012 by Pearson Education, Inc. All rights reserved

A Linked Implementation Searching a bag for a given entry, O(1) best case, O(n) worst case O(n) overall Copyright ©2012 by Pearson Education, Inc. All rights reserved

Figure 4-11 The time efficiencies of the ADT bag operations for two implementations, expressed in Big Oh notation Copyright ©2012 by Pearson Education, Inc. All rights reserved

End Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved