Question: Assume that we have two different data structures (STRUCT and STRUCT 2) to store three dimensional point data and we access data points in two

Assume that we have two different data structures (STRUCT and STRUCT 2) to store three dimensional point data and we access data points in two different ways (ACCESS - 1 and ACCESS - 2). Which data structure provides better spatial locality for the given accesses? Explain your answer by visualizing the data structures in memory and analyzing the reference patterns. STRUCT - 1 1: #define N 1000 2: 3: struct point{ 4: float x[N]; 5: float y[N]; 6: float z[N]; }; 8: struct point points; 9: float get_point_x(int i) { return points.x[i]; } 10: float get point y(int i) { return points.y[i]; } 11: float get_point_z(int i) { return points.z[i]; } 7: STRUCT - 2 1: #define N 1000 2: 3: struct point 4: float x; 5: float y; 6: float z; 7: }; 8: struct point points[N]; 9: float get_point_x(int i) { return points[i].x; } 10: float get_point y(int i) { return points[i].y; } 11: float get_point_z(int i) { return points[i].z; } ACCESS - 1 1: int i, x = 0, y = 0, z = 0; 2: for(i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
