Consider the following code For I 0 I 20 I For j 0 j 10
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
Solution
A.) One e.g. of spatial locality is sequential locality which means elements are accessed linearly. Therefore, a[i] in the given code is an e.g. of the spatial locality.
B.) Temporal locality states that two statements reference the same location within in very short time. Since, in the given code, j is using in very short time. Therefore, j is one example of the temporal locality in the code.
Hope it helps. Do give your response.
![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 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](/WebImages/40/consider-the-following-code-for-i-0-i-20-i-for-j-0-j-10-1124589-1761599328-0.webp)