advanced
Algorithmic Complexity Reduction
Optimize a recursive function using advanced mathematical concepts.
📝 Conteúdo do Prompt
Analyze a recursive function for calculating the nth Fibonacci number. Identify the performance bottlenecks, rewrite it using memoization to achieve O(n) time complexity, and further optimize it to O(log n) time complexity using matrix exponentiation. Explain the mathematical reasoning behind the final optimization.