7,337 views
0 votes
0 votes

Consider the following code:

for (i=0; i <20; i++) 
    for ( j= 0; j< 10; j++)
        a[i] = a[i]* j ;

a. Give one example of the spatial locality in the code.

b. Give one example of the temporal locality in the code.

1 Answer

1 votes
1 votes
a. a[1]  is accessed after a[0] both are near memory locations and hence example of spatial locality.

b. a[0] is accessed for j = 0 and for j = 1; same memory location accessed in nearby time and hence example of temporal locality.

Related questions

0 votes
0 votes
1 answer
3