Lecture-2-CS602-Divide-and-Conquer-I-Closest-pair-distance-FINAL-VERSION
Lecture-2-CS602-Divide-and-Conquer-I-Closest-pair-distance-FINAL-VERSION
CS602
Lecture 2
Divide and Conquer Paradigm – I
- Closest Pair of Points
1
Homework from last class
2
Multiple Merit Lists
19 IITs
31 NITs
18 IIITs
33989 seats 1304127 candidates
18 OtherGFTIs
3
Fairness
Choice list of Mohan
p q p
Mohan
q
Ram
Ram Mohan
4
How to tackle Multiple Merit Lists using
“Single Merit list algorithm”
5
A common man’s algorithm
Allocation Allocation No
IITs NITs
Should we
remove from
NITs for future ?
Repeat
or ?
I prefer to .
𝒑 𝒓 𝒒 6
Choice list for IITs Choice list for NITs
A common man’s algorithm
Allocation_IIT();
Allocation_NIT();
; Round
While ( ) and Round )
{ For each do
{ is asked to choose between the two choices;
The preference list of is trimmed accordingly;
}
Allocation_IIT();
Allocation_NIT(); Round Round +
;
}
7
Homework
8
Divide and Conquer paradigm
9
An Overview
1. Divide the problem instance into two or more instances of the same problem.
10
Example Problems
1. Merge Sort
11
Divide and Conquer Paradigm
(Advanced Problems)
• Geometric Problems:
1. Closest Pair Distance
2. Non-dominated Points
3. Convex Hull
(𝑥 𝑗 , 𝑦 𝑗 )
O() time
( 𝑥𝑖 , 𝑦𝑖)
𝑥
13
The Closest Pair Distance Problem
𝑥
14
The Closest Pair Distance Problem
Problem Definition:
Given a set of points in plane,
compute the minimum Euclidean distance among all pairs of points.
Algorithms:
• O() : Trivial algorithm
• O() : Divide and Conquer based algorithm
15
Question 1
Tool 1 A fact from high school geometry
Fact :
Let and be any two points.
• If , distance()
• If , distance()
16
A discrete math exercise
Exercise:
What is the maximum number of points that can be placed in a unit square
such that each pair of them is separated by distance at least 1 ?
17
A discrete math exercise
Tool 2
Exercise:
What is the maximum number of points that can be placed in a𝜹unit − square
such that each pair of them is separated by distance at least 1𝜹 ?
Answer: 4.
1
√2
𝜹
1
18
Question 2
Tool 3 A fundamental question about data structure ?
Question:
While solving an algorithmic problem, when do we feel the need of an
efficient data structure ?
Answer:
when the algorithm involves “many” operations of same type on a given data.
19
A DIVIDE AND CONQUER ALGORITHM
FOR
Closest Pair Distance
20
The divide step
𝑥
21
Solving the problem in 1-dimension
Median of points.
𝑦
𝑥
Left half set points points 22
Right half set
Solving the problem in 1-dimension
We can not afford to compute
distance
We need to consider onlybetween
one pointeach
frompoint of half set
the left
T() = c + 2 T(/2) thethe
()and one point from leftright
halfhalf
set and eachyou
set. Can point
spot them ?
of the right half set.
𝜹𝑳 𝜹𝑹
𝑥
Left half set points points 23
Right half set
How to extend to 2-dimensions
𝑥
24
The divide step
𝑥
25
Solving the 2 smaller instances
𝜹𝑳
𝜹𝑹
Tool 1
¿𝜹
𝜹𝑳
𝜹𝑹
𝜹𝜹
min() 27
The combine step
Potentially points in each strip
𝜹𝑳
𝜹𝑹
𝜹
𝜹
min() 28
The combine step
Do we need to compute distance from
to each point of the red strip ?
Tool 1
𝜹𝑳
𝒑
𝜹𝑹
𝜹
𝜹
min() 29
The combine step
Tool 1
𝜹𝑳
𝜹
𝒑 𝜹
𝜹𝑹
𝜹
𝜹
min() 30
The combine step
But
Howwemany
needpoints
to do this
lie intask
for each
thesepoint of left? strip.
2 squares
Tool 2
𝜹𝑳
𝜹
′ ′
𝜹
𝜹
(𝑥 , 𝑦 ) Binary search for ()
𝒑 𝜹
𝜹Binary
𝑹
search for ()
𝜹
𝜹
min() 32
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 ;
}
33
Running time of the algorithm
What is the recurrence for running time?
Theorem:
There exists an O( ) time algorithm to compute the closest pair distance of
points in plane.
34