EE 230 Probability and random variables
Freivalds’ algorithm Report
Bhakti Laxman Kalyankasture 210108019
It is used for verifying matrix multiplication.
Naïve method:
Multiplying n*n matrices(consider n=2)
[ a b ][w x ] = [aw+by ax+bz]
[ c d ][ y z ] [cw+dy cx+dz]
Complexity of algorithm: Θ(n^3 )
Calculating time complexity:
Matrix multiplication of A, B of order n:
for i=1 to n ----O(n)
for j=1 to n ----O(n)
c[i][j]=0
for k=1 to n ----O(n)
c[i][j] = c[i][j]+a[i][k]*b[k][j]
Therefore time complexity of matrix multiplication: O(n^3)
(There are 8 multiplications here; in general, n multiplications for each of n^2 entries)
Freivalds’ Algorithm:
1. Input: n×n matrices A, B and C.
2. We would like to verify if A×B=C.
Choose a n×1 column vector r→∈{0,1}n, uniformly and at random. In
other words, each component of the vector is either 0 or 1 and chosen
randomly and uniformly.
3. Compute A⋅(B⋅r) and C⋅r. This takes Θ(n^2) time.
Time complexity:
for i=1 to n ----O(n)
for j=1 ----O(1)
c[i][j]=0
for k=1 to n ----O(n)
c[i][j] = c[i][j]+a[i][k]*b[k][j]
therefore time complexity of Freivalds’ Algorithm is O(n^2) if we interate
k times time complexity = O(kn^2)
4. Now comes the output
• If A⋅(B⋅r)≠C⋅r, output FALSE. In other words, we say that the
given matrix multiplication is incorrect. This has a probability of
correctness = 1.
• If A⋅(B⋅r)=C⋅r, output TRUE. In other words, we say that the given
matrix multiplication is correct. This has a probability of
correctness ≥1/2.
Though it has some problems
Error analysis in Freivalds’ Algorithm: