2.3. Checking for symmetry.
How do we check for "symmetry"? We know it means a[i,j] =
a[j,i] but how do we test this condition? We may do something
like:
for each element in array do
compare it against its corresponding element
and we should be systematic about our comparisons therefore we
should use roughly the same type of accessing of the elements as
we used when reading them in:
for each row i do
for each column j do
check a[i,j] for symmetry
What do we do when the symmetric test is true? And what
when it is false? Notice that this is an important point- if we
find a particular i,j pair for which a[i,j] = a[j,i] it only
means that the array might be symmetric, whereas finding a pair
where it doesn't hold means that the array cannot possibly be
symmetric. This is very important as it gives our approach to
the problem. We will assume that the array is symmetric and then
see if that is incorrect. We will use a logical or boolean
variable to indicate the correctness of our assumption. It will
be set to true initially and then set to false if a case of non
symmetry arises.
What is the pseudo-code for the algorithm?
Try to write the pseudo-code to process the array before
looking at the solution here.
Don't Cheat.