Académique Documents
Professionnel Documents
Culture Documents
1
A.Yazıcı Lower&Upper Bound, Fall 2015
Lower and Upper Bound Theory
How fast can we sort?
Lower-Bound Theory can help us answer this
question.
• Most of the sorting algorithms are comparison
sorts: only use comparisons to determine the
relative order of elements.
Examples: insertion sort, merge sort, quicksort,
heapsort.
• The best worst-case running time that we’ve
seen for comparison sorting is O(nlgn) .
Is O(nlgn) the best we can do? 2
A.Yazıcı Lower&Upper Bound, Fall 2015
Lower and Upper Bound Theory
• Lower Bound, L(n), is a property of the specific
problem, i.e. sorting problem, MST, matrix
multiplication, not of any particular algorithm
solving that problem.
• Lower bound theory says that no algorithm can
do the job in fewer than L(n) time units for
arbitrary inputs.
• For example, every comparison-based sorting
algorithm must take at least L(n), nlgn, time in
the worst case.
• L(n) is the minimum over all possible
algorithms, of the maximum complexity.
3
A.Yazıcı Lower&Upper Bound, Fall 2015
Lower and Upper Bound Theory
• Upper bound theory says that for any arbitrary inputs,
we can always sort in time at most U(n). How long it
would take to solve a problem using one of the known
algorithms with worst-case input gives us a upper
bound.
• U(n) is the minimum over all known algorithms, of the
maximum complexity.
• For example: Finding the maximum element in an
unsorted array is U(n), O(n).
• Both upper and lower bounds are minima over the
maximum complexity of inputs of size n.
• Improving an upper bound means finding a new
algorithm with better worst-case performance.
• The ultimate goal is to make these two functions
coincide. When this is done, the optimal algorithm will
have L(n) = U(n). 4
A.Yazıcı Lower&Upper Bound, Fall 2015
Lower Bounds
Examples:
• an estimate on a minimum amount needed to
multiply two n-by-n matrices of work needed to
solve a given problem.
• number of comparisons needed to find the mean
element in a set of n numbers.
• number of comparisons needed to sort an array of
size n.
• number of comparisons necessary for searching in a
sorted array.
• number of multiplications for n-digit integers.
5
A.Yazıcı Lower&Upper Bound, Fall 2015
Lower Bounds (cont.)
• Lower bound can be
– an exact count
– an efficiency class (Ω)
• information-theory
• decision tree
• problem reduction
• adversary arguments
7
A.Yazıcı Lower&Upper Bound, Fall 2015
Trivial Lower Bound Method
• Note that any algorithm must, at least, read its inputs and write
its outputs.
Comment:
• This method may and may not be useful
≤
>
<a,b> <c,d>
≤ > ≤ >
a b c d
≤ >
≤ > ≤ >
<1,2,3>
<2,1,3>
≤ >
≤ >
111
16
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree model
• Decision tree is a convenient model of algorithms
involving comparisons in which:
• Internal nodes represent comparisons
• leaves represent outcomes.
• There must be n internal nodes in all of these trees
corresponding to the n possible successful
occurrences of x in A.
• Because every leaf in a valid decision tree must be
reachable, the worst-case number of comparisons
done by such a tree is the number of nodes in the
longest path from the root to a leaf in the decision
tree consisting of the comparison nodes.
• Worst-case running time = the length of the longest
path of tree = the height of tree.
17
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree Model for Searching
18
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree model for Searching
x:A(lg(n+1)/2)
Height=log2n
≤
>
x:A(lg(n+1)/4) x:A(lg(3n+1)/4)
≤ >
> ≤ ….
≤ ≤ ≤
> > ≤ > >
Return Failure Return Failure Return Failure Return Failure
19
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree Model for Search on Sorted Elements
3
< >
=
1 3 5 Height=log2(7)=3
< > <
= >
=
0 1 2 4 5 6
<
= > <
=
> <
=
> < >
=
F 0 F F 2 F F 4 F F 6 F
20
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree Model for Searching
Example: Comparison-based searching problem
• A decision tree, with n leaves and height h, n ≤ 2h.
Indeed, a decision tree of height h with largest
number of leaves has all its leaves on the last
level. Hence, the largest number of leaves in such
a tree is 2h. FIND(n) = h ≥ log (n)
Since, n ≤ 2h and.
Such a longest path is Θ(lgn).
• Therefore, the lower bound for comparison-
based searching on ordered input is Θ(lgn).
21
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree model for Searching
x:A(1)
= ≠ Height = n
Return(A(1)) x:A(2)
≠
=
Return(A(2))
x:A(n)
= ≠
Return(A(n)) Return(A(0))
22
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree for Search on Unsorted Elements
4
= ≠
4 1
= ≠
1 5
= ≠
5 3
= ≠
Height = 5
3
=
2
≠
2 0
=
0 F
a1a2a3 a2a1a3
yes no yes no
a2<a3 a1<a3
a1a3a2 a2a3a1
a1<a2<a3 a2<a1<a3
yes no yes no
a1<a3 a2<a3
24
A.Yazıcı Lower&Upper Bound, Fall 2015
Decision-tree model for sorting
29
A.Yazıcı Lower&Upper Bound, Fall 2015
Example for reduction Convex Hull (cont.)
30
A.Yazıcı Lower&Upper Bound, Fall 2015
Example for reduction Convex Hull (cont.)
Theorem: The comparison-based sorting problem is
transformable (in linear time) to the convex hull
problem, therefore; the problem of finding the
ordered convex hull of n points in the plane requires
Ω(nlogn) time. That is, LB of the problem of
convex hull is also Ω(nlogn).
y y = x2
*
*
*
*
*
*
x
x1 x2 x3 x4 x5 x6
Sorted
33
A.Yazıcı Lower&Upper Bound, Fall 2015
Example for reduction Convex Hull (cont.)
34
A.Yazıcı Lower&Upper Bound, Fall 2015
Oracles and Adversary Arguments
• Another technique for obtaining LBs consists of making use of an oracle or
adversary arguments.
• Adversary arguments establish (worst-case) lower bounds by dynamically
creating inputs to a given algorithm that force the algorithm to perform
many basic operations.
• In order to derive a good LB, the adversary tries its best to cause the
algorithm to work as hard as it might.
• We only require that the adversary gives answers that are consistent and
truthful.
• We also assume that the algorithm uses a basic operation when querying the
adversary.
• Clever adversaries force any given algorithm to make many queries before
the algorithm has enough information to output the solution.
• LBs for the worst-case complexity are then obtained by counting the
number of basic operations that the adversary forces the algorithm to
perform.
35
A.Yazıcı Lower&Upper Bound, Fall 2015
Oracle and Adversary Arguments
• Adversary argument: a method of proving a lower bound by playing role of
adversary that makes algorithm work the hardest by adjusting input.
• LBs for the worst-case complexity are then obtained by counting the
number of basic operations that the adversary forces the algorithm to
perform.
Example-1: “Guessing” a number between 1 and n with yes/no
questions.
Adversary:Put the number in a larger of the two subsets
generated by last question.
For example; Adversary (or Oracle) knows your guess, which in the order
of <4,7,9,4,8>. So, you put the the numbers in that order, 8 at the end, to
force the algorithm the hardest way. That way, output is guessed as 8 only
after n-1 guesses. That means the lower bound for this problem is Ω(n).