UMass Lowell Computer Science 91.503
Analysis of Algorithms
Prof. Karen Daniels
Spring, 2009
Lecture 1 (Part 2)
“How to Make an Algorithm Sandwich”
adapted from the fall, 2000 talk
Finding the Largest Area Axis-Parallel Rectangle in a Polygon in O(n log2 n) Time
given at UMass Lowell MATHEMATICAL SCIENCES COLLOQUIUM
Context: Taxonomy of Problems
Supporting Apparel Manufacturing
Maximum
Rectangle
Geometric Restriction
Distance-Based
Subdivision
Ordered
Containment
Limited Gaps
Containment
Maximal Cover
Two-Phase Layout
Minimal
Enclosure
Lattice
Packing
Column-Based Layout
A Common (sub)Problem
Find a Good Approximation
Outer
Inner
What’s the Problem?
Given a 2D polygon that:
does
not intersect itself
may have holes
has n vertices
Find the Largest-Area Axis-Parallel Rectangle
How “hard” is it?
How “fast” can we find it?
Approach
Explore the problem to gain intuition:
Establish worst-case upper bound on the problem using
an algorithm
1
Describe it: What are the assumptions? (model of computation, etc...)
Has it already been solved?
Have similar problems been solved? (more on this later)
What does best-case input look like?
What does worst-case input look like?
Design a (simple) algorithm and find an upper bound on its worst-case
asymptotic running time; this tells us problem can be solved in a certain
amount of time. Algorithms taking more than this amount of time may exist,
but won’t help us.
Establish worst-case lower bound on the problem
Tighten each bound to form a worst-case “sandwich”
n
n2
n3
n4
n5
increasing worst-case asymptotic running time as a function of n
2n
Upper Bound
First Attempt
Designing an Algorithm
to Provide Upper Bound
First attempt uses a straightforward approach:
“brute-force”
“naïve”
Will most likely produce a “loose” upper bound
Characterize rectangle based on how it can “grow”
Contacts reduce degrees of freedom
O(n5) LR Algorithm
Find_LR(Polygon P)
area0
Find_LR_0_RC(P)
area1
Find_LR_1_RC(P)
area2
Find_LR_2_RC(P)
area3
Find_LR_3_RC(P)
area4
Find_LR_4_RC(P)
return maximum(area0, area1, area2, area3, area4)
Find_LR_0_RC(P)
for i
1 to n (for each edge of P)
for j
1 to n
for k
1 to n
for l
1 to n
O(n5)
area
area of LR for 0-RC determining set for (i,j,k,l)
O(n)
if LR is empty, then update maximum area
return maximum area
First Upper Bound:
What can we really conclude?
Algorithm’s worst-case running time is in O(n5).
Problem can be solved in O(n5) time, even for worst-case
inputs.
If a worst-case input exists that causes algorithm to
actually use time proportional to n5, then algorithm’s
worst-case running time is also in W(n5).
1
Note: there might exist algorithms for this problem that take more than n5
time, but they aren’t useful to us!
In this case, we can say algorithm’s worst-case running time is
in Q(n5).
An inefficient algorithm for
n
the problem might exist
n2
n5 that takes this much time,
but would not help us.
increasing worst-case asymptotic running time as a function of n
2n
Lower Bound
First Attempt
1
n
n2
n5
An inefficient algorithm for
the problem might exist
that takes this much time,
but would not help us.
increasing worst-case asymptotic running time as a function of n
2n
First Attempt
First attempt will most likely produce a “loose” lower
bound that can be improved later.
W(1) and W(n) are not hard to achieve:
Rationale for W(n) is that we must examine every vertex at
least once in order to solve the problem. This holds for every
algorithm that solves the problem, so it gives us a lower bound
on the problem in an even stronger sense than our upper
bound.
1
Remember that our upper bound does not guarantee that no algorithm
exists for this problem that takes more than O(n5) time, but if one exists
it will not help us!
No algorithm for the problem
exists that can solve it for
worst-case inputs in less
than linear time .
n5
n
worst-case bounds
on problem
An inefficient algorithm for
the problem might exist
that takes this much time,
but would not help us.
2n
Upper Bound
Tightening It
Approach
Think harder…
Design an algorithm that takes only O(n2) time for
worst-case inputs
tighter upper
bound
1
n
n2
2n
n5
worst-case bounds
on problem
Now we no longer care
about this one!
Approach (continued)
Think even harder…
Run into brick wall!
Characterize the brick wall: this type of case
Go around brick wall by looking at similar problems.
This requires ability to compare functions!
worst-case bounds
on problem
1
n
n2
n5
2n
Some Related Problems
1 n
n a(n) n log(n) n a(n) log(n) n log2(n)
n5
2n
Some Related Problems
(continued)
1 n
n a(n) n log(n) n a(n) log(n) n log2(n)
n5
2n
Approach (continued)
Reduce the O(n2) bound to O(n log2 n):
Adapt
a technique that worked for a similar problem in
order to develop a general framework for the
problematic case
worst-case bounds
on problem
1
n
n log2 n
n2
n5
2n
Lower Bound
Tightening It
Approach
Go around lower bound brick wall by:
examining
strong lower bounds for some similar
problems
transforming a similar problem to our problem
[this process is similar to what we do when we prove problems NP-complete]
worst-case bounds
on problem
1
n
n log2 n
n2
n5
2n
Lower Bounds for Related Problems
SmallestOuterCircle: Q (n)
point set, polygon
SmallestOuterRectangle: Q (n) point set, polygon
LargestInnerRectangle: W (n) polygon
LargestInnerCircle: Q (n log n) point set
Largest circle containing no points of the set & whose center is in convex hull of the points
LargestInnerRectangle: O (n log2(n)) polygon
1
n
n log(n)
n log2(n)
worst-case bounds on our problem
n5
2n
Lower Bound of W(n log n) by
Transforming a (seemingly unrelated) Problem
MAX-GAP instance: given n real numbers { x1, x2, ... xn } find the
maximum difference between 2 consecutive numbers in the
sorted list.
O(n) time transformation
Rectangle
specialized
area is a
polygon
solution to the
MAX-GAP
x2
instance
x4
x3 x1
Rectangle algorithm must take as least as much time as MAX-GAP.
MAX-GAP is known to be in W(n log n).
Rectangle algorithm must take W(n log n) time
for specialized polygons.
[Transforming yet another different problem yields bound for unspecialized polygons.]
Summary
First attempt:
Tighten bounds to make an “algorithm sandwich”
Establish weak (but tighter) worst-case O(n log2 n) upper
1
Establish weak (and loose) worst-case upper bound on the
problem using an algorithm
Establish strong (and loose) worst-case lower bound on the
problem
n
bound on the problem using an algorithm
Establish strong (and tighter) worst-case lower bound on the
problem by transforming a problem with known lower bound
n log(n)
n log2(n)
bounds on problem
n5
2n
Further Improvement!
“Finding the Largest Axis-Aligned Rectangle in a
Polygon in O(n log n) Time”
Ralph Boland, Jorge Urrutia
1
n
Canadian Conference on Computational Geometry,
August 13-15, 2001
n log(n)
n log2(n)
n5
2n
bounds on problem
1
n
n log(n)
n log2(n)
Tight bound on problem
n5
2n
For More Information
Journal paper: “Finding the largest area axis-parallel
rectangle in a polygon”
Computational Geometry: Theory and Applications
http://www.cs.uml.edu/~kdaniels/
Computational Geometry:
Chapter 33 of 91.503 textbook
Graduate CS course in Computational Geometry offered at UMass
Lowell in Spring ’01, Spring ’04, Spring ’05, Spring ’07
http://www.cs.uml.edu/~kdaniels/ALG_504.html
Introductory text:
Computational Geometry in C (O’Rourke)
Computational Geometry Algorithms Library (CGAL)
http://www.cgal.org
© Copyright 2026 Paperzz