Lecture 16: Randomized Incremental Construction
Download
Report
Transcript Lecture 16: Randomized Incremental Construction
Randomized Algorithms
CS648
Lecture 16
Randomized Incremental Construction
(Backward analysis)
1
PROBLEM 1
FIND-MIN PROBLEM
2
Find-Min algorithm
A
1
2
Find-Min(A[1..๐])
{ ๐๐๐ ๏ A[1];
For ๐ = ๐ to ๐ do
{ if (A[๐] < ๐๐๐)
๐๐๐ ๏ A[๐] ;
}
return ๐๐๐;
}
๐โ๐
โฆ
๐ฟ: no. of times ๐๐๐ is updated.
๐ฟ๐ =
๐ if ๐๐๐ is updated in ๐th iteration
๐ otherwise
๐ฟ=๐+
๐>๐ ๐ฟ๐
๏จ๐ ๐ =๐+
=๐+
Probability that
โA[๐] is smaller than {A[๐],โฆ, A[๐ โ ๐]}โ
๐>๐ ๐[๐ฟ๐ ]
๐>๐ ๐(๐ฟ๐
= ๐)
??
3
Forward analysis for
First ๐ โ ๐ elements
๐(๐ฟ๐ = ๐)
A
1
2
Find-Min(A[1..๐])
{ ๐๐๐ ๏ A[1];
For ๐ = ๐ to ๐ do
{ if (A[๐] < ๐๐๐)
๐๐๐ ๏ A[๐] ;
}
return ๐๐๐;
}
โฆ
๐
๐โ๐
Notations:
โข ๐บ๐โ๐ : set of all subsets of A of size ๐ โ ๐.
โข For any ๐ โ ๐บ๐โ๐ ,
๐๐ : first ๐ โ ๐ elements of A are some
permutation of ๐.
Using Partition Theorem,
๐(๐ฟ๐ = ๐) = ๐โ๐บ๐โ๐ ๐(๐ฟ๐ = ๐ ๐๐
โ ๐(๐๐ )
4
Forward analysis for
๐(๐ฟ๐ = ๐)
๐ : a subset of ๐ โ ๐ elements.
๐(๐ฟ๐ = ๐ ๐๐ =
โGiven that first ๐ โ ๐ elements of A are some permutation of ๐, what is prob.
that ๐ฟ๐ = ๐ ?โ
For this event to happen, A[๐] must be smaller than every element of ๐.
๏จ ๐(๐ฟ๐ = ๐ ๐๐ depends upon ๐.
For example, if the smallest element of ๐ has rank ๐ in A, then
๐(๐ฟ๐ = ๐ ๐๐ = ?? ๐ โ ๐
๐โ๐+๐
Dependency on ๐ makes it hard to calculate
๐โ๐บ๐โ๐
๐(๐ฟ๐ = ๐ ๐๐
โ ๐(๐๐ )
5
Backward analysis for
First ๐ elements
๐(๐ฟ๐ = ๐)
A
1
2
Find-Min(A[1..๐])
{ ๐๐๐ ๏ A[1];
For ๐ = ๐ to ๐ do
{ if (A[๐] < ๐๐๐)
๐๐๐ ๏ A[๐] ;
}
return ๐๐๐;
}
โฆ
๐
๐โ๐
Notations:
โข ๐บ๐ : set of all subsets of A of size ๐.
โข For any ๐ โ ๐บ๐ ,
๐๐ : first ๐ elements of A are some
permutation of ๐.
Using Partition Theorem,
๐(๐ฟ๐ = ๐) = ๐โ๐บ๐ ๐(๐ฟ๐ = ๐ ๐๐ โ ๐(๐๐ )
6
Backward analysis for
๐(๐ฟ๐ = ๐)
๐ : a subset of ๐ โ ๐ elements.
๐(๐ฟ๐ = ๐ ๐๐ =
โGiven that first ๐ elements of A are some permutation of ๐, what is prob.
that ๐ฟ๐ = ๐ ?โ
For this event to happen, the smallest element of ๐ must appear at A[๐].
๏จ ๐(๐ฟ๐ = ๐ ๐๐ = ๐( โthe smallest element? ?of ๐ appear at A[๐]โ )
Fact: A is permuted randomly uniformly
๏จ Every element of ๐ is equally likely to appear at place A[๐].
๐
๏จ ๐(๐ฟ๐ = ๐ ๐๐ = ??
๐
Same for each ๐
7
Backward analysis for
First ๐ elements
๐(๐ฟ๐ = ๐)
A
1
2
Find-Min(A[1..๐])
{ ๐๐๐ ๏ A[1];
For ๐ = ๐ to ๐ do
{ if (A[๐] < ๐๐๐)
๐๐๐ ๏ A[๐] ;
}
return ๐๐๐;
}
โฆ
๐
๐โ๐
Notations:
โข ๐บ๐ : set of all subsets of A of size ๐.
โข For any ๐ โ ๐บ๐ ,
๐๐ : first ๐ elements of A are some
permutation of ๐.
Using Partition Theorem,
๐(๐ฟ๐ = ๐) = ๐โ๐บ๐ ๐(๐ฟ๐ =๐๐ ๐๐ โ ๐(๐๐ )
=
๐
๐
๐
๐
๐
๐โ๐บ๐
๐(๐๐ )
= โ
๐
8
PROBLEM 2
CLOSEST PAIR OF POINTS
9
Closest Pair of Points
Problem Definition:
Given a set ๐ท of ๐ > ๐ points in plane, compute the pair of points with
minimum Euclidean distance.
Randomized algorithm:
โข O(๐) : Randomized Incremental Construction based algorithm
10
๐th iteration
Grid structure for first ๐ โ ๐ points
๐น๐โ๐
๐น๐โ๐
11
Analysis of ๐th iteration
Closest-pair-algorithm(๐ท)
Let <๐๐ ,๐๐ ,โฆ,๐๐ > be a uniformly random permutation of ๐ท;
๐น๐ ๏ distance(๐๐ ,๐๐ );
๐ฎ ๏ Build_Grid(๐น๐ , {๐๐ , ๐๐ });
For ๐ = ๐ to ๐ do
{
Step 1: locate the cell of the grid ๐ฎ containing ๐๐ ;
Step 2: find the point ๐ โ {๐๐ , โฆ , ๐๐โ๐ } closest to ๐๐ ;
let ๐น = distance(๐, ๐๐ );
Step 3: If ๐น > ๐น๐โ๐
๐น๐ ๏ ๐น๐โ๐ ; Insert(๐๐ ,๐ฎ);
Else
๐น๐ ๏ ๐น;
๐ฎ๏ Build_Grid(๐น, {๐๐ , โฆ , ๐๐ });
}
return ๐น๐ ;
O(1)
O(1)
O(1)
๐๐ for constant ๐
12
running time of ๐th iteration
๐ฟ๐ : running time of ๐th iteration
O(1) + ๐๐ โ ๐(๐น๐ < ๐น๐โ๐ )
E[๐ฟ๐ ] = ??
Question: What is ๐(๐น๐ < ๐น๐โ๐ ) ?
13
Forward analysis for
๐(๐น๐ < ๐น๐โ๐ )
Closest-pair-algorithm(๐ท)
Let <๐๐ ,๐๐ ,โฆ,๐๐ > be a uniformly random permutation of ๐ท;
๐น๐ ๏ distance(๐๐ ,๐๐ );
๐ฎ ๏ Build_Grid(๐น๐ , {๐๐ , ๐๐ });
For ๐ = ๐ to ๐ do
{
Step 1: locate the cell of the grid ๐ฎ containing ๐๐ ;
Step 2: find the point ๐ โ {๐๐ , โฆ , ๐๐โ๐ } closest to ๐๐ ;
let ๐น = distance(๐, ๐๐ );
Step 3: If ๐น > ๐น๐โ๐
๐น๐ ๏ ๐น๐โ๐ ; Insert(๐๐ ,๐ฎ);
Else
๐น๐ ๏ ๐น;
๐ฎ๏ Build_Grid(๐น, {๐๐ , โฆ , ๐๐ });
}
return ๐น๐ ;
14
Forward analysis for
๐(๐น๐ < ๐น๐โ๐ )
๐ : a subset of ๐ โ ๐ points from ๐ท.
๐๐ :
๐น๐โ๐
first ๐ โ ๐ points of ๐ท are some permutation of ๐
๐(๐น๐ < ๐น๐โ๐ ๐๐ = ??Depends upon ๐
๐น๐โ๐
Calculating ๐(๐น๐ < ๐น๐โ๐ ) :
Let ๐บ๐โ๐ be the set of all subsets of ๐ท of size ๐ โ ๐.
๐(๐น๐ < ๐น๐โ๐ )=
๐โ๐บ๐ ๐(๐น๐
< ๐น๐โ๐ ๐๐ โ ๐(๐๐ )
Grid structure for first ๐ โ ๐ points
15
Backward analysis for
๐(๐น๐ < ๐น๐โ๐ )
Closest-pair-algorithm(๐ท)
Let <๐๐ ,๐๐ ,โฆ,๐๐ > be a uniformly random permutation of ๐ท;
๐น๐ ๏ distance(๐๐ ,๐๐ );
๐ฎ ๏ Build_Grid(๐น๐ , {๐๐ , ๐๐ });
For ๐ = ๐ to ๐ do
{
Step 1: locate the cell of the grid ๐ฎ containing ๐๐ ;
Step 2: find the point ๐ โ {๐๐ , โฆ , ๐๐โ๐ } closest to ๐๐ ;
let ๐น = distance(๐, ๐๐ );
Step 3: If ๐น > ๐น๐โ๐
๐น๐ ๏ ๐น๐โ๐ ; Insert(๐๐ ,๐ฎ);
Else
๐น๐ ๏ ๐น;
๐ฎ๏ Build_Grid(๐น, {๐๐ , โฆ , ๐๐ });
}
return ๐น๐ ;
16
Backward analysis for
๐(๐น๐ < ๐น๐โ๐ )
๐ : a subset of ๐ points from ๐ท.
๐๐ : first ๐ points of ๐ท are some permutation of ๐
๐น๐
๐
๐(๐น๐ < ๐น๐โ๐ ๐๐ = ??
๐
Calculating ๐(๐น๐ < ๐น๐โ๐ ) :
Let ๐บ๐ be the set of all subsets of ๐ท of size ๐.
๐น๐
๐(๐น๐ < ๐น๐โ๐ )=
๐โ๐บ๐ ๐(๐น๐
=
๐โ๐บ๐
๐
Grid structure for first ๐ points
=๐โ
๐โ๐บ๐
๐
๐
< ๐น๐โ๐ ๐๐ โ ๐(๐๐ )
โ ๐(๐๐ )
๐(๐๐ )
=
๐
๐
17
running time of ๐th iteration
๐ฟ๐ : running time of ๐th iteration
E[๐ฟ๐ ] = O(1) + ๐๐ โ ๐(๐น๐ < ๐น๐โ๐ )
= O(1) + ๐๐ โ
๐
๐
= O(1)
Expected running time of the algorithm :
E[๐ฟ๐ ]
๐โค๐
=
O(1)
= O(๐)
๐โค๐
Theorem:
There exists a linear time Las Vegas algorithm to compute closest pair of
points in plane.
18
RANDOMIZED INCREMENTAL
CONSTRUCTION
19
Randomized Incremental Construction
โข Permute the elements of input randomly uniformly.
โข Build the structure incrementally.
โข Keep some data structure to perform ๐th iteration efficiently.
โข Use Backward analysis to analyze the expected running time.
20
Randomized Incremental Construction
โข Convex Hull of a set of points
โข Trapezoidal decomposition of a set of segments.
โข Convex polytope of a set of half-planes
โข Smallest sphere enclosing a set of points.
โข Linear programming in finite dimensions.
21
PROBLEM 3
CONVEX HULL OF POINTS
22
Convex hull of Points
Problem definition:
Given ๐ points in a plane, compute a convex polygon of smallest area that
encloses all the points.
23
Convex hull of Points
Deterministic algorithm:
โข O(๐ ๐ฅ๐จ๐ ๐) time algorithm.
โข Many algorithms exist:
Grahams Scan, Jarvisโs march, divide and conquer,โฆ
Randomized algorithm:
โข O(๐ ๐ฅ๐จ๐ ๐) time algorithm.
โข Based on Randomized Incremental Construction.
โข Generalizable to higher dimensions.
24
Randomized algorithm for convex hull
Convex-hull-algorithm(๐ท)
{
Let <๐๐ ,๐๐ ,โฆ,๐๐ > be a uniformly random permutation of ๐ท;
๐ฏ๏ triangle(๐๐ ,๐๐ , ๐๐ );
For ๐ = ๐ to ๐ do
insert ๐๐ and update ๐ฏ
return ๐ฏ;
}
25
A simple exercise from geometry
Exercise: Given a line L and two points p and q, determine whether the
points lie on the same/different sides of L.
L
p
q
q
๐ = ๐๐ + ๐
26
Conflict graph : a powerful data structure
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
27
Before entering the for loop
28
Before entering the for loop
๐ โ ๐ points
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
29
INSERTING ๐TH POINT
30
๐th iteration
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
31
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
32
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
33
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
34
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
35
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
36
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
37
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
38
๐th iteration
๐๐
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
39
๐th iteration
๐ โ ๐ points
๐๐
cones
๐๐
๐๐
๐โฒ
๐โฒ
๐"
๐๐
๐๐
๐"
๐๐
๐๐
๐๐
40
Running time of ๐th iteration
Running time of ๐th iteration is of the order of
โข Number of edges destroyed
Total time for ๐ iterations = O(๐)
โข Number of new edges created
โข Number of points in the two adjacent cones that get created
๐ฟ๐
Question: What is the max. number of new edges created in an iteration ?
Answer: 2
๏จ Number of edges created during the algorithm = O(๐)
Since every edge destroyed was once created, so
Total number of edges destroyed < Total number of edges decreated
41
Backward analysis of ๐th iteration
๐ : a subset of ๐ points from ๐ท.
๐๐ : first ๐ points of ๐ท are some
permutation of ๐
๐[๐ฟ๐ ๐๐ = ??
42
Backward analysis of ๐th iteration
๐๐
๐๐
๐ : a subset of ๐ points from ๐ท.
๐๐ : first ๐ points of ๐ท are some
permutation of ๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐[๐ฟ๐ ๐๐ = ??
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
43
Backward analysis of ๐th iteration
๐๐
๐๐
๐ : a subset of ๐ points from ๐ท.
๐๐ : first ๐ points of ๐ท are some
permutation of ๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐[๐ฟ๐ ๐๐ = ??
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
44
Backward analysis of ๐th iteration
๐๐
๐๐
๐ : a subset of ๐ points from ๐ท.
๐๐ : first ๐ points of ๐ท are some
permutation of ๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
Calculating ๐[๐ฟ๐ ] :
๐๐
๐๐
๐๐
๐๐
๐๐
๐๐
๐[๐ฟ๐ ๐๐ = ??๐(๐ โ ๐)
๐
๐๐
Let ๐บ๐ be the set of all subsets of
๐ท of size ๐.
๐[๐ฟ๐ ] =
=
=
๐โ๐บ๐ ๐[๐ฟ๐
๐โ๐บ๐
๐(๐โ๐)
๐
๐๐ โ ๐(๐๐ )
๐(๐โ๐)
โ
๐
๐(๐๐ )
45
Running time of the algorithm
Expected running time of ith iteration
= ๐[๐ฟ๐ ] + O(1)
= O(
๐โ๐
)
๐
Expected running time of the algorithm = O(๐ ๐ฅ๐จ๐ ๐ )
Theorem:
There is an O(๐ ๐ฅ๐จ๐ ๐ ) time Las Vegas algorithm for computing convex hull.
46
47