Analysis of Algorithms II

Slides:



Advertisements
Similar presentations
Analysys & Complexity of Algorithms Big Oh Notation.
Advertisements

Chapter 1 – Basic Concepts
Chapter 3 Growth of Functions
Big-O and Friends. Formal definition of Big-O A function f(n) is O(g(n)) if there exist positive numbers c and N such that: f(n) = N Example: Let f(n)
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
20-Jun-15 Analysis of Algorithms II. 2 Basics Before we attempt to analyze an algorithm, we need to define two things: How we measure the size of the.
Algorithmic Complexity 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Cmpt-225 Algorithm Efficiency.
The Efficiency of Algorithms
The Efficiency of Algorithms
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Elementary Data Structures and Algorithms
CS2336: Computer Science II
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
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.
Analysis CS 367 – Introduction to Data Structures.
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Lecture 2 Computational Complexity
Coursenotes CS3114: Data Structures and Algorithms Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright ©
Asymptotic Notation (O, Ω, )
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
Algorithm Analysis Part of slides are borrowed from UST.
Asymptotic Notations By Er. Devdutt Baresary. Introduction In mathematics, computer science, and related fields, big O notation describes the limiting.
Algorithm Analysis (Big O)
Scalability for Search Scaling means how a system must grow if resources or work grows –Scalability is the ability of a system, network, or process, to.
David Meredith Growth of Functions David Meredith
Algorithm Complexity L. Grewe 1. Algorithm Efficiency There are often many approaches (algorithms) to solve a problem. How do we choose between them?
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
21-Feb-16 Analysis of Algorithms II. 2 Basics Before we attempt to analyze an algorithm, we need to define two things: How we measure the size of the.
Introduction to Algorithms Book by Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest and Clifford Stein Powerpoint by Michael Block.
Computational complexity The same problem can frequently be solved with different algorithms which differ in efficiency. Computational complexity is a.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Design and Analysis of Algorithms
Introduction to Analysis of Algorithms
Analysis of Algorithms
Scalability for Search
Analysis of Algorithms
Asymptotic Analysis.
Introduction to Algorithms
Big-O notation.
Growth of functions CSC317.
Teach A level Computing: Algorithms and Data Structures
Algorithm Analysis (not included in any exams!)
O-notation (upper bound)
Asymptotic Notations Algorithms Lecture 9.
Foundations II: Data Structures and Algorithms
Asymptotes: Why? How to describe an algorithm’s running time?
Introduction to Algorithms Analysis
Asymptotic Analysis.
Analysys & Complexity of Algorithms
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Analysis of Algorithms
Analysis of Algorithms II
CS200: Algorithms Analysis
Searching, Sorting, and Asymptotic Complexity
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
Presentation transcript:

Analysis of Algorithms II 22-Feb-19

Basics Before we attempt to analyze an algorithm, we need to define two things: How we measure the size of the input How we measure the time (or space) requirements Once we have done this, we find an equation that describes the time (or space) requirements in terms of the size of the input We simplify the equation by discarding constants and discarding all but the fastest-growing term

Size of the input Usually it’s quite easy to define the size of the input If we are sorting an array, it’s the size of the array If we are computing n!, the number n is the “size” of the problem Sometimes more than one number is required If we are trying to pack objects into boxes, the results might depend on both the number of objects and the number of boxes Sometimes it’s very hard to define “size of the input” Consider: f(n) = if n is 1, then 1; else if n is even, then f(n/2); else f(3*n + 1) The obvious measure of size, n, is not actually a very good measure To see this, compute f(7) and f(8)

Measuring requirements If we want to know how much time or space an algorithm takes, we can do empirical tests—run the algorithm over different sizes of input, and measure the results This is not analysis However, empirical testing is useful as a check on analysis Analysis means figuring out the time or space requirements Measuring space is usually straightforward Look at the sizes of the data structures Measuring time is usually done by counting characteristic operations Characteristic operation is a difficult term to define In any algorithm, there is some code that is executed the most times This is in an innermost loop, or a deepest recursion This code requires “constant time” (time bounded by a constant) Example: Counting the comparisons needed in an array search

Big-O and friends Informal definitions: Given a complexity function f(n), (f(n)) is the set of complexity functions that are lower bounds on f(n) O(f(n)) is the set of complexity functions that are upper bounds on f(n) (f(n)) is the set of complexity functions that, given the correct constants, correctly describes f(n) Example: If f(n) = 17x3 + 4x – 12, then (f(n)) contains 1, x, x2, log x, x log x, etc. O(f(n)) contains x4, x5, 2x, etc. (f(n)) contains x3

Formal definition of Big-O* A function f(n) is O(g(n)) if there exist positive constants c and N such that, for all n > N, 0 < f(n) < cg(n) That is, if n is big enough (larger than N—we don’t care about small problems), then cg(n) will be bigger than f(n) Example: 5x2 + 6 is O(n3) because 0 < 5n2 + 6 < 2n3 whenever n > 3 (c = 2, N = 3) We could just as well use c = 1, N = 6, or c = 50, N = 50 Of course, 5x2 + 6 is also O(n4), O(2n), and even O(n2)

Formal definition of Big-* A function f(n) is (g(n)) if there exist positive constants c and N such that, for all n > N, 0 < cg(n) < f(n) That is, if n is big enough (larger than N—we don’t care about small problems), then cg(n) will be smaller than f(n) Example: 5x2 + 6 is (n) because 0 < 20n < 5n2 + 6 whenever n > 4 (c=20, N=4) We could just as well use c = 50, N = 50 Of course, 5x2 + 6 is also O(log n), O(n), and even O(n2)

Formal definition of Big-* A function f(n) is (g(n)) if there exist positive constants c1 and c2 and N such that, for all n > N, 0 < c1g(n) < f(n) < c2g(n) That is, if n is big enough (larger than N), then c1g(n) will be smaller than f(n) and c2g(n) will be larger than f(n) In a sense,  is the “best” complexity of f(n) Example: 5x2 + 6 is (n2) because n2 < 5n2 + 6 < 6n2 whenever n > 5 (c1 = 1, c2 = 6)

Graphs Points to notice: f(n) cg(n) f(n) is O(g(n)) N f(n) cg(n) f(n) is (g(n)) N f(n) c2g(n) c1g(n) f(n) is (g(n)) N Points to notice: What happens near the beginning (n < N) is not important cg(n) always passes through 0, but f(n) might not (why?) In the third diagram, c1g(n) and c2g(n) have the same “shape” (why?)

Informal review For any function f(n), and large enough values of n, f(n) = O(g(n)) if cg(n) is greater than f(n), f(n) = theta(g(n)) if c1g(n) is greater than f(n) and c2g(n) is less than f(n), f(n) = omega(g(n)) if cg(n) is less than f(n), ...for suitably chosen values of c, c1, and c2

The End The formal definitions were taken, with some slight modifications, from Introduction to Algorithms, by Thomas H. Cormen, Charles E. Leiserson, Donald L. Rivest, and Clifford Stein