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

Lecture 6

The document discusses divide and conquer algorithms for polynomial evaluation. It introduces the polynomial evaluation problem and proposes a divide and conquer solution that divides the polynomial into even and odd terms. Complex roots of unity are then discussed as a way to select evaluation points so that the polynomials can be evaluated independently in parallel.

Uploaded by

mandyroseforlife
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lecture 6

The document discusses divide and conquer algorithms for polynomial evaluation. It introduces the polynomial evaluation problem and proposes a divide and conquer solution that divides the polynomial into even and odd terms. Complex roots of unity are then discussed as a way to select evaluation points so that the polynomials can be evaluated independently in parallel.

Uploaded by

mandyroseforlife
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Design and Analysis of Algorithms

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,

1. Choose any set of numbers

2. Compute for all .

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
𝑺

Try to express as 2 polynomials of degree less than .

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

1. Show that the algorithm will require time.

7
The Recursion Tree points
for
evaluation
() + () degree

𝑨 ¿ 𝒏 𝑺𝒏

𝑨 first 𝑨 second ¿ 𝒏/ 𝟐 𝑺 𝒏

¿ 𝒏/ 𝟒𝑺 𝒏

¿ 𝟏𝑺 𝒏

polynomials, each to be evaluated at distinct numbers 

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

𝑨 ¿ 𝒏 𝑺𝒏

𝑨 𝑒𝑣𝑒𝑛 𝑨 𝑜𝑑𝑑 ¿ 𝒏/ 𝟐 𝑺 𝟐𝒏

¿ 𝒏/ 𝟒𝑺 𝟒𝒏

¿ 𝟏𝑺 𝒏𝒏

polynomials, each to be evaluated at distinct numbers 


Question: Is it possible to select such that
This hurdle is pointing to a very
𝒏 𝒏 important
Now question
recall thewhose
setanswer
¿ 𝑺𝟐∨¿ ¿ 𝑺𝟒∨¿ 𝒏
𝟒 … ¿ 𝑺 ∨¿ 𝟏 will solve this problem …
𝟐 you selected. What is the size
of , , …, ?
10
Question

Is it possible to select such that


𝟐 𝒏 =
¿ 𝑺 ∨¿
𝟐

𝟒 𝒏
¿ 𝑺 ∨¿ Good start !
𝟒
But how to satisfy the
… remaining requirements …

𝒏
¿ 𝑺 ∨¿ 𝟏

11
Complex numbers

Recalling elementary facts

12
Complex numbers
√ 𝑎2 +𝑏2 Complex plane

𝑏
𝜑
𝑟
Addition 𝑎
= ? Vector addition

Multiplication
= 𝑟 1 𝑟?2 (cos (𝜙 1+ 𝜙 2)+𝑖 sin (𝜙 1 + 𝜙2 ))

Magnitudes get multiplied &


Arguments get added… beautiful 

13
Complex roots of unity

Definition: Complex plane


A number is said to be th root of unity
if it satisfies equation.

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

Is it possible to select such that

𝟐 𝒏
𝑺 =
𝟐
Theorem:
If is odd 𝟒 𝒏
𝑺 =
𝟒
If is even

𝒏
𝑺 =𝟏 ?

𝑺=𝑹 𝒏
16
The Recursion Tree points
for
evaluation
() + () degree

𝑨 ¿ 𝒏 𝑹𝒏

𝑨 𝑒𝑣𝑒𝑛 𝑨 𝑜𝑑𝑑 ¿ 𝒏/ 𝟐 𝑹 𝒏
𝟐

¿ 𝒏/ 𝟒𝑹 𝒏𝟒

¿ 𝟏𝑹 𝟏

T() = Time complexity of Evaluating on


= a + T()

17
O() time

<> <>
Coefficient <>
represntation

?
O( log ) time Done
O( log ) time

{}
{} {}

O() time

18
Interpolation
There is a polynomial

with ’s unknown.

Given the following (point, value) representation of :

{}
Aim: To compute ’s .
Interestingly, Polynomial Interpolation can be solved using
Polynomial Evaluation only .

19
Interpolation

Can you guess the polynomial whose evaluation


will help solve polynomial interpolation ?
Make an obvious guess.

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

For those of you, who love competitive programming,


try to write a neat code for the algorithm we discussed for
multiplication of two polynomials.

How will you implement complex numbers ?

22

You might also like