Computational complexity and some Graph Theory

Similar documents
CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms

Time-bounded computations

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

P, NP, NP-Complete, and NPhard

CSE525: Randomized Algorithms and Probabilistic Analysis April 2, Lecture 1

Growth of Functions (CLRS 2.3,3)

Complexity Theory Part I

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms

The Growth of Functions. A Practical Introduction with as Little Theory as possible

Data Structures and Algorithms. Asymptotic notation

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

An introduction to parallel algorithms

Enumerate all possible assignments and take the An algorithm is a well-defined computational

Theory of Computation

This chapter covers asymptotic analysis of function growth and big-o notation.

Notes for Lecture Notes 2

Asymptotic Analysis. Thomas A. Anastasio. January 7, 2004

Algorithm efficiency can be measured in terms of: Time Space Other resources such as processors, network packets, etc.

Runtime Complexity. CS 331: Data Structures and Algorithms

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2

Big , and Definition Definition

Introduction to Algorithms

NP-Completeness Review

Topic 17. Analysis of Algorithms

Lecture 1 - Preliminaries

Lecture 10: Big-Oh. Doina Precup With many thanks to Prakash Panagaden and Mathieu Blanchette. January 27, 2014

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Defining Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 421: Intro Algorithms. Summer 2007 Larry Ruzzo

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

Cpt S 223. School of EECS, WSU

MATH 22 FUNCTIONS: ORDER OF GROWTH. Lecture O: 10/21/2003. The old order changeth, yielding place to new. Tennyson, Idylls of the King

Measuring Goodness of an Algorithm. Asymptotic Analysis of Algorithms. Measuring Efficiency of an Algorithm. Algorithm and Data Structure

Ch 01. Analysis of Algorithms

Essential facts about NP-completeness:

Lecture 25: Cook s Theorem (1997) Steven Skiena. skiena

Boolean circuits. Lecture Definitions

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N,

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Define Efficiency. 2: Analysis. Efficiency. Measuring efficiency. CSE 417: Algorithms and Computational Complexity. Winter 2007 Larry Ruzzo

The Complexity of Optimization Problems

Introduction. How can we say that one algorithm performs better than another? Quantify the resources required to execute:

Great Theoretical Ideas in Computer Science. Lecture 7: Introduction to Computational Complexity

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Computational Complexity

1 Reals are Uncountable

1 Computational Problems

Introduction. An Introduction to Algorithms and Data Structures

2. ALGORITHM ANALYSIS

Lecture 7: The Satisfiability Problem

Class Note #20. In today s class, the following four concepts were introduced: decision

Ch01. Analysis of Algorithms

Computational Complexity for Algebraists

An analogy from Calculus: limits

PAC Learning. prof. dr Arno Siebes. Algorithmic Data Analysis Group Department of Information and Computing Sciences Universiteit Utrecht

Advanced topic: Space complexity

Lecture 3. 1 Polynomial-time algorithms for the maximum flow problem

Analysis of Algorithms

csci 210: Data Structures Program Analysis

Great Theoretical Ideas in Computer Science. Lecture 9: Introduction to Computational Complexity

2 How many distinct elements are in a stream?

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Circuits. Lecture 11 Uniform Circuit Complexity

Analysis of Algorithms

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes

Computer Science 431 Algorithms The College of Saint Rose Spring Topic Notes: Analysis Fundamentals

Universal Algebra and Computational Complexity Lecture 1

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Running Time Evaluation

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

1 Reductions and Expressiveness

csci 210: Data Structures Program Analysis

Data Structures and Algorithms Running time and growth functions January 18, 2018

Lecture 4. 1 Circuit Complexity. Notes on Complexity Theory: Fall 2005 Last updated: September, Jonathan Katz

Space Complexity of Algorithms

CSE 373: Data Structures and Algorithms. Asymptotic Analysis. Autumn Shrirang (Shri) Mare

Lecture 6: Introducing Complexity

Lecture 2. More Algorithm Analysis, Math and MCSS By: Sarah Buchanan

Problem-Solving via Search Lecture 3

Time Complexity (1) CSCI Spring Original Slides were written by Dr. Frederick W Maier. CSCI 2670 Time Complexity (1)

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

COMP 355 Advanced Algorithms

Theory of Computation

Data Structures and Algorithms

COMPUTATIONAL COMPLEXITY

Lecture Space Bounded and Random Turing Machines and RL

Lecture 22: Quantum computational complexity

COLLEGE ALGEBRA. Paul Dawkins

Matrix Multiplication

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background

Principles of Algorithm Analysis

Complexity of Matrix Multiplication and Bilinear Problems

Introduction to Machine Learning

Elliptic Curves Spring 2013 Lecture #3 02/12/2013

Lecture 29: Tractable and Intractable Problems

Transcription:

Graph Theory Lars Hellström January 22, 2014

Contents of todays lecture

An important concern when choosing the algorithm to use for something (after basic requirements such as correctness and stability) is the amount of various resources that the algorithm will require. The most important resources are: work How many primitive operations would it take to carry out the algorithm? time How long time would it take to execute the algorithm? space How much memory would the algorithm need to use? energy How much energy is required to run the algorithm? (Emerging concern!) In the classical single processor setting, time and work are pretty much the same, so one often speaks of time (or just ) when discussing the amount of work. Parallel processing is growing in importance, but considering it is still viewed as luxury.

What is asymptotic? The resource requirements of an algorithm depend on what input data is is given. Predicting the exact resource requirements is seldom feasible, but it is often possible to give useful bounds for them. The main parameter in terms of which such bounds are stated is the size of the input, i.e., the number of bits that would be required to encode the input. If n is the input size and f (n) is some bound on a resource, then the asymptotic of that resource is the asymptotic behaviour of the function f (n) as n.

The main workhorse in describing asymptotic behaviour is the big O notation: f (n) = O ( g(n) ) (read f (n) is O of g(n) ) means there exists positive constants M and N such that f (n) M g(n) for all n > N. (Note the abuse of =, which should really be an.) If g(n) is nonzero for sufficiently large n, the above is equivalent to lim sup n f (n) g(n) <.

Big O is a way of ignoring constant factors (which anyway depend on what units one uses): Cg(n) = O ( g(n) ) for all g. Big O also lets one ignore lower order terms: f (n) = O ( g(n) ) = g(n) + f (n) = O ( g(n) ). Big O is multiplicative: if f 1 (n) = O ( g 1 (n) ) and f 2 (n) = O ( g 2 (n) ) then f 1 (n)f 2 (n) = O ( g 1 (n)g 2 (n) )

Big O simplification Finding the big O notation of a function f (x) is usually done using the following two rules: If f (x) is a sum of more than one term, keep only the one which grows the fastest. If f (x) is a product of more than one factor, remove any constant factor (doesn t depend on x).

Big O example We consider the function: If n is large then f (n) = 10 log 2 (n)n + 3n 2 + log 2 (n) 3n 2 > 10 log 2 (n)n > log 2 (n), so we keep only the second term 3n 2. Next we remove the constant term ending up with: f (n) = O(n 2 )

Big O hierarchy For any a > 1 and p R, n p = O(a n ) but a n O(n p ). For all p, q R such that p < q, n p = O(n q ) but n q O(n p ). For any a, p > 0, log a n = O(n p ) but n p O(log a n). In particular, O(log a n) is the same for all bases a, so the logarithm base is typically omitted inside a big O. O(1) is the class of all (asymptotically) bounded functions.

Example: Matrix addition Input: Two n n matrices A and B. Output: The matrix C = A + B. for i from 1 to n do for j from 1 to n do C i,j := A i,j + B i,j ; endfor endfor j loop body does O(1) operations. j loop repeats n times, so j loop does O(n) operations. i loop repeats n times, so i loop does n O(n) = O(n 2 ) operations. Algorithm is O(n 2 ).

Example: Matrix multiplication (naive algorithm) Input: Two n n matrices A and B. Output: The matrix C = AB. for i from 1 to n do for j from 1 to n do C i,j := 0; for k from 1 to n do C i,j := C i,j + A i,k B k,j ; endfor endfor endfor Algorithm is O(n 3 ).

Little O notation Big O is a kind of less than or equal to. The strict counterpart is little O: f (n) = o ( g(n) ) (read f (n) is little O of g(n) ) means for every ε > 0 there is some N such that (n) ε g(n) for all n > N. If g(n) is nonzero for sufficiently large n, the above is equivalent to f (n) lim n g(n) = 0.

Smaller is better? The general sentiment is that an algorithm is better the lower its asymptotic, or more formally: If algorithm A has f (n) and algorithm B has g(n), where f (n) = o ( g(n) ), then A is better than B. Caveats: To achieve lower, the algorithm often needs to be more complicated, and may thus be harder to implement correctly. The O notations hide constants, which may make a difference for problems of the size you re interested in.

Algorithms for matrix multiplication Naive matrix multiplication is O(n 3 ). Strassen s matrix multiplication algorithm (1969) is O(n 2.81 ). From 1980 and forth, various o(n 2.5 ) algorithms have been presented (Coppersmith Winograd and others). In general, the lower the exponent, the higher the constant factor that is hidden by the big O notation (though not according to a simple pattern). Strassen s O(n 2.81 ) algorithm perform fewer operations than the naive one for n > 100, if implemented well. The various o(n 2.5 ) algorithms all have gigantic constants, and are inferior for all matrices of managable size.

The algorithm is a bound, but what is it a bound of? If nothing else is said, it should be a bound for all possible outcomes, even the most unfavourable ones. This is called worst-case. Average-case is instead a bound for the expected outcome for random input of the given size. Amortised is a bound for the average of an operation if it is repeated a large number of times. This can be appropriate for operations that are part of a larger algorithm.

Example: Exponential growth of list An unbounded length list can be implemented using: a pointer to a dynamically allocated vector of items, a counter N for the number of elements in the list, a counter K for the number of elements in the vector. If N < K, then appending an element to the list is worst-case O(1). But if N = K (the vector is full), one must first allocate a new, larger vector and copy all data from the old one to the new before adding the new element. This is an O(N) operation. If the vector size is grown by a constant factor c > 1 each time it is resized, then it is possible to achieve O(1) amortised for appending.

Concrete One classification refers to concrete estimates: constant O(1) logarithmic O(log n) linear O(n) quadratic O(n 2 ) cubic O(n 3 ) polynomial O(n d ) for some constant d exponential O(a n ) for some constant a doubly exponential O(a an ) Sub- and super- are sometimes used as prefixes to the above to mean less than and more than respectively, sometimes with an implied slightly. n! and n n are both superexponential, but only slightly so, since they are both O(2 n log n ).

Anything less than linear means you ll have to accomplish the task without even looking at all the input! This is rare, but happens, and may be dependant upon the computation model. For larger time complexities (polynomial and up), the exact model usually doesn t matter, because the different models can emulate each other well enough. The exact format of the input can matter greatly in low settings, but is less important in higher, as a preprocessing step translating to the preferred format tends to contribute only a lower order term to the total. Note that the n in matrix algorithm estimates tends to be the matrix side rather than the formal input size. A general n n matrix requires at least Cn 2 bits to encode, so in that sense matrix addition is a linear time operation.

Theoretical There is also a more theoretical hierarchy of, which refers more to families of computational problems and the of an optimal algorithm for solving these. P is the class of all problems for which the output is a boolean (yes/no problems) and for which there is a polynomial algorithm. NP is the class of all problems with boolean output for which the corresponding verification problem (checking someone s substantiated claim that the answer is yes ) is in P. A typical example of an NP problem would be to ask whether a system of inequalities has a solution. If the answer is yes, then the claimant can substantiate this claim by giving that solution; verifying that something is a solution can easily be done in polynomial time.

Surprisingly, the majority of all NP problems for which no polynomial algorithm is known are NP-complete: any other NP problem can be transformed to an instance of that problem. Hence they are all equally difficult. All known algorithms for NP-complete problems have exponential time. It is not a severe restriction that NP problems only answer yes/no questions. A bit string of any length can be calculated through a series of yes/no questions asking whether the kth bit is 1.