Chapter 9 Efficiency of Algorithms. 9.3 Efficiency of Algorithms.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

Efficiency of Algorithms
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Chapter 1 – Basic Concepts
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
1 ICS 353 Design and Analysis of Algorithms Spring Semester (062) King Fahd University of Petroleum & Minerals Information & Computer Science.
Introduction to Analysis of Algorithms
Efficiency of Algorithms
Complexity Analysis (Part I)
CS107 Introduction to Computer Science
Complexity Analysis (Part I)
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
1 Efficiency of Algorithms. 2  Two main issues related to the efficiency of algorithms:  Speed of algorithm  Efficient memory allocation  We will.
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Solution methods for Discrete Optimization Problems.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Algorithm Analysis (Big O)
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
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
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
Introduction to complexity. 2 Analysis of Algorithms Why do we need to analyze algorithms? –To measure the performance –Comparison of different algorithms.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
{ 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)
Lecture 2 Computational Complexity
Mathematics Review and Asymptotic Notation
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Analysis of Algorithms
Chapter 19: Searching and Sorting Algorithms
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
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.
Algorithm Analysis (Big O)
Algorithm Analysis: Running Time Big O and omega ( 
Searching Topics Sequential Search Binary Search.
1 Chapter 2 Program Performance. 2 Concepts Memory and time complexity of a program Measuring the time complexity using the operation count and step count.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
CS 302 Data Structures Algorithm Efficiency.
Complexity Analysis (Part I)
Analysis of Algorithms
Introduction to complexity
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Computation.
Algorithm Efficiency Chapter 10.
Applied Discrete Mathematics Week 6: Computation
Programming and Data Structure
Chapter 2.
Programming and Data Structure
Algorithm Analysis Bina Ramamurthy CSE116A,B.
David Kauchak cs161 Summer 2009
Complexity Analysis (Part I)
Complexity Analysis (Part I)
Presentation transcript:

Chapter 9 Efficiency of Algorithms

9.3 Efficiency of Algorithms

Two aspects of algorithm efficiency are important: – 1. the amount of time required for execution – 2. amount of memory space needed when it runs. Algorithms are usually analyzed in terms of their best case, worst case, and average. How can the time efficiency of an algorithm be calculated? – Have to factor in the input size to the algorithm – Nature of the input data

Efficiency of Algorithms Because the time efficiency can be influenced by many physical parameters of a computing device, i.e. processor speed, memory size, multi-core, etc., a method of analysis must be used that is not a factor of the processing platform. Evaluation of algorithms can be based on the number of elementary operations required by the algorithm. – Elementary operations are addition, subtraction, multiplication, division and comparison. – All elementary ops are viewed as taking 1 time unit on any system.

Example Consider algorithms A & B designed to accomplish the same task. For input size of n – A requires 10n to 20n elementary operations. – B requires 2n 2 to 4n 2 elementary operations. Which algorithm is more efficient? – for n ≤ 10, 2n 2 < 20n, and hence, B is better – for n > 10, 20n < 2n 2, and in this case A is better The answer is dependent on the size of the input. For a small n B is better, but for a larger inputs A wins. It is important to understand the constraints on the order.

Definition Let A be an algorithm 1.Suppose the number of elementary ops performed when A is executed for an input of size n depends on n alone and not on the nature of the input data; say it equals f(n). If f(n) is Θ(g(n)) then, A is of order g(n). 2.Suppose the number of elementary operations performed when A is executed for an input of size n depends on the nature of the input data as well as on n. 1.Let b(n) be the minimum number of elementary operations required to execute A for all possible input sets of size n. If b(n) is Θ(g(n)), we say A has a best case order of g(n). 2.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 Θ(g(n)), we say A has a worst case order of g(n).

Time Comparisons of Algorithm Orders

Example Consider the following algorithm segment p =0, x=2 for i = 2 to n p = (p + i) * x next I Compute the actual number of elementary ops? – 1 multi, 1 add for each iteration. – 2 ops per iteration. – num of iteration = n – = n-1. – num of elementary ops = 2(n-1) Find an order from among the set of power functions – by theorem on polynomial orders, 2n – 2 is Θ(n) – and thus, segment is Θ(n).

Example Consider a segment with a nested loop (loop inside of a loop) s=0 for i=1 to n for j= 1 to i s=s + j * (i-j+1) next j next i Compute the number of elementary ops. – 2 adds, 1 multi, and 1 minus (4 ops) for each iteration – inside loop (j) iterates i=1 1, i=2 2, i=3 3 … i=n n times – inside loop: … + n = n(n+1)/2 – num of ops = 4 * n(n+1)/2 = 2*n(n+1) = 2n 2 + 2n Find the order among the set of power functions – 2n(n+1) = 2n 2 + 2n is Θ(n 2 ), – hence, segment is Θ(n 2 )

Example Consider the segment where the floor function is used. for i = n/2 to n a = n – I next I Compute the actual number of subtractions performed. – 1 subtraction for each iteration. – loop iterates n - n/2 + 1 times. n is even: n/2 = n/2 n – n/2 + 1 = (2n – n + 2)/2 = (n+2)/2 n is odd: n/2 = (n-1)/2 n – (n-1)/2 + 1 = [2n – (n-1) + 2]/2 = (n+3)/2 Find an order for this segment – (n+2)/2 is Θ(n) and hence, segment is Θ(n)

Sequential Search Sequential search occurs when every element in the list is compared to a particular x until either a match is found or the end of the list.

Example Find the best and worst case orders for sequential search. – Best case: the best case occurs when the first element of the list is the item that is being pursued (searched for). The search takes 1 comparison. Θ(1) – Worst case: the element being searched for is the last element or not in the last (these two situations are equal). The search takes n comparisons. Θ(n)