Comparison of Algorithms Objective: Understand how and why algorithms are compared. Imagine you own a company. You’re trying to buy software to process.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

HL MARKETING THEORY SUPPLY CHAIN MANAGEMENT (LOGISTICS) IB BUSINESS & MANAGEMENT – A COURSE COMPANION, OXFORD 2009, p220.
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
Computational Complexity 1. Time Complexity 2. Space Complexity.
Quick Sort. Quicksort Quicksort is a well-known sorting algorithm developed by C. A. R. Hoare. The quick sort is an in-place, divide- and-conquer, massively.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CS 263.  Classification of algorithm against a model pattern ◦ Each model demonstrate the performance scalability of an algorithm  Sorting algorithms.
Embedded vs. PC Application Programming. Overview  The software design cycle  Designing differences  Code differences  Test differences.
Introduction to Analysis of Algorithms
CS107 Introduction to Computer Science
Cmpt-225 Algorithm Efficiency.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Chapter 4 Assessing and Understanding Performance
Concept of Basic Time Complexity Problem size (Input size) Time complexity analysis.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Elementary Data Structures and Algorithms
Algorithm Analysis (Big O)
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
BIT Presentation 4.  An algorithm is a method for solving a class of problems.  While computer scientists think a lot about algorithms, the term.
COMPSCI 102 Introduction to Discrete Mathematics.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Program Performance & Asymptotic Notations CSE, POSTECH.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
1 Growth of Functions CS 202 Epp, section ??? Aaron Bloomfield.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Analysis of Algorithms
What have mr aldred’s dirty clothes got to do with the cpu
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
Growth of Functions. Asymptotic Analysis for Algorithms T(n) = the maximum number of steps taken by an algorithm for any input of size n (worst-case runtime)
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
1 CS/EE 362 Hardware Fundamentals Lecture 9 (Chapter 2: Hennessy and Patterson) Winter Quarter 1998 Chris Myers.
Hardware. Make sure you have paper and pen to hand as you will need to take notes and write down answers and thoughts that you can refer to later on.
Complexity of Algorithms
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Lauren Milne Summer 2015.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Nicki Dell Spring 2014.
CS 2601 Runtime Analysis Big O, Θ, some simple sums. (see section 1.2 for motivation) Notes, examples and code adapted from Data Structures and Other Objects.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CSE 373: Data Structures and Algorithms
September 10 Performance Read 3.1 through 3.4 for Wednesday Only 3 classes before 1 st Exam!
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Algorithm Analysis Lakshmish Ramaswamy. What Constitutes Good Software? Code correctness Good design Code reusability OO design can help us in achieving.
1 The Role of Algorithms in Computing. 2 Computational problems A computational problem specifies an input-output relationship  What does the.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
1 Potential for Parallel Computation Chapter 2 – Part 2 Jordan & Alaghband.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Winter 2015.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Algorithm Analysis 1.
CMPT 438 Algorithms.
Introduction to Algorithms
Introduction to Analysis of Algorithms
September 2 Performance Read 3.1 through 3.4 for Tuesday
Analysis of Algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
CS2100 Computer Organisation
Introduction to Data Structures
Big O Notation.
CSE 373 Data Structures and Algorithms
Introduction to Algorithms
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
CSE 373: Data Structures and Algorithms
Presentation transcript:

Comparison of Algorithms Objective: Understand how and why algorithms are compared. Imagine you own a company. You’re trying to buy software to process customer orders You meet Mr. Smith and Mr. Jones. They both sell order processing software: Smith Jones

Is it worth the extra $$$? Smith’s software uses an algorithm that processes each order in 3 seconds. But takes 30 seconds to start up Jones’s algorithm also processes each order in 3 seconds and has no start up time but costs $1000 more

Probably Not! Especially if you process hundreds of orders at a time. In general, algorithm A is not considered superior to algorithm B if all it can boast that it takes a fixed amount less time. For example, 5 minutes faster, 8 fewer operations, etc.

Is Smith’s new algorithm worth it? Smith improves his algorithm so there is no start up time and it takes 2 seconds/order. But now his costs $1000 more Jones’s algorithm still takes 3 seconds/order. He points out that a computer that is 50% faster only costs $500 more!

No it’s not… In general, algorithm A is not considered superior to algorithm B even if it can boast that it takes a fraction of the time. –For example half the time, one third the number of operations, etc. –Because run times are dependant on the way a compiler translate code, processor speeds etc. –A faster processor could take half the time, a faster compiler could take 1/3 the operations.

Some Time Later… Now suppose your order processing needs become much more complicated. –The old software you bought from Jones is no longer sufficient –You go back to Smith and Jones

Now whose do you buy? The best Smith can do is a minute an order. To process 300 orders will take 5 hours! Jones’s takes N 2 seconds where N is the number of orders. I.e. 1 second for 1 order, 4 seconds for 2 orders, 9 seconds for 3.

Compare! Number of Orders 1010 Minutes1½ Mins. 601 Hour 1202 Hours4 Hours 1803 Hours9 Hours 3005 Hours25 Hours

Jones’s algorithm is only better for small numbers Although Smith’s algorithm performs poorly for small numbers, it grows much more slowly than Jones’s How quickly an algorithm’s runtime grows is independent of : –What type of computer it runs on –What compiler is used –How much time it takes to set up.

Therefore… When we compare algorithm A and algorithm B, we conclude that algorithm A is more efficient only if its runtime grows more slowly than algorithm B as the size of the input grows. The growth of an algorithm’s run time is usually expressed in terms of “N”, the number of inputs. For example: –N 2, the square of the number of inputs –LogN, the logarithm of the number of inputs.

Why? How long an algorithm takes to set up, or how quickly it runs is not necessarily a property of the algorithm. –Affected by speed of the computer –Affected by efficiency of the compiler The growth of the runtime as the input grows is a property of the algorithm. –Unaffected by the speed of the computer –Unaffected by the efficiency of the compiler –There is no computer fast enough to make an algorithm that takes N 2 steps look like one that takes N steps

Some Examples Two algorithms: –One takes N 3 time –One takes 400N 2 time –Second is more efficient. It grows more slowly Two algorithms –One always takes seconds –One takes 2N seconds –First is more efficient – Grows more slowly

Some Examples cont’d Two algorithms: –One takes 3N time –One takes 100N time –These are considered similar –Could get the same improvement with a better compiler or a faster computer –I.e. the difference is not necessarily a characteristic of the algorithm

Summary A fixed amount of extra setup time (e.g. N+100 vs. N+200) is not enough to make an algorithm considered to be more efficient Run time multiplied by a smaller constant (e.g. 2N vs. 10N) is also not enough to make an algorithm considered to be more efficient. For an algorithm to be considered more efficient, its runtime must grow more slowly (e.g. N 2 vs. N 3 )