0

I am given the following algorithm, which checks whether a given matrix is symmetric:

isSym(A):
1.   b = True
2.   for i = 0 to n-1 do
3.     for j = i+1 to n-1 do
4.       if A[i,j] != A[j,i] then b = False
5.   return b

My aim is to prove that it is $\Omega(n^2)$ for any $n\times n$ input matrix. I have something, but I want to see if it is correct and if it is correct, whether there is a more obvious way to prove it.

Firstly, the outer loop in line $2$ runs $n$ times. As for the inner loop in line $3$, this runs from $i+1$ to $n-1$. Therefore this loop runs $n-i-1$ times regardless of input and is $\Omega(n-i-1)$, where $i$ goes from $0$ to $n-1$ in the outer loop. So I have

$\sum\limits_{i=0}^{n-1}\Omega(n-i-1) = \Omega(\sum\limits_{i=0}^{n-1}(n-i-1))$, where if I split the summation up I get

$\Omega(\sum\limits_{i=0}^{n-1}n-i-1) = \Omega(n^2 - \frac{n(n-1)}{2} - n)$

This can be simplified as $\Omega(\frac{n^2 - 3n}{2}) = \Omega(n^2)$

Is this the correct approach?

  • If something seems obvious, try proof by contradiction. – greybeard Apr 15 '15 at 06:43
  • This looks good so far. You need to fix a cost measure, though; if you count, say, only executions of b = false you won't get $\Omega(n^2)$ this way. – Raphael Apr 15 '15 at 08:56

0 Answers0