GATE | GATE-CS-2000 | Question 2

An n x n array v is defined as follows:

v[i, j] = i-j for all i, j, 1 <= i <= n, 1 <= j <= n

The sum of the elements of the array v is
(A) 0
(B) n-1
(C) n2 – 3n + 2
(D) n2 (n+1)/2


Answer: (A)

Explanation: In this case, the matrix would be

0    -1    -2    -3    -4    -5    -6    -7    ...    -n
1     0    -1    -2    -3    -4    -5    -6    ...  -(n-1)
2     1     0    -1    -2    -3    -4    -5    ...  -(n-2)
3     2     1     0    -1    -2    -3    -4    ...  -(n-3)
4     3     2     1     0    -1    -2    -3    ...  -(n-4)
5     4     3     2     1     0    -1    -2    ...  -(n-5)
6     5     4     3     2     1     0    -1    ...  -(n-6)
7     6     5     4     3     2     1     0    ...  -(n-6)
.     .     .     .     .     .     .     .     .   .   .
.     .     .     .     .     .     .     .     .   .   .
.     .     .     .     .     .     .     .     .   .   .
n    n-1   n-2   n-3   n-4   n-5   n-6    n-7  ...  2   1

Now, we take the sum of first row and first column, which comes out to be zero. Similarly, we take the sum of second row and second column, third row and third column, and so on, and it is found that all have a sum equal to zero.
So, the sum of all the elements in the matrix is zero.

 
Thus, A is the correct choice.

 
Please comment below if you find anything wrong in the above post.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.