This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Divide and Conquer We typically reduce instances of size n to a instances of size (roughly) n/b , for sufficiently large n . The running time of the resulting recursive algorithm is given by f ( n ) af ( n/b ) + ( h ( n )) whenever n is a multiple of b , where the running time excluding the recursive calls is in ( h ( n )) . 1 By Theorem 3.32, if h ( n ) = n q g ( n ) such that for some positive integer n , g ( n ) = g ( n b n ) is smooth, f ( n ) ( h ( n )) if a < b q ( h ( n ) lg n ) if a = b q ( n log b a ) if a > b q This result can sometimes give us insight into how to improve the performance of an algorithm. 2 Polynomial Multiplication Input: Arrays p [0 ..n 1] and q [0 ..n 1] giving the coefficients of two polynomials: p ( x ) = n 1 summationdisplay i =0 p [ i ] x i and q ( x ) = n 1 summationdisplay i =0 q [ i ] x i . Output: Array P [0 .. 2 n 2] of coefficients of the product: P ( x ) = 2 n 2 summationdisplay i =0 i summationdisplay j =0 p [ j ] q [ i j ] x i . Straightforward Algorithm: ( n 2 ) . 3 We can divide each polynomial: p ( x ) = p ( x ) + x m p 1 ( x ) q ( x ) = q ( x ) + x m q 1 ( x ) , where p ( x ) = m 1 summationdisplay i =0 p [ i ] x i p 1 ( x ) = n m 1 summationdisplay i =0 p [ m + i ] x i q ( x ) = m 1 summationdisplay i =0 q [ i ] x i q 1 ( x ) = n m 1 summationdisplay i =0 q [ m + i ] x i . We can choose m = n/ 2 . 4 pq ( x ) = p ( x ) q ( x )+ x m ( p ( x ) q 1 ( x ) + p 1 ( x ) q ( x ))+ x 2 m p 1 ( x ) q 1 ( x ) . f ( n ) 4 f ( n/ 2) + ( n ) ( n 2 ) . We should either: reduce the number of recursive calls; or decrease the size of the subinstances. We will try the former. 5 ( p ( x ) + p 1 ( x ))( q ( x ) + q 1 ( x )) = p ( x ) q ( x ) + p ( x ) q 1 ( x ) + p 1 ( x ) q ( x ) + p 1 ( x ) q 1 ( x ) . We can obtain the above with one recursive multiplication. We can obtain p ( x ) q ( x ) and p 1 ( x ) q 1 ( x ) with two additional recursive multiplications....
View
Full
Document
This note was uploaded on 09/06/2009 for the course CIS 11274 taught by Professor Howell during the Spring '09 term at Kansas State University.
 Spring '09
 Howell

Click to edit the document details