Professional Documents
Culture Documents
Lecture 3 CS345A 2023
Lecture 3 CS345A 2023
Algorithms-II : CS345A
Lecture 3
Divide and Conquer Paradigm – II
- Closest Pair of Points (Final algorithm)
- Non-Dominated Points
- Convex Hull
1
Recap of the last lecture
2
The combine step
𝜹
𝜹
𝜹
𝜹
Sort all points of the right strip in
𝜹𝑳 increasing order of -coordinate.
𝜹
𝜹
𝜹
(𝑥′ , 𝑦 ′ ) Binary search for ()
𝒑 𝜹
𝜹Binary
𝑹
search for ()
𝜹
𝜹
min() 3
Divide and Conquer based algorithm
CP-Distance()
{ If (| |=1 ) return infinity;
{ Compute -median of ;
Split-by--median(); + 2 T(||/2) time
CP-Distance() ; Divide step
CP-Distance() ;
min(, );
strip of ;
strip of ;
Sorted array of ;
For each ,
time
y-coordinate of ;
Search for points with y-coordinate within ; Combine/conquer step
Compute distance from to each of these points;
Update accordingly;
return ;
}
4
Running time of the algorithm
What is the recurrence for running time?
c
Theorem:
There exists an O( ) time algorithm to compute the closest pair distance of
points in plane.
5
The combine step in O() time
If the two strips are already sorted
𝜹𝑳
𝜹𝑹
𝜹 𝜹
min() 6
The combine step in O() time
If the two strips are already sorted
𝜹
𝒑
𝜹𝑳
𝜹𝑹
𝜹 𝜹
min() 7
The combine step in O() time
Tool 2 ?
𝜹
¿𝜹
𝒑
𝜹
Fact : At most consecutive points need to be considered.
8
The combine step in O() time
If the two strips are already sorted
𝜹𝑳
𝜹𝑹
𝜹 𝜹
min() 9
The combine step in O() time
If the two strips are already sorted ?
𝜹𝑳
𝜹𝑹
𝜹 𝜹
min() 10
Inspiration from Merge sort
Merge
11
The combine step in O() time
𝜹𝑳
𝜹𝑹
𝜹𝑳 𝜹𝑳
12
Divide and Conquer based algorithm
CP-Distance()
{ If (| |=1 ) return (, );
Compute -median of ;
Split-by--median();
(, ) CP-Distance() ;
(, ) CP-Distance() ; + 2 T(||/2) time
min(, ); -Merge(, ); Divide step
strip of ; strip of ;
While( and )
{ first() ; first();
If( y() y() )
{ Compute distance from to the first 4 points in ;
Update accordingly;
time
Remove from ;
} conquer step
else … //similar processing for point ;
}
return (, )
}
13
Conclusion
Theorem:
There exists an O( ) time algorithm to compute the closest pair distance of
points in plane.
14
PROBLEM 2
Non-dominated Points
15
The Non-Dominated Points
Let be a set of points in x-y plane.
Definition: point is said to be a non-dominated point if
there is no point such that
x() > x()
and y() > y()
16
The Non-Dominated Points
y
(0,0) x
17
The Non-Dominated Points
y
(0,0) x
18
The Non-Dominated Points
A simpler problem:
Design an efficient algorithm to report any non-dominated point from .
19
The Non-Dominated Points
y
O() time
(0,0) x
20
A simple algorithm for
all non-dominated points
21
A Simple Algorithm
y
(0,0) x
22
A Simple Algorithm
y : no. of non-dominated points
(0,0) x
23
A Divide and Conquer algorithm
24
A Divide and Conquer algorithm
25
The Divide step
y
O() time
(0,0) x
Left half set points points Right half set
26
Solving the Subproblems recursively
y
2 T() time
(0,0) x
Left half set points points Right half set
27
The conquer step
y
O() time
(0,0) x
Left half set points points Right half set
28
The time complexity of the algorithm
y
T() = c + 2 T(/2)
Time complexity = O( )
(0,0) x
Left half set points points Right half set
29
Theorem:
There exists an O( ) time algorithm to compute non-dominated
points for a given set of points in a plane.
Homework:
1. Write a neat and complete pseudocode of the algorithm.
Check out the first worked out assignment on the course website that
addresses the above question.
30
PROBLEM 3
Convex Hull
31
A Convex Polygon
Definition: A polygon is convex if for any two points belonging to the polygon,
the line segment joining them is inside the polygon.
32
Convex hull
Definition: Convex polygon of smallest area enclosing a set of points.
34
Tool 2
𝑦 =𝑚𝑥 +𝑐
𝑟 =(𝑎 2 , 𝑏2)
35
Homework
36