• edited by
2,284 views
9 9 votes

Consider the following program modifying an $n \times n$ square matrix $A$:

for i=1 to n:
    for j=1 to n:
        temp=A[i][j]+10
        A[i][j]=A[j][i]
        A[j][i]=temp-10
    end for
end for

Which of the following statements about the contents of matrix $A$ at the end of this program must be TRUE?

  1. the new $A$ is the transpose of the old $A$
  2. all elements above the diagonal have their values increased by $10$ and all the values below have their values decreased by $10$
  3. all elements above the diagonal have their values decreased by $10$ and all the values below have their values increased by $10$
  4. the new matrix $A$ is symmetric, that is, $A[i][j]=A[j][i]$ for all $1 \leq i, j \leq n$
  5. $A$ remains unchanged

1 Answer

Best answer
13 13 votes
1.for i=1 to n:
2.    for j=1 to n:
3.        temp=A[i][j]+10
4.        A[i][j]=A[j][i]
5.        A[j][i]=temp-10
6.    end for
7.end for

The $3,4,5$ lines swap $A [ j ] [ i ]$ and $A [ i ] [ j ]$.

The same variables are swapped twice. For eg when: $i =5$, $j = 10$. $A [10] [5]$ and $A [5] [10]$ will be swapped. They will be swapped again when $i = 10$, $j =5$.

Two times swap of same elements will lead to $A$ remaining unchanged.

Hence, E is correct.

• edited by
Answer:
Position:
Show:

Related questions

15 15 votes
4 answers 4 answers
3.5k
3.5k views
go_editor asked Dec 23, 2016
3,472 views
Let $T(a, b)$ be the function with two arguments (both nonnegative integral powers of 2) defined by the following recurrence:$ T(a, b) = T \left( \frac{a}{2}, b \right) +...
24 24 votes
4 answers 4 answers
6.2k
6.2k views
go_editor asked Dec 21, 2016
6,185 views
Which of the following functions asymptotically grows the fastest as $n$ goes to infinity?$(\log \: \log \: n)!$$(\log \: \log \: n)^ {\log \: n}$$(\log \: \log \: n)^{\l...
5 5 votes
1 1 answer
1.7k
1.7k views
go_editor asked Dec 23, 2016
1,665 views
A multivariate polynomial in $n$ variables with integer coefficients has a binary root if it is possible to assign each variable either 0 or 1, so that the polynomial eva...
16 16 votes
2 answers 2 answers
5.0k
5.0k views
go_editor asked Dec 23, 2016
4,968 views
An array of $n$ distinct elements is said to be un-sorted if for every index $i$ such that $ 2 \leq i \leq n-1$, either $A[i] \text{max} \{A [i-1], A[i+1]\}$, or $A[i] <...