2.1 Computational Tractability. 2 Computational Tractability Charles Babbage (1864) As soon as an Analytic Engine exists, it will necessarily guide the.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
Time Analysis Since the time it takes to execute an algorithm usually depends on the size of the input, we express the algorithm's time complexity as a.
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Chapter 10 Algorithm Efficiency
Introduction to Analysis of Algorithms
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Runtime Analysis CSC 172 SPRING 2002 LECTURE 9 RUNNING TIME A program or algorithm has running time T(n), where n is the measure of the size of the input.
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Data Structure Algorithm Analysis TA: Abbas Sarraf
The Complexity of Algorithms and the Lower Bounds of Problems
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Chapter 6 Algorithm Analysis Bernard Chen Spring 2006.
COMPSCI 102 Introduction to Discrete Mathematics.
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
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
2.1 Computational Tractability
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
Complexity Analysis Chapter 1.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 4.
Complexity & Analysis of Data Structures & Algorithms Piyush Kumar (Lecture 2: Algorithmic Analysis) Welcome to COP4531 Based on slides from J. Edmonds,
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Asymptotic Analysis-Ch. 3
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
Introduction to Analysis of Algorithms COMP171 Fall 2005.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
MS 101: Algorithms Instructor Neelima Gupta
Lecture 3 Analysis of Algorithms, Part II. Plan for today Finish Big Oh, more motivation and examples, do some limit calculations. Little Oh, Theta notation.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
CSCI 256 Data Structures and Algorithm Analysis Lecture 3 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Asymptotic Growth Rates  Themes  Analyzing the cost of programs  Ignoring constants and Big-Oh  Recurrence Relations & Sums  Divide and Conquer 
Time Complexity of Algorithms
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
Big-O. Algorithm Analysis Exact analysis: produce a function f(n) measuring how many basic steps are needed for a given inputs n On any input of size.
Chapter 2 Computational Complexity. Computational Complexity Compares growth of two functions Independent of constant multipliers and lower-order effects.
Algorithm Analysis Chapter 5. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. –recipes –directions.
CSC 430: Basics of Algorithm Runtime Analysis 1. What is Runtime Analysis? Fundamentally, it is the process of counting the number of “steps” it takes.
Asymptotic Analysis CSE 331. Definition of Efficiency An algorithm is efficient if, when implemented, it runs quickly on real instances Implemented where?
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
 2007 Pearson Education, Inc. All rights reserved Sorting: A Deeper Look.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
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.
Lecture 3COMPSCI.220.S1.T Running Time: Estimation Rules Running time is proportional to the most significant term in T(n) Once a problem size.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
CMPT 438 Algorithms.
Chapter 2 Algorithm Analysis
Theoretical analysis of time efficiency
Analysis of Algorithmic Efficiency
Chapter 2 Basics of Algorithm Analysis
Complexity & Analysis of Data Structures & Algorithms
Chapter 2.
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Chapter 2 Basics of Algorithm Analysis
Presentation transcript:

2.1 Computational Tractability

2 Computational Tractability Charles Babbage (1864) As soon as an Analytic Engine exists, it will necessarily guide the future course of the science. Whenever any result is sought by its aid, the question will arise - By what course of calculation can these results be arrived at by the machine in the shortest time? - Charles Babbage Analytic Engine (schematic)

3 Polynomial-Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that checks every possible solution. n Typically takes 2 N time or worse for inputs of size N. n Unacceptable in practice. Desirable scaling property. When the input size doubles, the algorithm should only slow down by some constant factor C. Def. An algorithm is poly-time if the above scaling property holds. There exists constants c > 0 and d > 0 such that on every input of size N, its running time is bounded by c N d steps. choose C = 2 d n ! for stable matching with n men and n women

4 Worst-Case Analysis Worst case running time. Obtain bound on largest possible running time of algorithm on input of a given size N. n Generally captures efficiency in practice. n Draconian view, but hard to find effective alternative. Average case running time. Obtain bound on running time of algorithm on random input as a function of input size N. n Hard (or impossible) to accurately model real instances by random distributions. n Algorithm tuned for a certain distribution may perform poorly on other inputs.

5 Worst-Case Polynomial-Time Def. An algorithm is efficient if its running time is polynomial. Justification: It really works in practice! n Although 6.02   N 20 is technically poly-time, it would be useless in practice. n In practice, the poly-time algorithms that people develop almost always have low constants and low exponents. n Breaking through the exponential barrier of brute force typically exposes some crucial structure of the problem. Exceptions. n Some poly-time algorithms do have high constants and/or exponents, and are useless in practice. n Some exponential-time (or worse) algorithms are widely used because the worst-case instances seem to be rare. simplex method Unix grep

6 Why It Matters

2.2 Asymptotic Order of Growth

8 Asymptotic Order of Growth Upper bounds. T(n) is O(f(n)) if there exist constants c > 0 and n 0  0 such that for all n  n 0 we have T(n)  c · f(n). Lower bounds. T(n) is  (f(n)) if there exist constants c > 0 and n 0  0 such that for all n  n 0 we have T(n)  c · f(n). Tight bounds. T(n) is  (f(n)) if T(n) is both O(f(n)) and  (f(n)). Ex: T(n) = 32n n n T(n) is O(n 2 ), O(n 3 ),  (n 2 ),  (n), and  (n 2 ). n T(n) is not O(n),  (n 3 ),  (n), or  (n 3 ).

9 Notation Slight abuse of notation. T(n) = O(f(n)). n Asymmetric: – f(n) = 5n 3 ; g(n) = 3n 2 – f(n) = O(n 3 ) = g(n) – but f(n)  g(n). n Better notation: T(n)  O(f(n)). Meaningless statement. Any comparison-based sorting algorithm requires at least O(n log n) comparisons. n Statement doesn't "type-check." n Use  for lower bounds.

10 Properties Transitivity. n If f  O(g) and g  O(h) then f  O(h). n If f   (g) and g   (h) then f   (h). n If f   (g) and g   (h) then f   (h). Additivity. n If f  O(h) and g  O(h) then f + g  O(h). n If f   (h) and g   (h) then f + g   (h). n If f   (h) and g  O(h) then f + g   (h).

11 Asymptotic Bounds for Some Common Functions Polynomials. a 0 + a 1 n + … + a d n d is  (n d ) if a d > 0. Polynomial time. Running time is O(n d ) for some constant d independent of the input size n. Logarithms. O(log a n) = O(log b n) for any constants a, b > 0. Logarithms. For every x > 0, log n  O(n x ). Exponentials. For every r > 1 and every d > 0, n d  O(r n ). every exponential grows faster than every polynomial can avoid specifying the base log grows slower than every polynomial

2.4 A Survey of Common Running Times

13 Linear Time: O(n) Linear time. Running time is at most a constant factor times the size of the input. Computing the maximum. Compute maximum of n numbers a 1, …, a n. max  a 1 for i = 2 to n { if (a i > max) max  a i }

14 Linear Time: O(n) Merge. Combine two sorted lists A = a 1,a 2,…,a n with B = b 1,b 2,…,b n into sorted whole. Claim. Merging two lists of size n takes O(n) time. Pf. After each comparison, the length of output list increases by 1. i = 1, j = 1 while (both lists are nonempty) { if (a i  b j ) append a i to output list and increment i else(a i  b j )append b j to output list and increment j } append remainder of nonempty list to output list

15 O(n log n) Time O(n log n) time. Arises in divide-and-conquer algorithms. Sorting. Mergesort and heapsort are sorting algorithms that perform O(n log n) comparisons. Largest empty interval. Given n time-stamps x 1, …, x n on which copies of a file arrive at a server, what is largest interval of time when no copies of the file arrive? O(n log n) solution. Sort the time-stamps. Scan the sorted list in order, identifying the maximum gap between successive time-stamps. also referred to as linearithmic time

16 Quadratic Time: O(n 2 ) Quadratic time. Enumerate all pairs of elements. Closest pair of points. Given a list of n points in the plane (x 1, y 1 ), …, (x n, y n ), find the pair that is closest. O(n 2 ) solution. Try all pairs of points. Remark.  (n 2 ) seems inevitable, but this is just an illusion. min  (x 1 - x 2 ) 2 + (y 1 - y 2 ) 2 for i = 1 to n { for j = i+1 to n { d  (x i - x j ) 2 + (y i - y j ) 2 if (d < min) min  d } don't need to take square roots see chapter 5

17 Cubic Time: O(n 3 ) Cubic time. Enumerate all triples of elements. Set disjointness. Given n sets S 1, …, S n each of which is a subset of 1, 2, …, n, is there some pair of these which are disjoint? O(n 3 ) solution. For each pairs of sets, determine if they are disjoint. foreach set S i { foreach other set S j { foreach element p of S i { determine whether p also belongs to S j } if (no element of S i belongs to S j ) report that S i and S j are disjoint }

18 Polynomial Time: O(n k ) Time Independent set of size k. Given a graph, are there k nodes such that no two are joined by an edge? O(n k ) solution. Enumerate all subsets of k nodes. n Check whether S is an independent set = O(k 2 ). n Number of k element subsets = n O(k 2 n k / k!) = O(n k ). foreach subset S of k nodes { check whether S in an independent set if (S is an independent set) report S is an independent set } poly-time for k=17, but not practical k is a constant

19 Exponential Time Independent set. Given a graph, what is maximum size of an independent set? O(n 2 2 n ) solution. Enumerate all subsets. S*   foreach subset S of nodes { check whether S in an independent set if (S is largest independent set seen so far) update S*  S }