lecture 16
TRANSCRIPT
Randomized AlgorithmsCS648
Lecture 16Randomized Incremental Construction
(Backward analysis)
1
PROBLEM 1FIND-MIN PROBLEM
2
Find-Min algorithm
Find-Min(A[1..]){ A[1]; For to do { if (A[] ) A[] ; } return ; }
: no. of times is updated.
3
??
𝒏−𝟏1 2 …
A
Probability that “A[] is smaller than {A[],…, A[]}”
Forward analysis for
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
𝒊 𝒏−𝟏1 2 …
A
First elements
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 = ??
5
𝒌−𝟏𝒏−𝒊+𝟏
Dependency on makes it hard to calculate
Backward analysis for
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
𝒊 𝒏−𝟏1 2 …
A
First elements
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[].
=
Every element of is equally likely to appear at place A[].
= ??
7
“the smallest element of appear at A[]”
𝟏𝒊
Fact: A is permuted randomly uniformly
Same for each
Backward analysis for
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
𝒊 𝒏−𝟏1 2 …
A
First elements
PROBLEM 2CLOSEST 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
11
𝜹𝒊−𝟏
𝜹𝒊−𝟏
Grid structure for first points
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 ;
12
O(1)
O(1)
O(1)
for constant
running time of th iteration
: running time of th iteration
E[] = ??
Question: What is ?
13
O(1) + ∙
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
= ??
Calculating :
Let be the set of all subsets of of size .
=
15
𝜹𝒊−𝟏
𝜹𝒊−𝟏
Grid structure for first points
Depends upon
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 .
= = =
17
𝜹𝒊
𝜹𝒊
𝟐𝒊
= Grid structure for first points
running time of th iteration
: running time of th iteration
E[] = O(1) + ∙ = O(1) + ∙ = O(1)
Expected running time of the algorithm :
Theorem:There exists a linear time Las Vegas algorithm to compute closest pair of points in plane.
18
¿∑𝒊≤𝒏
O(1) =
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 3CONVEX 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.
26
L p
q
q
𝒚=𝒎𝒙+𝒄
27
Conflict graph : a powerful data structure
𝒄𝟒
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
conespoints𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟏
Before entering the for loop
28
Before entering the for loop
29
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟏
𝒄𝟐
𝒄𝟑
points cones
INSERTING TH POINT
30
th iteration
31
𝒄𝟏
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
th iteration
32
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
33
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
34
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
35
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
36
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
37
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
38
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
39
𝒄𝟏
𝒄𝟐
𝒄𝟑
𝒄𝟒
𝒄𝟓
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄𝟐
𝒄𝟑
𝒄𝟒𝒄𝟓𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
th iteration
40
𝒄𝟏
𝒄 ′
𝒄
𝒄𝟔
𝒄𝟕
𝒄𝟖
𝒄 ′
𝒄
𝒄𝟔
𝒄𝟕
𝒄𝟖
points cones𝒄𝟏
Running time of th iterationRunning time of th iteration is of the order of
• Number of edges destroyed
• 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
Total time for iterations = O()
𝑿 𝒊
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