Professional Documents
Culture Documents
Algorithms-II : CS345A
Lecture 4
• Divide and Conquer Paradigm - III
• Convex Hull
• Algorithm to multiply 2 polynomials
1
PROBLEM 3
Convex Hull
2
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.
3
Convex hull
Definition: Convex polygon of smallest area enclosing a set of points.
8
Tool 2
𝑦 =𝑚𝑥 +𝑐
𝑟 =(𝑎 2 , 𝑏2)
9
Convex hull
…
10
Convex hull
11
Convex hull
12
Convex hull
13
Convex hull
O() time
Homework:
Prove the correctness of the algorithm.
14
DIVIDE AND CONQUER ALGORITHM
Convex Hull
15
The Divide Step
O() time
2 T() time
20
The right half set is a point
21
The right half set is a point
Tool 1
𝑞
Up
p er
tan
ge
nt
𝑝
ent
ta ng
wer
Lo
𝑟
22
The right half set is a point
Upper Hull
Up
p er
tan
ge
nt
Lemma:
Upper tangent from will be incident on one point of the upper hull.
23
The right half set is a point
𝑝
t
gen
an
rt
owe
L
25
How to compute the upper tangent ?
26
How to compute the upper tangent ?
𝑠
Consider successor of
𝑤 𝑞
𝑢
𝑡 𝑝
𝑟
𝑠
Consider predecessor of
𝑤 𝑞
𝑢
𝑡 𝑝
𝑟
𝑠
Does it remind you
𝑤 𝑞 Up something “very basic” you
p er learnt in the past ?
tan
ge
nt
𝑡 𝑝
𝑟
Binary Search
We perform binary search on the upper hull to find the upper tangent from
29
O(log ) time to find upper tangent
Going back to the original problem
Conquer Step
30
The Conquer step
gent
Upper tan
Lower tangen
t
points points 31
How to compute the upper tangent ?
O(log ) time
𝑤 𝑥
𝑣
𝑢
𝑦
points points 32
Running time of the algorithm
What is the recurrence for running time?
c
Theorem:
There exists an O( ) time algorithm to compute the convex hull of points in
plane.
33
Homework
34
Problem 4
An algorithm for
multiplying two polynomials
35
Multiplying two polynomials
Definition (polynomial of degree less than )
Compute
where =
𝑎0 𝑏𝑖 +𝑎1 𝑏 𝑖−1 +𝑎2 𝑏𝑖 −2 +…+𝑎𝑖−1 𝑏1 +𝑎𝑖 𝑏0 O() time
Trivial algorithm: O( )
Aim: O( )
Applications:
• Signal processing (Discrete Fourier Transform)
• As practical as sorting and searching
• Multiplication of two integers.
36
Divide Step
Attempt 1
𝑨 ( 𝑥 ) =𝑎 0 +𝑎 1 𝑥+ 𝑎2 𝑥2 +… 𝑎 𝑛− 1 𝑥𝑛 −1
( ) ( ( ))
𝑛 𝑛 𝑛 𝑛
−1 −1
First terms
𝑎 0 +…+𝑎 𝑛 of
𝑥 2 2 Last
𝑥𝑎 𝑛⋅ 𝑥𝑎 +…
2terms
+
𝑛 …𝑎𝑎𝑛of
𝑛 − 1𝑥
−1
𝑥 𝑛2
−1
−1
2 2 2
𝑨 first ( 𝑥 ) 𝑨 second ( 𝑥 )
37
Homework
for those aiming beyond A*
Hint:
Recall ESO207
38