Difference Between Spatial Locality and Temporal Locality

Prerequisite – Locality of Reference
1. Spatial Locality :
Spatial Locality means that all those instructions which are stored nearby to the recently executed instruction have high chances of execution. It refers to the use of data elements(instructions) which are relatively close in storage locations.

2. Temporal Locality :
Temporal Locality means that a instruction which is recently executed have high chances of execution again. So the instruction is kept in cache memory such that it can be fetched easily and takes no time in searching for the same instruction.



Difference between Spatial Locality and Temporal Locality :

S.No. Spatial Locality Temporal Locality
1. In Spatial Locality, nearby instructions to recently executed instruction are likely to be executed soon. In Temporal Locality, a recently executed instruction is likely to be executed again very soon.
2. It refers to the tendency of execution which involve a number of memory locations . It refers to the tendency of execution where memory location that have been used recently have a access.
3. It is also known as locality in space. It is also known as locality in time.
4. It only refers to data item which are closed together in memory. It repeatedly refers to same data in short time span.
5. Each time new data comes into execution. Each time same useful data comes into execution.
6. Example :
Data elements accessed in array (where each time different (or just next) element is being accessing ).
Example :
Data elements accessed in loops (where same data elements are accessed multiple times).

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.