- Freivald's algorithm
Freivald's algorithm is a
randomized algorithm used to verifymatrix multiplication . Given three "n" x "n" matrices "A", "B", and "C", a general problem is to verify whether "A" x "B" = "C". A naïvealgorithm would compute the product "A" x "B" explicitly and compare term by term whether this product equals "C". However, this approach takes O("n"3) time. To resolve this, Freivald's algorithm utilizesrandomization in order to reduce this time bound to O("n"2).The Algorithm
Input
Three "n" x "n" matrices "A", "B", "C".
Output
Yes, if "A" x "B" = "C"; No, otherwise.
Procedure
- Generate an "n" x 1
random 0/1 vector . - Compute .
- Output "Yes" if ; "No," otherwise.
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.
="A" x "B" = "C"=If "A" x "B" = "C", then "A" x "B" − "C" = 0, and so , regardless of what our vector was.
"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.
Ramifications
Simple algorithmic analysis shows that the running time of this
algorithm is O("n"2), beating the classical deterministic algorithm's bound of O("n"3). The error analysis also shows that if we run ouralgorithm "k" times, we can achieve an error bound of less than , an exponentially small quantity. Therefore, utilization ofrandomized algorithms can speed up a very slowdeterministic algorithm . In fact, the best known deterministic matrix multiplication verification algorithm known at the current time is theCoppersmith-Winograd algorithm with an asymptotic running time of O("n"2.376).- Generate an "n" x 1
Wikimedia Foundation. 2010.