To calculate the duration of one MP3 file, we need to know how it is encoded first. The estimation of durtation is different based on how they are encoded. CBR(Constant...…
Master Fibonacci
You may know how to get n-th Fibonacci number, but do you know what the fastest way to calculate it is?
Calculating Fibonacci Numbers by Fast Doubling
In previous post, we learned how to calculate Fibonacci numbers by Fast Doubling in math. Today, we will apply it in programming and optimize it step by step. Fast Doubling...…
Matrix Difference Equation for Fibonacci Sequence
Recurrence relation Suppose we have a difference equation defined by: \[x_n = a \cdot x_{n - 1} + b \cdot x_{n - 2}\] Then, \[\begin{align} x_n &= a \cdot x_{n...…
Exponentiation by squaring
What is the time complexity of the computation for \(k^n\)? We might intuitively think it’s \(O(n)\). In fact, it can be done in \(O(\log n)\) by exponentiation by squaring. The...…
Closed Form for the Fibonacci Sequence
The Fibonacci number can be defined as: \[F_n = F_{n-1} + F_{n-2}\] where \(F_0 = 0, F_1 = 1\). Assume \(F_n = s \cdot r^n\), then \(F_n = F_{n-1} +...…