Which of the following is the correct TRIPLE representation of the given below…

Which of the following is the correct TRIPLE representation of the given below assignment statement.
B[i] = b+A[i][j]

Attempted by 47 students.

Show answer & explanation

Triple representation of array A[i] is :

image.png

Assumptions:

  • Row-major layout, element size = 1 (or implicit), number of columns in A = COLS.

  • Triple format: (op, arg1, arg2). Result of each triple is referred to by its triple number.

Triple representation (one correct expansion):

  1. (*, i, COLS) // t1 = i * COLS

  2. (+, 1, j) // t2 = t1 + j (index within A)

  3. ([], A, 2) // t3 = A[t2] (load A[i][j])

  4. (+, 3, b) // t4 = t3 + b (compute b + A[i][j])

  5. ([], B, i) // t5 = &B[i] or B[i] (location/value depending on model)

  6. (:=, 4, 5) // store t4 into B[i] (i.e., B[i] := t4)

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…