0% found this document useful (0 votes)
2 views

Lecture-2-CS602-Divide-and-Conquer-I-Closest-pair-distance-FINAL-VERSION

The document discusses the Divide and Conquer paradigm, specifically focusing on the Closest Pair of Points problem. It outlines the algorithm for solving this problem, including the divide, conquer, and combine steps, and presents tools necessary for understanding the algorithm's implementation. Additionally, it poses homework questions related to the algorithm's correctness and time complexity analysis.

Uploaded by

Virtuous leader
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture-2-CS602-Divide-and-Conquer-I-Closest-pair-distance-FINAL-VERSION

The document discusses the Divide and Conquer paradigm, specifically focusing on the Closest Pair of Points problem. It outlines the algorithm for solving this problem, including the divide, conquer, and combine steps, and presents tools necessary for understanding the algorithm's implementation. Additionally, it poses homework questions related to the algorithm's correctness and time complexity analysis.

Uploaded by

Virtuous leader
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Design and Analysis of Algorithms

CS602

Lecture 2
Divide and Conquer Paradigm – I
- Closest Pair of Points

1
Homework from last class

1. The seat allocation algorithm for the single merit list.?

2. Can you now tackle the problem of multiple merit lists ?

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

Merit list of programme q

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

1. Transform the common man’s algorithm to just 1 round ?

2. Analyse the common man’s algorithm. In particular, try to


prove its correctness.

8
Divide and Conquer paradigm

9
An Overview

1. Divide the problem instance into two or more instances of the same problem.

2. Solve each smaller instance recursively (base case suitably defined).

3. Combine the solutions of the smaller instances


to get the solution of the original instance.

10
Example Problems

1. Merge Sort

2. Multiplication of two -bit integers.

3. Counting the number of inversions in an array.

4. Finding median of numbers in linear time.

11
Divide and Conquer Paradigm
(Advanced Problems)

• Geometric Problems:
1. Closest Pair Distance
2. Non-dominated Points
3. Convex Hull

• Number theoretic Problem


1. Multiplication of 2 Polynomials
12
Distance between 2 points

(𝑥 𝑗 , 𝑦 𝑗 )
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

We shall use 3 tools to design this algorithm.


Please make sure you internalize them well.

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

𝜹𝑳

𝜹𝑹

points  min() points 26


Left half set Right half set
The combine step

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

𝜹𝑳

It will take time to compute points only


these points for a given . 𝜹
𝒑 𝜹
𝜹𝑹
𝜹
𝜹
 min() 31
The combine step
But we need to do this task
for each point of left strip.
Tool 3 𝜹
𝜹
𝜹
𝜹
Sort all points of the right strip in
𝜹𝑳 increasing order of -coordinate.

𝜹
′ ′
𝜹
𝜹
(𝑥 , 𝑦 ) 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?

T() = c log + 2 T(/2)



T() = O( )

Theorem:
There exists an O( ) time algorithm to compute the closest pair distance of
points in plane.

Homework: Try to improve the time complexity of the algorithm to O( )

34

You might also like