1 Efficiency of Algorithms. 2  Two main issues related to the efficiency of algorithms:  Speed of algorithm  Efficient memory allocation  We will.

Slides:



Advertisements
Similar presentations
Efficiency of Algorithms
Advertisements

1 Chapter 15.3 Hamilton Paths and Hamilton Circuits Objectives 1.Understand the definitions of Hamilton paths & Hamilton circuits. 2.Find the number of.
CHAPTER 1 Compiled by: Dr. Mohammad Omar Alhawarat Algorithm’s Analysis.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Hardness Results for Problems P: Class of “easy to solve” problems Absolute hardness results Relative hardness results –Reduction technique.
Introduction to Analysis of Algorithms
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 21 Instructor: Paul Beame.
Complexity Analysis (Part I)
CS107 Introduction to Computer Science
Complexity Analysis (Part I)
CSE 830: Design and Theory of Algorithms
CSE 830: Design and Theory of Algorithms Dr. Eric Torng.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
Lecture 7 CSE 331 Sep 16, Feedback forms VOLUNTARY Last 5 mins of the lecture.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Asymptotic Analysis Motivation Definitions Common complexity functions
TTIT33 Algorithms and Optimization – Lecture 1 Jan Maluszynski - HT Analysis of Algorithms Introductory Example Principles of Analysis Big-Oh notation.
1 Algorithms and Analysis CS 2308 Foundations of CS II.
Network Optimization Problems: Models and Algorithms
Solution methods for Discrete Optimization Problems.
Algorithm Analysis and Big Oh Notation Courtesy of Prof. Ajay Gupta (with updates by Dr. Leszek T. Lilien) CS 1120 – Fall 2006 Department of Computer Science.
Lecture 2: Algorithm Complexity. Recursion A subroutine which calls itself, with different parameters. Need to evaluate factorial(n) factorial(n) = n.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
Ch. 11: Optimization and Search Stephen Marsland, Machine Learning: An Algorithmic Perspective. CRC 2009 some slides from Stephen Marsland, some images.
CS-2852 Data Structures LECTURE 3A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
Programming & Data Structures
Algorithms for Network Optimization Problems This handout: Minimum Spanning Tree Problem Approximation Algorithms Traveling Salesman Problem.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
The Growth of Functions Rosen 2.2 Basic Rules of Logarithms log z (xy) log z (x/y) log z (x y ) If x = y If x < y log z (-|x|) is undefined = log z (x)
Graph Theory Hamilton Paths and Hamilton Circuits.
Analysis of Algorithms
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
© 2010 Pearson Prentice Hall. All rights reserved. 1 §15.3, Hamilton Paths and Circuits.
© 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.
CSS342: Algorithm Analysis1 Professor: Munehiro Fukuda.
Excursions in Modern Mathematics, 7e: Copyright © 2010 Pearson Education, Inc. 6 The Mathematics of Touring 6.1Hamilton Paths and Hamilton Circuits.
Introduction to Analysis of Algorithms COMP171 Fall 2005.
What is an algorithm? Algorithms are the ideas behind computer programs. An algorithm is the thing which stays the same whether the program is in Pascal.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Metaheuristic – Threshold Acceptance (TA). 2 Outlines ▪ Measuring Computational Efficiency ▪ Construction Heuristics ▪ Local Search Algorithms ▪ Metaheuristic.
Algorithm Efficiency and Sorting Data Structure & Algorithm.
Algorithm Analysis Data Structures and Algorithms (60-254)
Traveling Salesman Problem (TSP)
Chapter 9 Efficiency of Algorithms. 9.3 Efficiency of Algorithms.
2-0 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 2 Theoretical.
Computer Science Background for Biologists CSC 487/687 Computing for Bioinformatics Fall 2005.
CSE 373: Data Structures and Algorithms
Computer Science/Ch. Algorithmic Foundation of CS 4-1 Chapter 4 Chapter 4 Algorithmic Foundation of Computer Science.
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.
Management Science 461 Lecture 7 – Routing (TSP) October 28, 2008.
Copyright © 2014 Curt Hill Algorithm Analysis How Do We Determine the Complexity of Algorithms.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Mathematical modeling To describe or represent a real-world situation quantitatively, in mathematical language.
Exhaustive search Exhaustive search is simply a brute- force approach to combinatorial problems. It suggests generating each and every element of the problem.
Complexity Analysis (Part I)
Analysis of Algorithms
3. Brute Force Selection sort Brute-Force string matching
3. Brute Force Selection sort Brute-Force string matching
Hamilton Paths and Hamilton Circuits
Complexity Analysis (Part I)
Complexity Analysis (Part I)
3. Brute Force Selection sort Brute-Force string matching
Presentation transcript:

1 Efficiency of Algorithms

2  Two main issues related to the efficiency of algorithms:  Speed of algorithm  Efficient memory allocation  We will focus on the speed of algorithms. The speed of an algorithm (running time) is determined by the number of elementary operations: addition, subtraction, multiplication, division, comparison. The number of elementary operations depends on  problem size  nature of input data

3 Analysis of Running Time  Running time of an algorithm is a function of input size.  Two kind of analyses of running time:  Worst-case running time analysis  Average-case running time analysis Most results in the analysis of algorithms concern the worst-case running time.

4 Efficiency of Algorithms: Example Traveling Salesman Problem (TSP)  Recall the Traveling Salesman Problem (TSP) : There are n cities. The salesman  starts his tour from City 1,  visits each of the cities exactly once,  and returns to City 1. For each pair of cities i,j there is a cost c ij associated with traveling from City i to City j. Goal: Find a minimum-cost tour.

5 “Exhaustive enumeration” algorithm  One way of solving the problem is by an algorithm which is based on exhaustive enumeration (brute force): 1) Compute the costs of all possible tours; 2) Choose the tour with minimum cost.  What is the running time of this algorithm? 1)  The number of possible tours is (n-1)!  The cost of each tour is the sum of n individual costs  requires n-1 additions.  Thus, computing the costs of all possible tours requires (n-1)∙(n-1)! elementary operations. 2) Choosing the tour with minimum cost requires (n-1)!-1 comparisons. Summarizing, (n-1)∙(n-1)! + (n-1)! -1 = n! -1 elementary operations are needed for implementing the algorithm.

6 Efficiency of the “Exhaustive enumeration” algorithm Is the “exhaustive enumeration” algorithm efficient? Assume that each elementary operation can be done in 1 nanosecond = seconds. Then the running time: n=10n=20n= sec77 years 8.4  centuries

7 “Nearest neighbor” algorithm  Consider another method for solving the TSP, the “Nearest neighbor” algorithm: In every iteration (except the last one) go to the closest city not visited yet.  What is the running time of this algorithm?  In each iteration we choose one of the n cities; so there are n iterations.  In each iteration, we need at most n comparisons to choose the next city. Thus, the total number of elementary operations is at most n 2.

8 Efficiency of the “Nearest Neighbor” algorithm Compare the running times of “Nearest neighbor” and “Exhaustive enumeration” algorithms: Note: The “Nearest Neighbor” algorithm might not return an optimal solution. n=10n=30n=100n=1000 n2n sec sec sec sec. n!0.004 sec 8.4  cent.

9 Bad case example for Bad case example for the “Nearest Neighbor” algorithm Output of the “Nearest neighbor” algorithm Optimal solution

10 Overwhelming terms in running times Suppose in the “Exhaustive enumeration” algorithm, we need to preprocess the costs before applying the main routine (e.g., converting kilometers to miles). Preprocessing requires at most n 2 multiplications; thus, the running time of the new algorithm is n!+n 2. For large n, the term n! overwhelms the term n 2. Thus, the running time n!+n 2 qualitatively is not much different from n!.

11 Order of an Algorithm  Definition: Let A be an algorithm. Let w(n) be the maximum number of elementary operations required to execute A for all possible input sets of size n. If w(n) is O(f(n)), we say that A has a (worst case) order of f(n).  Ex.: Suppose the maximum number of operations needed to execute algorithm A is 5n 2 +3n+7. Then A has an order of n 2.  Definition: An algorithm is called polynomial-time if it has an order of f(n)=n k for some constant k.  Polynomial-time algorithms are normally considered efficient.

Time comparisons of the most common algorithm orders f(n)n=10n=1000n=10 5 n=10 7 log 2 n 3.3  sec sec. 1.7  sec.2.3  sec. n sec sec sec.0.01 sec. n∙ log 2 n 3.3  sec sec sec.0.23 sec. n2n sec sec.10 sec.27.8 min. n3n sec.1 sec.11.6 min.317 cent. 2n2n sec. 3.4  years 3.2  years 3.1  years