dsa7 min read
Matrix Exponentiation Explained — Fibonacci and Linear Recurrences in O(log n) [LC 509, Google, Stripe]
Matrix exponentiation collapses any linear recurrence into O(log n) by raising a transition matrix to the n-th power. Master Fibonacci, k-th order recurrences, and DP optimization tricks that let you answer queries with n up to 10^18 in milliseconds.
Read →