GATE Computer ScienceHardGATE CS (PYQ pattern)
Only the non-zero band of a 20 x 20 tridiagonal matrix (entries with |i - j| <= 1, rows and columns numbered from 1) is stored in a 1-D array indexed from 1, once row by row and once column by column. At which indices does the element (12, 13) appear in the two layouts?
- A. 36 and 35
- B. 34 and 36
- C. 35 and 36
- D. 35 and 37
Correct answer: C. 35 and 36
Row by row: row 1 has 2 entries and rows 2..11 have 3 each, so 2 + 30 = 32 entries precede row 12, whose entries are (12, 11), (12, 12), (12, 13): index 35. Column by column: column 1 has 2 entries and columns 2..12 have 3 each, 2 + 33 = 35 entries before column 13, whose first entry is (12, 13): index 36. The two layouts are not symmetric for an off-diagonal element.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- void f(int n) { if (n <= 1) return; f(n - 1); f(n / 2); } Each activation record takes 32 bytes. What is the peak stack usage in bytes…
- void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } int main() { int a[5] = {3, 7, 9, 12, 5}; for (int i = 0; i < 5; i++) swap(&a[i], &a[4…
- for (i = 2; i <= 100; i++) if (!comp[i]) for (j = i i; j <= 100; j += i) { comp[j] = 1; cnt++; } With comp[] initially all 0, what is the…
- long p(long x, int n) { if (n == 0) return 1; if (n % 2 == 0) { long h = p(x, n / 2); return h h; } return x p(x, n - 1); } How many…
- void perm(char s, int k) { if (s[k] == 0) { puts(s); return; } for (int i = k; s[i]; i++) { char t = s[k]; s[k] = s[i]; s[i] = t; perm(s…
- void h(int n, char a, char b, char c) { if (n == 0) return; h(n - 1, a, c, b); printf("move disk %dn", n); h(n - 1, c, b, a); } During…