1) Suppose that you have a 2-dimensional array A of size N x N (i.e., M rows and N columns) that is stored in memory in row-major order as shown in the following diagram.

b) Suppose you want to walk a pointer down the diagonal elements of A, A[0, 0], A[1, 1], ... , A[N-1, N-1].

i) Write a formula for the value of the amount that you would need to add to the pointer to move it from A[i, i] to A[i+1, i+1].

ii) How many multiplication's and additions will be saved for each diagonal element accessed

by walking pointers instead of the index calculation in part (a)?

# of multiplication's saved =

# of additions saved =

2) Suppose that you have a 3-dimensional array A of size N x N x N (i.e., N rows, N columns, and N depths) that is stored in memory as shown in the following diagram.

b) Suppose you want to walk a pointer down the diagonal elements of A, A[0, 0, 0], A[1, 1, 1], ... , A[N-1, N-1, N-1].

i) Write a formula for the value of the amount that you would need to add to the pointer to move it from A[i, i, i] to A[i+1, i+1, i+1].

ii) How many multiplication's and additions will be saved for each diagonal element accessed

by walking pointers instead of the index calculation in part (a)?

# of multiplication's saved =

# of additions saved =