0% found this document useful (0 votes)
57 views3 pages

Exercise 1

This document presents an algorithm for computing binomial coefficients modulo m in O(log n) time. It introduces a recursive formula to compute C(n) based on dividing n by 4 at each step. It then generalizes this to dividing by any integer k, and proves that for k = log n, the algorithm runs in optimal O(log n) time. Experimental results show the algorithm has best performance when k = 3 for large n.

Uploaded by

inbvt esxcd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views3 pages

Exercise 1

This document presents an algorithm for computing binomial coefficients modulo m in O(log n) time. It introduces a recursive formula to compute C(n) based on dividing n by 4 at each step. It then generalizes this to dividing by any integer k, and proves that for k = log n, the algorithm runs in optimal O(log n) time. Experimental results show the algorithm has best performance when k = 3 for large n.

Uploaded by

inbvt esxcd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXERCISE 1

xnmod
dN
xn
4 n 4 4

( x ) -
[r n > 3
-

(l) Cln) = C ( nmod 4 ) + C ( n div 4 ) + 3

C (0) = C (1) = C ( 2) = C (3)

Cln ) = Cln 11 41 ⼗ 3

l -ltZAssumethatthisisthecase.i.e.CM
Wehavetoprovec.cn ) ⼆ 3

) E 3
ltf J +2

Wehavei
Cln ) = C (n 11 4 ) +3

Ccn ) E
(3 等
⼗ 9
1 +2
) +3

-1

9" 3
Cln )
( +2
E t
3

Cln ) 三
Íllogznj -3 +2 +3

(m) E
Íllogznj +2 PROVED *

(2)

t.compute t.x.XI.pk -1

xnmodzkcxndivzkjzk-xnmodmcxndivmjmwhere.mn
2. Gmpute xn
recursivey
=

K
= 2

(3) Cln ) =
C ( nmodzk ) + C ( ndiv 2k ) + K + 1

K
C(0) = C ( 1) = _ _ _ = C( 2 -
1 ) = 0

K
Cln ) = C ( n /1 2 ) + K + 1

Assume.CM ) ⼆
logznlltitéki )
C.cn/i2k)+k+l-)J+k+le-fkccn)Ellog2EklI+i+eogzt
Cln ) =

egzn-logzzkclrnellogzn-kllltitek.pt
=

ktl-logzn-kc melogznt -t zkt-gc ma-logznt ftzkc.me


eogznlltftékj ) PROVED *

(4)
log.nl 1 ⼗
六 ⼗
Ǘg )

Ifweviewkasaconstant.thisalgorithmhast.me complexity Ollogn )

Ifwechoosek-llogzlogzn-logzlogzlog.nl

thenizltgzeogzn-l
埔 ogzegzegznjezhgzhgznl
1 ⼗

j
o)g.nl
Táiegn
1-tzltgzeogzn-logzlogzlogznj-logznlltug.agn.e.gagag.nl
_

loszn

Ehgnlltug.g.n.fyilogzelogznlltegz-tegz-l-lgnlkeg.is
ilimtI-o.ithisdgorithmisstilloftime.com plexity Ollogn )

n-logzlogznundersuchchoiceofKWESHOWEDTHATTHEC.lt
logzlogzn-log.logzlogzntLEADSTOANASYMPTOTICAL.LY
0 ICE K = L

OPTIMAL ALGORITHM
For

istheoriginalbinarypoweringIdoritknowtheexactreas.in
(5) k ⼆ 1 ,
this

but

accordingtotheexperimentImade.thedgorithmhasbest.pe
rformancewhenk-3lwhenngetslargeshetflkilog.nl
ltf ⼗点川
flk) K = 1 2 3 4 5

6
n 41.86

5592107
=
10 33.90 34.58 40 -91

59.90 48,51 38.88 39.00 45.07


8
10 5 5,15 43.86 43.43 49.22 63,89
9
10 61.79 48.85 47 -86 53.37 67 -88

10 68.44 53.83 5229 57.52 71.86


⼼ 75.08 58.81 56 -72 61.68 75.85
2
⼼ 81.73 63.79 61.15 65.83 79 -84

You might also like