Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

Design and Analysis of Algorithms

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

a Divide and Conquer algorithm for


Closest Pair Distance

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?

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



T() = O( )

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.

Note: There exists a randomized algorithm with O() expected time.

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()

Problem: Design an efficient algorithm to compute all non-dominated points


of set .

Assumption: No 2 points have the same x-coordinates or y-coordinates.

16
The Non-Dominated Points
y

(0,0) x
17
The Non-Dominated Points
y

(0,0) x
18
The Non-Dominated Points

Let be a set of points in x-y plane.

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

Time complexity = O()


O() ?

(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.

2. Can we improve the time complexity beyond O( ) ?


Ponder over it.

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.

Problem: Design an efficient algorithm to compute the convex hull of .

Assumption: No three points are colinear.


33
Tool 1
Let .
Convex Hull of must be fully contained inside the convex hull of .

34
Tool 2

• Given a non-vertical line and a point =(), how to determine


whether lies above or below ?
time
𝑞=(𝑎1 , 𝑏1)

𝑦 =𝑚𝑥 +𝑐

𝑟 =(𝑎 2 , 𝑏2)

Corollary: Given two points and a line , it takes time to determine


whether they lie on the same side or different sides of .

35
Homework

1. Try to design an O() time algorithm to compute the convex hull.

2. Try to make an attempt to design an O( ) time algorithm based on


Divide and Conquer paradigm to compute the convex hull.

We shall discuss them in the next lecture .

36

You might also like