Example. Calculate F6 and FlO' Note that FIB2 is faster than FIBl.
F I 82
IilDmDIIllDDmII _ _
Comparison of FIB1 and FIB2
FIBl calculates intermediate values Fi more than once, while FIB2 cal-
culates each intermediate Fi only once. Consequently, FIB2 is faster.
The difference in speed increases with the size of
because the time
required for FIBl grows exponentially with n, while the time required
for FIB2 grows only linearly with n.
The diagram below shows the beginning steps of FIBl calculating FlO'
Note the number of intermediate calculations: 1 in the first row, 2 in
the second row, 4 in the third row, and 8 in the fourth row.
28: Programming Examples