Freivald's algorithm
From Wikipedia, the free encyclopedia
Freivald's algorithm is a randomized algorithm used to verify matrix multiplication. Given three n x n matrices A, B, and C, a general problem is to verify whether A x B = C. A naïve algorithm would compute the product A x B explicitly and compare term by term whether this product equals C. However, this approach takes O(n3) time. To resolve this, Freivald's algorithm utilizes randomization in order to reduce this time bound to O(n2).
Contents |
[edit] The Algorithm
[edit] Input
Three n x n matrices A, B, C.
[edit] Output
Yes, if A x B = C; No, otherwise.
[edit] Procedure
[edit] Error Analysis
Let p equal the probability of error. We claim that if A x B = C, then p = 0, and if A x B ≠ C, then p ≤ 1/2.
[edit] A x B = C
If A x B = C, then A x B − C = 0, and so , regardless of what our vector was.
[edit] A x B ≠ C
Let , so . Since A x B ≠ C, we have A x B − C ≠ 0, so some element of D is nonzero.
Suppose that the element . By the definition of matrix multiplication, we have .
Using Bayes' Theorem, we have .
Also, note that:
Plugging these in the above equation, we have:
Therefore,
- .
This completes the proof.
[edit] Ramifications
Simple algorithmic analysis shows that the running time of this algorithm is O(n2), beating the classical deterministic algorithm's bound of O(n3). The error analysis also shows that if we run our algorithm k times, we can achieve an error bound of less than , an exponentially small quantity. Therefore, utilization of randomized algorithms can speed up a very slow deterministic algorithm. In fact, the best known deterministic matrix multiplication verification algorithm known at the current time is the Coppersmith-Winograd algorithm with an asymptotic running time of O(n2.376).