Download presentation
Presentation is loading. Please wait.
1
CS420 lecture three Lowerbounds wim bohm, cs CSU
2
Big O, big omega, big theta f(x) = O(g(x)) iff there are positive integers c and n 0 such that f(x) n 0 f(x) = Ω(g(x)) iff there are positive integers c and n 0 such that f(x) > c.g(x) for all x > n 0 f(x) = Θ(g(x)) iff f(x) = O(g(x)) and f(x) = Ω(g(x))
3
Big O etc. Big O used in upper bounds, ie the worst or average case complexity of an algorithm. Big theta is a tight bound, eg stronger than upper bound. Big omega used in lower bounds, ie the complexity of a problem.
4
lower bounds An easy lower bound on a problem is the size of the output it needs to produce, or the number of inputs it has to access – Generate all permutations of size n, lower bound? – Towers of Hanoi, lower bound? – Sum n input integers, lower bound? but... sum integers 1 to n?
5
some Ω(n) problems Given an unsorted array A and a number p, rearrange A such that all A[i] x
6
some Ω(n) problems Given an unsorted array A and a number x, rearrange A such that all A[i] =x L=1; R=n; while(L<R){ while((A[L]<=x)&&(L<R)L++ while((A[R]>=x)&&(L<R))R- - if(L<R)swap(A,L,R) }
7
Dutch National Flag
8
flag
10
Comparison problems We have seen search.
11
Comparison problems We have seen search. Why is it closed?
12
Comparison problems We have seen search. Why is it Ω(logn)?
13
Comparison problems We have seen search. What are the allowed operations?
14
Comparison problems We have seen search. Why is the decision tree binary?
15
Comparison problems We have seen search. At least how many leaves?
16
Comparison problems We have seen search. At least how high? Why?
17
Comparison problems Let's try the same for sort we have an O(n logn) upper bound what would be the allowed steps?
18
Comparison problems Let's try the same for sort we have an O(n logn) upper bound comparison, array element assignment, index arithmetic, establish sorted
19
Comparison problems Let's try the same for sort we have an O(n logn) upper bound is the decision tree binary again?
20
Comparison problems Let's try the same for sort we have an O(n logn) upper bound how many leaves this time?
21
Comparison problems Let's try the same for sort we have an O(n logn) upper bound every leaf represents a specific permutation of the array
22
Comparison problems Let's try the same for sort we have an O(n logn) upper bound how many different permutations?
23
Comparison problems Let's try the same for sort we have an O(n logn) upper bound n! how high will the decision tree at least be?
24
Comparison problems Let's try the same for sort we have an O(n logn) upper bound the decision tree will be at least log(n!) high log(n!) = O(nlogn) so sort is Ω(nlogn), and thus closed.
25
Tournaments Selecting the maximum element of an array. View it as a tournament. Comparison is a match, winning is transitive: – A>B and B>C implies A>C, so A does not need to play C, and B and C can never be the winner of the tournament Many possible O(n) algorithms tennis(S): if (|S|==1) S 1 else max(tennis(topHalf(S)), tennis(bottomHalf(S))) sweep(S): winner= S 1 for i=2 to n winner = max(winner,S i )
26
Runner up a b c d e f g h b a d c f e h g tennis sweep which gives more info about runner up?
27
Assumptions about initial input Transitive and total ordering – transitive: a>b and b>c implies a>c (no roshambo) – total: for all a and b: either a>b or b>a – ie the elements can be ranked Any assignment of ranks to names is feasible – in previous example we could assign any of the 8! permutations of rankings 1 to 8 to a to h Because we look for the winner, anyone who loses stops playing. Therefore there will be n-1 (n is number of inputs) games / comparisons for any tournament – notice: both sweep and tennis have 7 matches
28
Simpler case: n=4 Any of the 24 assignments of 1..4 to a..d is valid Build a decision tree for sweep (for n = 4), which is sometimes called "caterpillar"
29
Decision tree for sweep Any of the 24 assignments of 1..4 to a..d is valid Build a decision tree for sweep (for n = 4) a:b b a a:c c a b:c c b c:d d c b:d d b c:d d c a:d d a
30
Decision tree for sweep Any of the 24 assignments of 1..4 to a..d is valid Build a decision tree for sweep (for n = 4) a:b b a a:c c a b:c c b c:d d c b:d d b c:d d c a:d d a what do we know about the runner up for this outcome?
31
Decision tree for sweep Any of the 24 assignments of 1..4 to a..d is valid Build a decision tree for sweep (for n = 4) a:b b a a:c c a b:c c b c:d d c b:d d b c:d d c a:d d a what do we know about the runner up for this outcome?
32
tennis Build a decision tree for tennis (for n = 4)
33
Decision tree for tennis Build a decision tree for tennis (for n = 4) a:b b a c:d d c d c b:d d b b:c c b a:d d a a:c c a
34
Decision tree for tennis Build a decision tree for tennis (for n = 4) a:b b a c:d d c d c b:d d b b:c c b a:d d a a:c c a what do we know about the runner up for this outcome?
35
Decision tree for tennis Build a decision tree for tennis (for n = 4) a:b b a c:d d c d c b:d d b b:c c b a:d d a a:c c a what do we know about the runner up for this outcome?
36
Runner up In “The Art of Computer Programming, vol 3”, Donald Knuth proved that the tennis tournament algorithm provides the lower bound to determine the runner up: In the case of tennis we need lg n more comparisons to find the runner up
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.