- swap symmetric off-diagonal elements
- Perform step $1$ for all elements one-after-another
- We will get the same matrix

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+21 votes

Let $A$ be the square matrix of size $n \times n$. Consider the following pseudocode. What is the expected output?

C=100; for i=1 to n do for j=1 to n do { Temp = A[i][j]+C; A[i][j] = A[j][i]; A[j][i] = Temp -C; } for i=1 to n do for j=1 to n do output (A[i][j]);

- The matrix $A$ itself
- Transpose of the matrix $A$
- Adding $100$ to the upper diagonal elements and subtracting $100$ from lower diagonal elements of $A$
- None of the above

+27 votes

Best answer

**A**.

In the computation of given pseudo code for each row and column of Matrix $A$, each upper triangular element will be interchanged by its mirror image in the lower triangular and after that the same lower triangular element will be again re-interchanged by its mirror image in the upper triangular, resulting the final computed Matrix $A$ same as input Matrix $A$.

+18 votes

Take a small matrix

1 2

3 4

now trace the iteration

i=1,j=1 //no change in matrix cz a[i,j]=a[j,i]

i=1,j=2 // resultant matrix

1 3

2 4

i=2,j=1 //resultant matrix

1 2

3 4

i=2,j=2 //no change in matrix cz a[i,j]=a[j,i]

we get the original matrix as it is So, Option A is Ans.

1 2

3 4

now trace the iteration

i=1,j=1 //no change in matrix cz a[i,j]=a[j,i]

i=1,j=2 // resultant matrix

1 3

2 4

i=2,j=1 //resultant matrix

1 2

3 4

i=2,j=2 //no change in matrix cz a[i,j]=a[j,i]

we get the original matrix as it is So, Option A is Ans.

- All categories
- General Aptitude 1.5k
- Engineering Mathematics 7.1k
- Digital Logic 2.7k
- Programming & DS 4.9k
- Algorithms 4.2k
- Theory of Computation 5.3k
- Compiler Design 2.1k
- Databases 4k
- CO & Architecture 3.5k
- Computer Networks 4k
- Non GATE 1.4k
- Others 1.5k
- Admissions 556
- Exam Queries 551
- Tier 1 Placement Questions 23
- Job Queries 69
- Projects 18

47,894 questions

52,260 answers

182,165 comments

67,679 users