edited by
11,969 views
36 votes
36 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]);
  1. The matrix $A$ itself
  2. Transpose of the matrix $A$
  3. Adding $100$ to the upper diagonal elements and subtracting $100$ from lower diagonal elements of $A$
  4. None of the above
edited by

3 Answers

Best answer
38 votes
38 votes

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$.

edited by
33 votes
33 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.
3 votes
3 votes
take a small matrix
[a b]

[c d]

it will give
[a c

b+100 d]
for first row iterated

[a b + 100 -100
c d]
for second row iterated.
hence answer A.
Answer:

Related questions

27 votes
27 votes
5 answers
1
go_editor asked Sep 28, 2014
11,369 views
Consider the function func shown below: int func(int num) { int count = 0; while (num) { count++; num>>= 1; } return (count); }The value returned by func($435$) is ______...
61 votes
61 votes
10 answers
2
go_editor asked Sep 28, 2014
30,658 views
You have an array of $n$ elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the...
5 votes
5 votes
2 answers
3
Souvik33 asked Jan 15, 2023
1,095 views
Consider the function func shown below: int func(int num) { int count = 0; while (num) { count++; num>>= 1; } return (count); }The value returned by func(-435) is:69Will ...