Assume we have two dimensional array of size 100x100, each element is occupying 4 bytes and array is stored in row major order. Further assume RAM is 1MB and cache is 4KB with each size of 32 bytes:
X: for(i = 0; i < 100; i++){
for(j = 0; j < 100; j++){
{
print(a[i][j] );
}
}
Y: for(i = 99; i >= 0; i--){
for(j = 99; j >= 0; j--){
{
print(a[i][j]);
}
}
In case of 2-way set associative cache, number of cache misses is(assume initially cache is empty)
(A) 1250
(B) 2500
(C) 2400
(D) 2372