Juor-Prof. Dr. Robert Elsässer, Marco Muñz, Phllp Hedegger WS 2009/200 Algorthms Theory, Soluto for Assgmet 2 http://lak.formatk.u-freburg.de/lak_teachg/ws09_0/algo090.php Exercse 2. - Fast Fourer Trasform The two polyomals have degree less tha 2, hece the polyomal pq has degree less tha 4. We represet p ad q by four etres a array ad compute DFT 4 usg FFT. We splt p a ad q a to two parts: For k 3, t holds that: p(x) = 3x + p a = [, 3, 0, 0] q(x) = 7x + 4 q a = [4, 7, 0, 0] p a = [, 0] p 2 a = [3, 0] q a = [4, 0] q 2 a = [7, 0] DF T k (p a, 4) = (DF T (p a, 2), DF T (p a, 2)) k + ω k 4 (DF T (p 2 a, 2), DF T (p 2 a, 2)) k () Ht: If v s a vector wth elemets ad v 2 s a vector wth m elemets, the (v, v 2 ) s a vector wth + m elemets, The: { v k f k (v, v 2 ) k := f < k + m ad j = k v j Example The followg example demostrates the otato gve above: ((, 2, 3), (4, 5)) = (, 2, 3, 4, 5) Hece, (DF T (p a, 2), DF T (p a, 2)) s a vector wth 4 etres, ad the frst two etres are the same as the secod oe. We state ω 0 4 = ω 2 4 = ω 4 = ω 3 4 = Hece we ca wrte DF T (p a, 4) = F F T (p a, 4) as: F F T (p a, 4) = (F F T ([, 0], 2) + F F T ([3, 0], 2), F F T ([, 0], 2) 2 + F F T ([3, 0], 2) 2, F F T ([, 0], 2) + ( ) F F T ([3, 0], 2), F F T ([, 0], 2) 2 + ( ) F F T ([3, 0], 2) 2 ) Now we have to compute F F T ([, 0], 2) ad F F T ([3, 0], 2).. Frst we compute F F T ([, 0], 2). It s defed as: F F T ([, 0], 2) = ((F F T ([], ), F F T ([], )) + (F F T ([0], ), F F T ([0], )), (F F T ([], ), F F T ([], )) 2 + ( ) (F F T ([0], ), F F T ([0], )) 2 ) = ( + 0, 0) = (, )
2. Now, F F T ([3, 0], 2) yelds: F F T ([3, 0], 2) = (3, 3) We opta F F T (p a, 4) = ( + 3, + 3, 3, 3) = (4, + 3, 2, 3) (2) For q a t holds that: F F T (q a, 4) = (F F T ([4, 0], 2) + F F T ([7, 0], 2), F F T ([4, 0], 2) 2 + F F T ([7, 0], 2) 2, F F T ([4, 0], 2) + ( ) F F T ([7, 0], 2), F F T ([4, 0], 2) 2 + ( ) F F T ([7, 0], 2) 2 ). Frst we compute F F T ([4, 0], 2). F F T ([4, 0], 2) = (4, 4) 2. Now, F F T ([7, 0], 2) yelds: F F T ([7, 0], 2) = (7, 7) The, F F T (q a, 4) = (4 + 7, 4 + 7, 4 7, 4 7) = (, 4 + 7, 3, 4 7) (3) Hece we get the result for p q by multplyg (2) ad (3) : Ths yelds F F T (p q, 4) = (4, ( + 3) (4 + 7), 2 ( 3), ( 3) (4 7)) = (44, 7 + 9, 6, 7 9) pq(ω 0 4) = pq() = 44 pq(ω 4) = pq() = 7 + 9 pq(ω 2 4) = pq( ) = 6 pq(ω 3 4) = pq( ) = 7 9 Hece we have a pot-value represetato of pq. Iterpolato To compute the coeffcets we set r(x) := [44, 7 + 9, 6, 7 9]. We compute FFT(r,4) by frst splttg r to two parts: r = [44, 6] ad r 2 = [ 7 + 9, 7 9]. F F T (r, 4) = (F F T ([44, 6], 2) + F F T ([ 7 + 9, 7 9], 2), F F T ([44, 6], 2) 2 + F F T ([ 7 + 9, 7 9], 2) 2, F F T ([44, 6], 2) F F T ([ 7 + 9, 7 9], 2), F F T ([44, 6], 2) 2 F F T ([ 7 + 9, 7 9], 2) 2 ) We compute FFT([44,6],2) ad FFT([-7 + 9, -7-9],2): F F T ([44, 6], 2) = (44 + 6, 44 6) = (50, 38) F F T ([ 7 + 9, 7 9], 2) = ( 34, 38) Hece: F F T (r, 4) = (50 34, 38 + 38 2, 50 + 34, 38 38 2 ) = (6, 0, 84, 76) 2
From ths we obta the coeffcets a 0 = 4 6 = 4 a = 76 = 9 4 a 2 = 4 84 = 2 a 3 = 4 0 = 0 ad hece pq = 0x 3 + 2x 2 + 9x + 4 Exercse 2.2 - FFT. Defe p A = a m x m + a x + a 0 p B = b m x m + b x + b 0 for 0 j m where { f j A a j = 0 f j / A b j = { f j B 0 f j / B The polyomal p C = p A p B = k 2m 2 x 2m 2 + k x + k 0 represets the set C = A + B. For 0 j 2m t holds that j C k j > 0 Sce p c ca be computed by FFT tme O(m log m), the statemet holds. 2. The umbers k j are the soluto for the secod questo. Please otce that t s mportat to choose a j = f j A ad b j = f j B. 3. I ths part we eed to cout for all x all pars (a, b) A B, such that there exsts a c N wth x = c (a + b). Frst assume we have a fxed x. Assume for example x = 6. Computg d 6 ca by doe by summg up k, k 2, k 3 ad k 6. For x = 8 we sum up k, k 2, k 4, k 8. More geerally, for each x {,..., 2m 2}: We ca wrte ths to a table: d x = 2m 2 =, x d = k d 2 = k +k 2 d 3 = k +k 3 d 4 = k +k 2 +k 4 d 5 = k +k 5 d 6 = k +k 2 +k 3 +k 6 k It s easy to see that k s part of each sum, whle k 2 s part of d 2, d 4, d 6,..., d 2m 2. geeral, for each {,..., 2m 2} the value k s part of d, d 2, d 3,..., d k, where I k 2m 2 < r(k + ) Our algorthm takes k j as put. It computes for each x {,..., 2m 2} the umber d x. 3
INPUT: k [ ] d [ ] = ew Array [.. 2m 2 ] ( 0 ) ; for each [.. 2m 2] do for (x = ; x+ = ; x < 2m 2) d [ x ] = d [ x ] + k [ ] OUTPUT: d [ ] For = 2m 2, the rutme of the algorthm T (m) s bouded by: T (m) = = Hece, the rutme s O(m log m). ( x= ) ( ) = = = ( + Exercse 2.3 - Radomzed Qucksort =2 ) ( + log ) O( log ). T () = Θ( 2 ) arses whe the worst-case parttog occurs (.d. parttog yelds two sub-problems, wth umber of elemets ad 0 respectvely). Possble permutatos π of ad probabltes for p l ad p r are: π =, 2,..., m ad p l = 0, p r =. Symmetrcally we have: π = m, m,..., ad p l =, p r = 0. π =, 2,..., m ad p l = 0.5, p r = 0.5. Oe possble executo of Radomzed Qucksort could lead to the followg parttos: 2. We prove that T () O( log ). left rght 2, 3,..., m pvot = l = 2, 3..., m pvot = r = m 3,..., m pvot = l = 2. We choose a costat c, such that {,..., } T () c log. ad we prove for large that T () c log. 4
The defto of Θ() ad T () states that for some c N: T () 2 T (k) + c = 2c k= 2 c k log k + c k= /2 k log k + k= Sce log s a mootoe creasg fucto = 2c /2 k log 2 + = c k= k=/2+ k=/2+ k log k + c k log + c We use log /2 = log log 2 ad log 2 2c /2 (log ) k + log k + c k= k=/2+ = 2c /2 log k k + c k= k= = 2c ( ( )( 2) (/2 )(/2 2) log 2 2 (log ( )( 2) 4 ) ( 2)( 4) + c c log c 4 (2 6 + 8) + c = c log c 4 + 3 2 c 2c + c c log c 4 + 3 2 c + c We choose c = 4 ( ) c + 3 2 ) + c c log c + c 3 2 + 3 2 c For large t holds > c, whch yelds 3 2 c 3 2. Exercse 2.4 - RSA c log. Gve, p = 9, q = 29 ad e = 5. Compute = pq = 55. Use the exteded Eucld algorthm wth a = (p )(q ) = 504 ad b = e = 5 to compute d as the multplcatve verse of e modulo (p )(q ). put output (504, 5) (,, 504 5 ) = (,, 0) (5, 4) (,, 0 5 4 ) = (,, ) (4, ) (, 0, 4 0) = (, 0, ) (, 0) (,, 0) 5
The exteded Eucld algorthm returs the modular multplcatve verses such that gcd(a, b) = ax + by = 504 ( ) + 5 (0) Sce d e mod 504 =, we have d = y = 0. Publc key P = (e, ) = (5, 55), secret key S = (d, ) = (0, 55). 2. P (M) = P (22) = 22 5 mod 55 = 29 6