Divide And Conquer Homework Problems Pic

On By In 1

Unformatted text preview: CS 141 , Spring 2014 Homework 4 Problem 1. (25 points) Give a divide-and-conquer algorithm for multiplying two polynomials of degree n in time O ( n log 2 3 ). Answer: Suppose the two polynomials we want to multiply are A ( x ) = a + a 1 x + a 2 x 2 + ... + a n- 1 x n- 1 and B ( x ) = b + b 1 x + b 2 x 2 + ... + b n- 1 x n- 1 . We assume that n is a power of two (otherwise, we can always pad the coefficients with zeros to reach the ”next” power of two). Let us break A ( x ) and B ( x ) into two polynomials as follows. A ( x ) = A ( x ) + x n/ 2 A 1 ( x ) B ( x ) = B ( x ) + x n/ 2 B 1 ( x ) where A ( x ) = a + a 1 x + a 2 x 2 + ... + a n/ 2- 1 x n/ 2- 1 A 1 ( x ) = a n/ 2 + a n/ 2+1 x + a n/ 2+2 x 2 + ... + a n- 1 x n/ 2- 1 B ( x ) = b + b 1 x + b 2 x 2 + ... + b n/ 2- 1 x n/ 2- 1 B 1 ( x ) = b n/ 2 + b n/ 2+1 x + b n/ 2+2 x 2 + ... + b n- 1 x n/ 2- 1 Then the problem of multiplying A ( x ) B ( x ) can be decomposed in the problem of multiplying A ( x ) ,A 1 ( x ) ,B 1 ( x ) ,B 1 ( x ) as follows. We omit “( x )” to reduce the clutter. AB = ( A + x n/ 2 A 1 )( B + x n/ 2 B 1 ) = A B + x n/ 2 ( A B 1 + A 1 B ) + x n A 1 B 1 = A B + x n/ 2 (( A − A 1 )( B 1 − B ) + A B + A 1 B 1 ) + x n A 1 B 1 Therefore, we need 3 multiplications of two polynomials of degree n/ 2 (namely, A B , A 1 B 1 and ( A − A 1 )( B 1 − B )) and O ( n ) additional work for the sum and the differences. The recurrence relations is T ( n ) = braceleftBigg Θ(1) n = 1 3 T ( n/ 2) + O ( n ) n > 1 which can be solved using the Master Theorem, concluding that T ( n ) ∈ O ( n log 2 3 ). Problem 2. (25 points) In the algorithm Select described in class (linear-time selection), the input elements are divided into n/ 5 groups of 5. 1. Suppose you modify the algorithm to divide the input elements into n/ 7 groups of 7 instead. Let T ( n ) denote the worst-case running time of the modified algorithm as a function of the input size n . Write a recurrence relation for T ( n ), then give an upper bound for T ( n ). 2. Suppose you modify the algorithm to divide the input elements into2....
View Full Document

Grazie! - просиял итальянец. Он швырнул Беккеру ключи от «веспы», затем взял свою девушку за руку, и они, смеясь, побежали к зданию клуба. - Aspetta! - закричал Беккер.

 - Подождите.

0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *