22.01.2014 Views

IEOR 269, Spring 2010 Integer Programming and Combinatorial ...

IEOR 269, Spring 2010 Integer Programming and Combinatorial ...

IEOR 269, Spring 2010 Integer Programming and Combinatorial ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>IEOR</strong><strong>269</strong> notes, Prof. Hochbaum, <strong>2010</strong> 25<br />

15 Complexity analysis<br />

15.1 Measuring quality of an algorithm<br />

Algorithm: One approach is to enumerate the solutions, <strong>and</strong> select the best one.<br />

Recall that for the assignment problem with 70 people <strong>and</strong> 70 tasks there are 70! ≈ 2 332.4 solutions.<br />

The existence of an algorithm does not imply the existence of a good algorithm!<br />

To measure the complexity of a particular algorithm, we count the number of operations that are<br />

performed as a function of the ‘input size’. The idea is to consider each elementary operation<br />

(usually defined as a set of simple arithmetic operations such as {+, −, ×, /, ≤}) as having unit<br />

cost, <strong>and</strong> measure the number of operations (in terms of the size of the input) required to solve a<br />

problem. The goal is to measure the rate, ignoring constants, at which the running time grows as<br />

the size of the input grows; it is an asymptotic analysis.<br />

Complexity analysis is concerned with counting the number of operations that must be performed<br />

in the worst case.<br />

Definition 15.1 (Concrete Complexity of a problem). The complexity of a problem is the complexity<br />

of the algorithm that has the lowest complexity among all algorithms that solve the problem.<br />

15.1.1 Examples<br />

Set Membership - Unsorted list: We can determine if a particular item is in a list of n items<br />

by looking at each member of the list one by one. Thus the number of comparisons needed<br />

to find a member in an unsorted list of length n is n.<br />

Problem: given a real number x, we want to know if x ∈ S.<br />

Algorithm:<br />

1. Compare x to s i<br />

2. Stop if x = s i<br />

3. else if i ← i + 1 < n goto 1 else stop x is not in S<br />

Complexity = n comparisons in the worst case. This is also the concrete complexity of<br />

this problem. Why?<br />

Set Membership - Sorted list: We can determine if a particular item is in a list of n elements<br />

via binary search. The number of comparisons needed to find a member in a sorted list of<br />

length n is proportional to log 2 n.<br />

Problem: given a real number x, we want to know if x ∈ S.<br />

Algorithm:<br />

1. Select s med = ⌊ first+last<br />

2<br />

⌋ <strong>and</strong> compare to x<br />

2. If s med = x stop<br />

3. If s med < x then S = (s med+1 , . . . , s last ) else S = (s first , . . . , s med−1 )<br />

4. If first < last goto 1 else stop<br />

Complexity: after k th iteration<br />

n<br />

≤ 2, which implies:<br />

2 k−1<br />

n<br />

2 k−1 elements remain. We are done searching for k such that<br />

log 2 n ≤ k<br />

Thus the total number of comparisons is at most log 2 n.<br />

Aside: This binary search algorithm can be used more generally to find the zero in a monotone<br />

increasing <strong>and</strong> monotone nondecreasing functions.<br />

Matrix Multiplication: The straightforward method for multiplying two n × n matrices takes<br />

n 3 multiplications <strong>and</strong> n 2 (n − 1) additions. Algorithms with better complexity (though not

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!