GATE CS 2024 Set 2 | Question 43

MCQ · 2 marks · −0.66

Consider the following expression: \(x[i] = (p + r) * -s[i] + u/w\). The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).

(0)+\(p\)\(r\)
(1)
(2)uminus(1)
(3)
(4)/\(u\)\(w\)
(5)+(3)(4)
(6)
(7)=(6)(5)

Which one of the following options fills in the missing entries CORRECTLY?

  1. Option A: (1) =[] \(s\) \(i\) (3) * (0) (2) (6) []= \(x\) \(i\) (correct)
  2. Option B: (1) []= \(s\) \(i\) (3) – (0) (2) (6) =[] \(x\) (5)
  3. Option C: (1) =[] \(s\) \(i\) (3) * (0) (2) (6) []= \(x\) (5)
  4. Option D: (1) []= \(s\) \(i\) (3) – (0) (2) (6) =[] \(x\) \(i\)

Answer

(A)

Explanation

Triples have no result names: an operand is either a name or the number of an earlier triple.

  • (1) =[] s i reads the element \(s[i]\), the value that (2) negates. The operator []= stores into an array element and produces no value for uminus to use.
  • (3) * (0) (2) multiplies \(p + r\) by \(-s[i]\), which (5) then adds to \(u/w\). The expression contains no subtraction, so the options with – fail here too.
  • (6) []= x i marks the array location \(x[i]\), and (7) assigns the value of (5) to it. Putting (5) inside (6) would lose the index \(i\) and duplicate the work of (7).

Answer: A