Question

In: Computer Science

Define spatial and temporal locality.  Consider the following code:               for (i=0; i < 50; i++)           &nbsp

Define spatial and temporal locality.  Consider the following code:  

            for (i=0; i < 50; i++)

            for (j =0; j < 30; j++)

                  a[i] = a[i] * j;

  1. Give an example of spatial locality in the above code.

b. Give an example of temporal locality in the above code.

Solutions

Expert Solution

****This requires some effort so please drop a like if you are satisfied with the solution****

Spatial Locality:

Spacial locality is defined as the statement or instruction or data near to the memory address the is being accessed currently may be needed soon in future ....

in Spatial locality two instructions or statements refer to contiguous memory locations..

arrays are the best example of Spatial locality

a) In the above code, in the inner loop, in the statement a[i] = a[i] * j , the array locations a[0], a[1] ,a[2] are contiguous memory locations and are being accessed frequently so a[i] are examples of Spacial locality

Temporal Locality:

Temporal locality is defined as the current memory location that is being accessed or data being fetched might needed again soon in future...

in Temporal locality the same memory location is accessed many number of times frequently..

variables in a loop are good examples for temporal locality as they being accessed frequently

b) In the above code, in the inner loop, in statement a[i] = a[i] * j the variables i and j are accessed frequently or their memory locations are accessed frequently (number of times the loop runs) so they are the examples of temporal locality.


Related Solutions

. Define Temporal and Spatial summation and explain how each can propagate the occurrence of an...
. Define Temporal and Spatial summation and explain how each can propagate the occurrence of an action potential in the axon of the neuron?(25 points)
Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that...
Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that A and B are arrays of 64-bit integers, and C and i are 64-bit integers. Assume that all data values and their addresses are kept in memory (at addresses 1000, 3000, 5000, and 7000 for A, B, C, and i, respectively) except when they are operated on. Assume that values in registers are lost between iterations of the loop. Assume all addresses and words...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 50 is used...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 50 is used and the population standard deviation is 7. Use the critical value approach to state your conclusion for each of the following sample results. Use  = .05. a. With x (with line over top of x) = 52.5, what is the value of the test statistic (to 2 decimals)? b. With x = 51, what is the value of the test statistic (to 2 decimals)? c....
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 70 is used...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 70 is used and the population standard deviation is 7. Use the critical value approach to state your conclusion for each of the following sample results. Use  = .05. a. With x = 52.5, what is the value of the test statistic (to 2 decimals)? b.  With x = 51, what is the value of the test statistic (to 2 decimals)? c. With x = 51.8, what is the...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 55 is used...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 55 is used and the population standard deviation is 7. Use the critical value approach to state your conclusion for each of the following sample results. Use  = .05. a. With  = 52.5, what is the value of the test statistic (to 2 decimals)? Can it be concluded that the population mean is greater than 50? SelectYesNoItem 2 b. With  = 51, what is the value of the test statistic...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 65 is used...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 65 is used and the population standard deviation is 7. Use the critical value approach to state your conclusion for each of the following sample results. Use  = .05. a. With  = 52.5, what is the value of the test statistic (to 2 decimals)? Can it be concluded that the population mean is greater than 50? SelectYesNoItem 2 b. With  = 51, what is the value of the test statistic...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 60 is used...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 60 is used and the population standard deviation is 7. Use the critical value approach to state your conclusion for each of the following sample results. Use  = .05. a. With  = 52.5, what is the value of the test statistic (to 2 decimals)?    Can it be concluded that the population mean is greater than 50? SelectYesNoItem 2 b. With  = 51, what is the value of the test...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 55 is used...
Consider the following hypothesis test: H 0:   50 H a:  > 50 A sample of 55 is used and the population standard deviation is 8. Use the critical value approach to state your conclusion for each of the following sample results. Use  = .05. With  = 52.5, what is the value of the test statistic (to 2 decimals)?    Can it be concluded that the population mean is greater than 50? SelectYesNoItem 2 b. With  = 51, what is the value of the test statistic...
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
Write assembly code for the following C procedure: i = 1; sum = 0; while (i...
Write assembly code for the following C procedure: i = 1; sum = 0; while (i ≤ n) { sum += i; ++i; } i and sum corresponds to $s1 and $s2. n is preloaded into $s3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT