Data Structures & AlgorithmsHardCodeforces Div2 D · matrix power
Problem: What is the complexity of computing the n-th Fibonacci number modulo a prime p using matrix exponentiation?
- A. O(log n) matrix multiplications
- B. O(n) additions
- C. O(sqrt n)
- D. O(n log n)
Correct answer: A. O(log n) matrix multiplications
Exponentiation by squaring needs O(log n) multiplications of constant-size 2 x 2 matrices.
More Coding Interview Problems questions
- Problem: Which technique counts pairs in an array whose XOR is less than K in O(n bits) time?
- Problem: What is the time complexity of the Wagner-Fischer dynamic programme for edit distance on strings of length n and m?
- Problem: Which two properties define a matroid, which is what makes the greedy algorithm optimal?
- Problem: Which algorithm finds shortest paths in a grid where each cell weight is 0 or 1?
- Problem: Which technique counts subarrays with sum at most K in a non-negative array in O(n)?
- Problem: What is the time complexity of subset-sum over n items with a bitset of width W (up to 10^5)?