Sie sind auf Seite 1von 4

Repeated squaring

Computing nth Fibonacci number in o(n2 ) time

R. Inkulu
http://www.iitg.ac.in/rinkulu/

(Computing a Fibonacci Number)

1/4

Problem

Compute the nth Fibonacci number.

(Computing a Fibonacci Number)

2/4

Observation

0 1
1 1

n   

1
fn1
=
0
fn

denote with An b = c
naive: n matrix multiplications
but with repeated squaring: O(lg n) matrix multiplications suffice to

compute An
Further, multiplication of two 2 2 matrices involve O(1) integer

multiplications and integer additions

(Computing a Fibonacci Number)

3/4

Analysis

let M(n) denote the time to multiply/add two n-bit integers 1 , which is
O(n1.585 ) from the Karastubas algorithm
let T(n) denotes the time to compute the nth power of the given 2 2 matrix
(i.e., time to compute f (n))
T(n) = T( 2n ) + M(n)
Hence, T(n) is O(n1.585 )

1
as we had seen nth Fibonacci number is O(n ) i.e., it takes (n) time to write f (n); hence,
we need to consider the bit complexity in integer arithmatic
(Computing a Fibonacci Number)

4/4

Das könnte Ihnen auch gefallen