Skip to content

13 - Quiz

  • Your name:

  • Your VT email:


func columnMean(data [][]float64, col int) float64 {
  M := len(data)  // number of rows
  var sum float64
  for i := 0; i < M; i++ {
    sum += data[i][col]
  }
  return sum / float64(M)
}

Which statement best describes the relationship between the loop iterations?

  • A. Each iteration is independent in terms of reading data, but the shared variable sum introduces a dependency that must be handled.
  • B. Each iteration depends on the previous iteration because sum is updated sequentially.
  • C. Each iteration modifies the input matrix data, creating dependencies.
  • D. Each iteration requires the final value of sum before continuing.
func cumulativeMovingAverage(data [][]float64, col int) []float64 {
  M := len(data)  // number of rows
  var sum float64
  cma := make([]float64, M)
  for i := 0; i < M; i++ {
    sum += data[i][col]
    cma[i] = sum / float64(i+1)
  }
  return cma
}

Why is it difficult to parallelize the loop in cumulativeMovingAverage directly?

  • A. The slice cma cannot be written by multiple goroutines.
  • B. The computation requires the accumulated sum from all previous iterations.
  • C. The matrix data cannot be accessed concurrently.
  • D. Go does not allow loops to be parallelized.