© 2017 Pearson Education, Hoboken, NJ. All rights reserved

Slides:



Advertisements
Similar presentations
Md. Ahsan Arif, Assistant Professor, Dept. of CSE, AUB
Advertisements

© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 10 Algorithm Efficiency
© 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.
Data Structures Data Structures Topic #7. Today’s Agenda How to measure the efficiency of algorithms? Discuss program #3 in detail Review for the midterm.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Cmpt-225 Algorithm Efficiency.
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
TTIT33 Algorithms and Optimization – Lecture 1 Jan Maluszynski - HT Analysis of Algorithms Introductory Example Principles of Analysis Big-Oh notation.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Searching Chapter 18 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
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:
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Measuring the Efficiency of Algorithms Analysis of algorithms Provides tools for contrasting the efficiency of different methods of solution Time efficiency,
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.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Algorithm Efficiency and Sorting Data Structure & Algorithm.
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Efficiency of Algorithms. Node - data : Object - link : Node + createNode() + getData() + setData() + getLink() + setLink() + addNodeAfter() + removeNodeAfter()
Algorithm Analysis (Big O)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Concepts of Algorithms CSC-244 Unit 3 and 4 Algorithm Growth Rates Shahid Iqbal Lone Computer College Qassim University K.S.A.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
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,
Algorithm Analysis 1.
Chapter 10 Algorithm Efficiency
Algorithm Efficiency and Sorting
CS 302 Data Structures Algorithm Efficiency.
Analysis of Algorithms
ADT Implementation: Recursion, Algorithm Analysis, and Standard Algorithms Chapter 10 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second.
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Analysis of Algorithms
Computer Science 112 Fundamentals of Programming II
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.
GC 211:Data Structures Algorithm Analysis Tools
Algorithm Analysis and Big Oh Notation
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
GC 211:Data Structures Algorithm Analysis Tools
Algorithm Efficiency Chapter 10.
CS 201 Fundamental Structures of Computer Science
Algorithm Efficiency and Sorting
Analysis of Algorithms
Algorithm Efficiency: Searching and Sorting Algorithms
Algorithm Efficiency Chapter 10
Algorithm Analysis Bina Ramamurthy CSE116A,B.
Algorithm Efficiency and Sorting
Algorithm Analysis and Big Oh Notation
CSE 1342 Programming Concepts
8. Comparison of Algorithms
The Efficiency of Algorithms
Estimating Algorithm Performance
Algorithm Efficiency and Sorting
Analysis of Algorithms
Algorithm Efficiency and Sorting
Algorithm Efficiency and Sorting
Algorithm Efficiency and Sorting
Presentation transcript:

© 2017 Pearson Education, Hoboken, NJ. All rights reserved Algorithm Efficiency Chapter 10 © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

© 2017 Pearson Education, Hoboken, NJ. All rights reserved What Is a Good Solution? A program incurs a real and tangible cost. Computing time Memory required Difficulties encountered by users Consequences of incorrect actions by program A solution is good if … The total cost incurs … Over all phases of its life … is minimal © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

© 2017 Pearson Education, Hoboken, NJ. All rights reserved What Is a Good Solution? Important elements of the solution Good structure Good documentation Efficiency Be concerned with efficiency when Developing underlying algorithm Choice of objects and design of interaction between those objects © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Measuring Efficiency of Algorithms Important because Choice of algorithm has significant impact Examples Responsive word processors Grocery checkout systems Automatic teller machines Video machines Life support systems © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Measuring Efficiency of Algorithms Analysis of algorithms The area of computer science that provides tools for contrasting efficiency of different algorithms Comparison of algorithms should focus on significant differences in efficiency We consider comparisons of algorithms, not programs © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Measuring Efficiency of Algorithms Difficulties with comparing programs (instead of algorithms) How are the algorithms coded What computer will be used What data should the program use Algorithm analysis should be independent of Specific implementations, computers, and data © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

The Execution Time of Algorithms An algorithm’s execution time is related to number of operations it requires. Algorithm’s execution time is related to number of operations it requires. Example: Towers of Hanoi Solution for n disks required 2n – 1 moves If each move requires time m Solution requires (2n – 1)  m time units © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Algorithm Growth Rates Measure an algorithm’s time requirement as function of problem size Most important thing to learn How quickly algorithm’s time requirement grows as a function of problem size Demonstrates contrast in growth rates © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Algorithm Growth Rates FIGURE 10-1 Time requirements as a function of problem size n © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Analysis and Big O Notation Algorithm A is said to be order f (n), Denoted as O( f (n)) Function f(n) called algorithm’s growth rate function Notation with capital O denotes order Algorithm A of order denoted O(f(n)) Constants k and n0 exist such that A requires no more than k  f(n) time units For problem of size n  n0 © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Analysis and Big O Notation FIGURE 10-2 The graphs of 3  n2 and n2 - 3  n + 10 © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Analysis and Big O Notation Order of growth of some common functions © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Analysis and Big O Notation FIGURE 10-3 A comparison of growth-rate functions © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Analysis and Big O Notation FIGURE 10-4 A comparison of growth-rate functions © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Analysis and Big O Notation Worst-case analysis Worst case analysis usually considered Easier to calculate, thus more common Average-case analysis More difficult to perform Must determine relative probabilities of encountering problems of given size © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Keeping Your Perspective ADT used makes a difference Array-based getEntry is O(1) Link-based getEntry is O(n) Choosing implementation of ADT Consider how frequently certain operations will occur Seldom used but critical operations must also be efficient © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Keeping Your Perspective If problem size is always small Possible to ignore algorithm’s efficiency Weigh trade-offs between Algorithm’s time and memory requirements Compare algorithms for style and efficiency © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

Efficiency of Searching Algorithms Sequential search Worst case: O(n) Average case: O(n) Best case: O(1) Binary search O(log2n) in worst case At same time, maintaining array in sorted order requires overhead cost … can be substantial © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

© 2017 Pearson Education, Hoboken, NJ. All rights reserved End Chapter 10 © 2017 Pearson Education, Hoboken, NJ.  All rights reserved