The best asymptotic complexity of the tribonacci numbers will use the exponential matrix method, such as the one for Fibonacci numbers . In particular, it is written correctly, these are O (log n) entire operations, and not O (n) (as a dynamic programming method) or O (3 n ) (as a naive solution).
Matrix of interest
[1, 1, 1] M = [1, 0, 0] [0, 1, 0]
and the number n th tribonacci is in the upper left corner of M n . The expression of the matrix must be computed by squaring to achieve log (n) complexity.
(for F(n+3) = a F(n+2) + b F(n+1) + c F(n) , the matrix:
[a, b, c] M = [1, 0, 0] [0, 1, 0]
and the result: {F n + 2 , F n + 1 , F n } = M n {F 2 , F 1 , F 0 }, also see here .)
huon
source share