You are on page 1of 29

Design and Analysis of Algorithms

Algorithms-II : CS345A
Website: hello.iitk.ac.in

Lecture 4
• Algorithm for Joint Seat Allocation (final discussion)
• Divide and Conquer Paradigm - III
• Convex Hull

1
Homework from the last class

1. Are there multiple fair allocations if there are multiple merit lists ?

Ponder over it …

2
Multiple merit lists

IIT C B A A IIT ARCH NIT


NIT A C B B NIT IIT ARCH
ARCH B A C C ARCH NIT IIT
Merit Lists Choice Lists

A B C

Allocation Allocation Allocation


IIT C IIT A IIT B

NIT A NIT B NIT C

ARCH B ARCH C ARCH A

Candidate Pessimal Candidate Optimal


3
Homework

• Which allocation does the software industry’s algorithm output ?


– Candidate Optimal
– Candidate Pessimal
– None of the above
Ponder over it …

• Design an algorithm that outputs the candidate optimal allocation.


– Does such an allocation even exist ?

4
PROBLEM 3
Convex Hull

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

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


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

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

9
DIVIDE AND CONQUER ALGORITHM

Convex Hull

10
The Divide Step

O() time

Left half set points points Right half set


11
Solving the subproblems recursively

2 T() time

Left half set points points Right half set


12
The Conquer step

Left half set points points Right half set


13
The Conquer step

Left half set points points Right half set


14
A simpler problem
The right half set is a point

15
The right half set is a point

16
The right half set is a point

Tool 1
𝑞
Up
p er
tan
ge
nt

𝑝
e nt
g
tan
wer
Lo
𝑟

17
The right half set is a point

Upper Hull

Up
p er
tan
ge
nt

Lemma:
Upper tangent from will be incident on exactly one point of the upper hull.
18
The right half set is a point

𝑝
t
gen
an
rt
owe
L

Lemma: Lower Hull


Lower tangent from 𝑝 will be incident on exactly one point of the Lower hull.
19
How to compute the upper tangent ?

20
How to compute the upper tangent ?

Tool 2 𝑠
𝑤 𝑞

𝑡 𝑝
𝑟

Worst case time complexity for finding upper tangent: O() time.
We need better time complexity.
21
How to compute the upper tangent ?

𝑠
𝑤 𝑞

𝑡 𝑝
𝑟

22
How to compute the upper tangent ?

𝑠
𝑤 𝑞

𝑡 𝑝
𝑟

23
How to compute the upper tangent ?

𝑠
𝑤 𝑞U O(log ) time
pp
er
tan
ge
nt

𝑡
binary search
𝑝
𝑟

24
Going back to the original problem

Conquer Step

25
The Conquer step

gent
Upper tan

Lower tangen
t

points points 26
How to compute the upper tangent ?

O(log ) time

𝑤 𝑥
𝑣

𝑢
𝑦

points points 27
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 convex hull of points in
plane.

28
Homework

1. Provide complete details of the “conquer” part of the algorithm.

2. What data structure will be used to store convex hull ?

3. Try to modify the algorithm to achieve O( ) time complexity.

29

You might also like