Lecture 6
Lecture 6
Algorithms-II : CS345A
Lecture 6
Divide and Conquer Paradigm - V
1
Recap from Lecture 1
An algorithm for
multiplying two polynomials
2
Polynomial Evaluation Problem
Given a polynomial of degree less than in coefficient representation,
Assumption:
• is a power of 2.
3
A DIVIDE AND CONQUER ALGORITHM
FOR
Polynomial Evaluation Problem
4
Divide Step
Idea ?
2
𝑨 ( 𝑥 )=𝑎 0 + 𝑎1 𝑥 +𝑎 2 𝑥 +… 𝑎𝑛− 1 𝑥
𝑛 −1
𝑺
5
Divide Step
Attempt 1
2
𝑨 ( 𝑥 )=𝑎 0 + 𝑎1 𝑥 +𝑎 2 𝑥 +… 𝑎𝑛− 1 𝑥
𝑛 −1
𝑺
( ) ( ( ))
𝑛 𝑛 𝑛 𝑛
−1 −1
First terms
𝑎0 + …+𝑎 𝑛 of𝑥 2
𝑥𝑎 𝑛⋅ 𝑥Last
2
𝑎 ++…
2 terms
… 𝑎𝑎𝑛of
𝑛 𝑛
−1− 1𝑥𝑥 𝑛2
−1
−1
2 2 2
𝑨 first ( 𝑥 ) 𝑨 second ( 𝑥 )
• Evaluating at
• Evaluating at
Evaluating at = • Evaluating at
O() time O() time
O() time
6
Homework from last class
7
The Recursion Tree points
for
evaluation
() + () degree
𝑨 ¿ 𝒏 𝑺𝒏
𝑨 first 𝑨 second ¿ 𝒏/ 𝟐 𝑺 𝒏
¿ 𝒏/ 𝟒𝑺 𝒏
¿ 𝟏𝑺 𝒏
8
Divide Step
Attempt 2
2
𝑨 ( 𝑥 )=𝑎 0 + 𝑎1 𝑥 +𝑎 2 𝑥 +… 𝑎𝑛− 1 𝑥
𝑛 −1
𝑺
( 𝑎 0+ 𝑎 2 𝑥All2+even
…+ 𝑎𝑛 −of2 𝑥 𝑛 −2 )
terms ¿
) All odd terms of
2𝑖
2 𝑖 2 𝑖
2𝑖
𝑎 22𝑖𝑖(𝑥𝑥 ) 𝑎 2 𝑖 +1 (𝑥
𝑥 )
=
=, () + ()
𝑺 =¿ { 𝑐 |𝑐 ∈ 𝑺 }
𝟐 𝟐 2
• Evaluating at ? 𝑺
Evaluating at =
• Evaluating at
O() time
9
The Recursion Tree points
for
evaluation
() + () degree
𝑨 ¿ 𝒏 𝑺𝒏
𝑨 𝑒𝑣𝑒𝑛 𝑨 𝑜𝑑𝑑 ¿ 𝒏/ 𝟐 𝑺 𝟐𝒏
¿ 𝒏/ 𝟒𝑺 𝟒𝒏
¿ 𝟏𝑺 𝒏𝒏
𝟒 𝒏
¿ 𝑺 ∨¿ Good start !
𝟒
But how to satisfy the
… remaining requirements …
𝒏
¿ 𝑺 ∨¿ 𝟏
11
Complex numbers
12
Complex numbers
√ 𝑎2 +𝑏2 Complex plane
𝑏
𝜑
𝑟
Addition 𝑎
= ? Vector addition
Multiplication
= 𝑟 1 𝑟?2 (cos (𝜙 1+ 𝜙 2)+𝑖 sin (𝜙 1 + 𝜙2 ))
13
Complex roots of unity
2𝜋
𝑛
Magnitude() = 1 1
Argument() = ? multiple of
𝑹 𝒏=¿
Unit circle
So must lie on the
unit circle. But
Principal rool of unity where exactly …
14
Complex roots of unity
1
1
𝜔4
𝜔3
𝜔3
3
𝜔4
2
𝜔 44
2
𝜔3 3
𝜔4
What is ? 𝑹𝟑 What is ? 𝑹𝟐
15
Complex roots of unity
𝟐 𝒏
𝑺 =
𝟐
Theorem:
If is odd 𝟒 𝒏
𝑺 =
𝟒
If is even
…
𝒏
𝑺 =𝟏 ?
𝑺=𝑹 𝒏
16
The Recursion Tree points
for
evaluation
() + () degree
𝑨 ¿ 𝒏 𝑹𝒏
𝑨 𝑒𝑣𝑒𝑛 𝑨 𝑜𝑑𝑑 ¿ 𝒏/ 𝟐 𝑹 𝒏
𝟐
¿ 𝒏/ 𝟒𝑹 𝒏𝟒
¿ 𝟏𝑹 𝟏
17
O() time
<> <>
Coefficient <>
represntation
?
O( log ) time Done
O( log ) time
{}
{} {}
O() time
18
Interpolation
There is a polynomial
with ’s unknown.
{}
Aim: To compute ’s .
Interestingly, Polynomial Interpolation can be solved using
Polynomial Evaluation only .
19
Interpolation
20
Interpolation
Solution: Define a polynomial
where .
Analyse for to compute ’s. H
O
M
{} E
W
Hint: If and are such that ……….., then O
R
0 k
21
Optional Homework
22