umass lowell computer science 91.503 analysis of algorithms prof. karen daniels spring, 2005 lecture...
TRANSCRIPT
UMass Lowell Computer Science 91.503
Analysis of Algorithms Prof. Karen Daniels
Spring, 2005
UMass Lowell Computer Science 91.503
Analysis of Algorithms Prof. Karen Daniels
Spring, 2005
Lecture 1 (Part 2)Lecture 1 (Part 2)““How to Make an Algorithm SandwichHow to Make an Algorithm Sandwich””
adapted from the fall, 2000 talkadapted from the fall, 2000 talkFinding the Largest Area Axis-Parallel Rectangle in a Polygon in Finding the Largest Area Axis-Parallel Rectangle in a Polygon in OO(n log(n log22 n) Time n) Time
given at UMass Lowell MATHEMATICAL SCIENCES COLLOQUIUMgiven at UMass Lowell MATHEMATICAL SCIENCES COLLOQUIUM
Context: Taxonomy of ProblemsSupporting Apparel Manufacturing
Context: Taxonomy of ProblemsSupporting Apparel Manufacturing
Ordered Ordered ContainmentContainment
Geometric RestrictionGeometric Restriction
Distance-Based Distance-Based SubdivisionSubdivision
Maximum Maximum RectangleRectangle
Limited GapsLimited Gaps
Minimal Minimal EnclosureEnclosure
Column-Based LayoutColumn-Based LayoutTwo-Phase LayoutTwo-Phase Layout
Lattice Lattice PackingPacking
ContainmentContainment
Maximal CoverMaximal Cover
A Common (sub)Problem
Find a Good ApproximationFind a Good Approximation
Outer Outer InnerInner
Given a 2D polygon that:Given a 2D polygon that: does not intersect itselfdoes not intersect itself may have holesmay have holes has has nn vertices vertices
Find the Find the LLargest-Area Axis-Parallel argest-Area Axis-Parallel RRectangleectangle How “hard” is it?How “hard” is it? How “fast” can we find it?How “fast” can we find it?
What’s the Problem?
Explore the Explore the problem problem to gain intuition:to gain intuition: Describe it: What are the assumptions? Describe it: What are the assumptions? (model of computation, (model of computation,
etc...)etc...) Has it already been solved?Has it already been solved? Have similar problems been solved? (Have similar problems been solved? (more on this latermore on this later)) What does best-case input look like?What does best-case input look like? What does worst-case input look like?What does worst-case input look like?
Establish worst-case Establish worst-case upper boundupper bound on the on the problemproblem using using an algorithman algorithm Design a (simple) algorithm and find an upper bound on its worst-case Design a (simple) algorithm and find an upper bound on its worst-case
asymptotic running time; this tells us problem asymptotic running time; this tells us problem can becan be solved in a certain solved in a certain amount of time. Algorithms taking more than this amount of time may amount of time. Algorithms taking more than this amount of time may exist, but won’t help us.exist, but won’t help us.
Establish worst-case Establish worst-case lower boundlower bound on the on the problemproblem Tighten each bound to form a worst-case “sandwich” Tighten each bound to form a worst-case “sandwich”
Approach
increasing worst-case asymptotic running time as a function of nincreasing worst-case asymptotic running time as a function of n
nn11 22nnnn22 nn33 nn44 nn55
Upper BoundUpper Bound
First AttemptFirst Attempt
Designing an Algorithmto Provide Upper BoundDesigning an Algorithmto Provide Upper Bound
Contacts reduce degrees of freedomContacts reduce degrees of freedom
First attempt uses a straightforward approach:First attempt uses a straightforward approach: ““brute-force”brute-force” ““naïve”naïve”
Will most likely produce a “loose” upper boundWill most likely produce a “loose” upper bound Characterize rectangle based on how it can “grow”Characterize rectangle based on how it can “grow”
O(n5) LR AlgorithmO(n5) LR Algorithm
Find_LR(Polygon P)Find_LR(Polygon P) area0 Find_LR_0_RC(P)area0 Find_LR_0_RC(P) area1 Find_LR_1_RC(P)area1 Find_LR_1_RC(P) area2 Find_LR_2_RC(P)area2 Find_LR_2_RC(P) area3 Find_LR_3_RC(P)area3 Find_LR_3_RC(P) area4 Find_LR_4_RC(P)area4 Find_LR_4_RC(P) return maximum(area0, area1, area2, area3, area4)return maximum(area0, area1, area2, area3, area4)
Find_LR_0_RC(P)Find_LR_0_RC(P)for i 1 to n for i 1 to n ((for each edge of Pfor each edge of P))
for j 1 to nfor j 1 to n for k 1 to nfor k 1 to n for l 1 to nfor l 1 to n area area of LR for 0-RC determining set for (i,j,k,l)area area of LR for 0-RC determining set for (i,j,k,l)
if LR is empty, then update maximum areaif LR is empty, then update maximum area return maximum areareturn maximum areaO(n)O(n)
O(nO(n55))
First Upper Bound: What can we really conclude?First Upper Bound: What can we really conclude?
AlgorithmAlgorithm’s worst-case running time is in O(n’s worst-case running time is in O(n55).). ProblemProblem cancan be solved in O(n be solved in O(n55) time, even for worst-case ) time, even for worst-case
inputs.inputs. Note: there might exist algorithms for this problem that take more than nNote: there might exist algorithms for this problem that take more than n55
time, but they aren’t useful to us!time, but they aren’t useful to us!
If a worst-case input exists that causes If a worst-case input exists that causes algorithmalgorithm to to actually use time proportional to nactually use time proportional to n55, then , then algorithmalgorithm’s ’s worst-case running time is also in worst-case running time is also in (n(n55).). In this case,In this case, we can saywe can say algorithm algorithm’s worst-case running time is ’s worst-case running time is
in in (n(n55).).
nn11 nn22 22nnnn55
increasing worst-case asymptotic running time as a function of nincreasing worst-case asymptotic running time as a function of n
An inefficient algorithm for An inefficient algorithm for the problem might exist the problem might exist that takes this much time, that takes this much time, but would not help us.but would not help us.
Lower Bound Lower Bound
First AttemptFirst Attempt
nn11 nn22 22nnnn55
increasing worst-case asymptotic running time as a function of nincreasing worst-case asymptotic running time as a function of n
An inefficient algorithm for An inefficient algorithm for the problem might exist the problem might exist that takes this much time, that takes this much time, but would not help us.but would not help us.
First AttemptFirst Attempt
First attempt will most likely produce a “loose” lower First attempt will most likely produce a “loose” lower bound that can be improved later.bound that can be improved later.
(1) and (1) and (n) are not hard to achieve:(n) are not hard to achieve: Rationale for Rationale for (n) is that we must examine (n) is that we must examine everyevery vertex at vertex at
least once in order to solve the problem. This holds for least once in order to solve the problem. This holds for everyevery algorithm that solves the problem, so it gives us a lower bound algorithm that solves the problem, so it gives us a lower bound on the problem in an even stronger sense than our upper on the problem in an even stronger sense than our upper bound. bound. Remember that our upper bound Remember that our upper bound does not guaranteedoes not guarantee that that nono algorithm algorithm
exists for this problem that takes more than O(nexists for this problem that takes more than O(n55) time, but if one ) time, but if one exists it will not help us! exists it will not help us!
nn11 22nnnn55
worst-case boundsworst-case bounds on problemon problem
An inefficient algorithm for An inefficient algorithm for the problem might exist the problem might exist that takes this much time, that takes this much time, but would not help us.but would not help us.
No algorithm for the problem No algorithm for the problem exists that can solve it for exists that can solve it for worst-case inputs in less worst-case inputs in less than linear time .than linear time .
Know the Difference!Know the Difference!
nn11 22nnnn55
worst-case boundsworst-case bounds on problemon problem
An inefficient algorithm for An inefficient algorithm for the problem might exist the problem might exist that takes this much time, that takes this much time, but would not help us.but would not help us.
No algorithm for the problem No algorithm for the problem exists that can solve it for exists that can solve it for worst-case inputs in less worst-case inputs in less than linear time .than linear time .
Strong BoundStrong Bound: This : This worst-case worst-case lowerlower bound bound on the problem holds for on the problem holds for everyevery algorithm that algorithm that solves the problem and solves the problem and abides by our problem’s abides by our problem’s assumptions.assumptions.
Weak BoundWeak Bound: This worst-case : This worst-case upperupper bound on the problem bound on the problem comes from just considering comes from just considering oneone algorithm. Other, less algorithm. Other, less efficient algorithms that solve efficient algorithms that solve this problem might exist, but this problem might exist, but we don’t care about them!we don’t care about them!
Both the upper and lower bounds Both the upper and lower bounds are probably are probably looseloose (i.e. probably (i.e. probably can be can be tightenedtightened later on). later on).
Upper BoundUpper Bound
Tightening ItTightening It
Think harder…Think harder… Design an algorithm that takes only O(nDesign an algorithm that takes only O(n22) time for ) time for
worst-case inputsworst-case inputs
Approach
11 22nnnn55nn
worst-case boundsworst-case bounds on problemon problem
nn22
Now we no longer care Now we no longer care about this one!about this one!
tighter upper tighter upper boundbound
Think even harder…Think even harder… Run into brick wall!Run into brick wall! Characterize the brick wall: this type of caseCharacterize the brick wall: this type of case Go around brick wall by looking at similar problems.Go around brick wall by looking at similar problems. This requires ability to compare functions!This requires ability to compare functions!
Approach (continued)
nn11 22nnnn55
worst-case boundsworst-case bounds on problemon problem
nn22
Some Related ProblemsSome Related Problems
nn11 n log(n) n log(n) n logn log22(n) (n) 22nnnn55n n (n) log(n)(n) log(n)n n (n)(n)
Some Related Problems
(continued)Some Related Problems
(continued)
nn11 n log(n) n log(n) n logn log22(n) (n) 22nnnn55n n (n) log(n)(n) log(n)n n (n)(n)
Reduce the O(nReduce the O(n22) bound to O(n log) bound to O(n log22 n): n): Adapt a technique that worked for a similar problem in Adapt a technique that worked for a similar problem in
order to develop a general framework for the order to develop a general framework for the problematic caseproblematic case
Approach (continued)
nn11 22nnnn55
worst-case boundsworst-case bounds on problemon problem
nn22n logn log22 n n
Lower BoundLower Bound
Tightening ItTightening It
ApproachApproach
Go around lower bound brick wall by:Go around lower bound brick wall by: examining examining strongstrong lower bounds for some similar lower bounds for some similar
problemsproblems transforming a similar problem to our problemtransforming a similar problem to our problem
[this process is similar to what we do when we prove problems NP-complete][this process is similar to what we do when we prove problems NP-complete]
nn11 22nnnn55
worst-case boundsworst-case bounds on problemon problem
nn22n logn log22 n n
Lower Bounds for Related Problems Lower Bounds for Related Problems
nn11 n log(n) n log(n) n logn log22(n) (n) 22nnnn55
SmallestOuterRectangle: (n)
SmallestOuterCircle: (n)
LargestInnerRectangle: (n)
LargestInnerCircle: (n log n)
point set, polygonpoint set, polygon
point set, polygonpoint set, polygon
point setpoint set
polygonpolygon
LargestInnerRectangle: (n log2(n)) polygonpolygon
worst-case bounds on our problemworst-case bounds on our problem
Largest circle containing no points of the set & whose center is in convex hull of the pointsLargest circle containing no points of the set & whose center is in convex hull of the points
Lower Bound of (n log n) by Transforming a (seemingly unrelated) ProblemLower Bound of (n log n) by Transforming a (seemingly unrelated) Problem
MAX-GAP MAX-GAP instanceinstance: given : given nn real numbers { x real numbers { x11, x, x22, ... x, ... xn n } find the } find the maximum difference between 2 consecutive numbers in the maximum difference between 2 consecutive numbers in the sortedsorted list. list.
O(n) time transformationO(n) time transformationspecialized specialized polygonpolygon
xx22xx44 xx33 xx11
Rectangle Rectangle area is a area is a solution to the solution to the MAX-GAP MAX-GAP instance instance
Rectangle algorithm must take as least as much time as MAX-GAP.Rectangle algorithm must take as least as much time as MAX-GAP.MAX-GAP is known to be in MAX-GAP is known to be in (n log n).(n log n).
Rectangle algorithm must take Rectangle algorithm must take (n log n) time(n log n) timefor specialized polygons. for specialized polygons.
[[Transforming yet another different problem yields bound for unspecialized polygons.]Transforming yet another different problem yields bound for unspecialized polygons.]
First attempt:First attempt: Establish weak (and loose) worst-case Establish weak (and loose) worst-case upper boundupper bound on the on the
problemproblem using an algorithm using an algorithm Establish strong (and loose) worst-case Establish strong (and loose) worst-case lower boundlower bound on the on the
problemproblem
Tighten bounds to make an “algorithm sandwich”Tighten bounds to make an “algorithm sandwich” Establish weak (but tighter) worst-case Establish weak (but tighter) worst-case O(n logO(n log22 n) n) upper upper
boundbound on the on the problemproblem using an algorithm using an algorithm Establish strong (and tighter) worst-case Establish strong (and tighter) worst-case lower boundlower bound on the on the
problemproblem by transforming a problem with known lower bound by transforming a problem with known lower bound
Summary
nn11 n log(n)n log(n) n logn log22(n)(n) 22nnnn55
bounds on problembounds on problem
Recent Improvement!Recent Improvement!
““Finding the Largest Axis-Aligned Rectangle in a Finding the Largest Axis-Aligned Rectangle in a Polygon in O(n log n) Time”Polygon in O(n log n) Time” Ralph Boland, Jorge UrrutiaRalph Boland, Jorge Urrutia
Canadian Conference on Computational Geometry, Canadian Conference on Computational Geometry, August 13-15, 2001August 13-15, 2001
nn11 n log(n)n log(n) n logn log22(n)(n) 22nnnn55
bounds on problembounds on problem
nn11 n log(n)n log(n) n logn log22(n) (n) 22nnnn55
TightTight bound on problem bound on problem
For More InformationFor More Information
Computational Geometry:Computational Geometry: Graduate CS course in Computational Geometry Graduate CS course in Computational Geometry offered at UMass Lowell in Spring ’01, Spring offered at UMass Lowell in Spring ’01, Spring
‘04‘04 Introductory texts:Introductory texts:
Computational Geometry in CComputational Geometry in C (O’Rourke)(O’Rourke) Computational Geometry: An IntroductionComputational Geometry: An Introduction (Preparata & Shamos)(Preparata & Shamos)
Bibliography: ftp://ftp.cs.usask.ca/pub/geometry/Bibliography: ftp://ftp.cs.usask.ca/pub/geometry/ Software:http://www.geom.umn.edu/software/cglist/Software:http://www.geom.umn.edu/software/cglist/
My research:My research: http://www.cs.uml.edu/~kdanielshttp://www.cs.uml.edu/~kdaniels Journal paperJournal paper: “Finding the largest area axis-parallel rectangle in a polygon”: “Finding the largest area axis-parallel rectangle in a polygon”
((Computational Geometry: Theory and ApplicationsComputational Geometry: Theory and Applications)) Prof. Victor Milenkovic: Frequent co-author and former PhD advisorProf. Victor Milenkovic: Frequent co-author and former PhD advisor
http://www.cs.miami.edu/~vjmhttp://www.cs.miami.edu/~vjm