Objective: To gain insight into how subtle changes in how code implemented can h
ID: 644832 • Letter: O
Question
Objective: To gain insight into how subtle changes in how code implemented can have significant impacton the execution time. The specific assignment is to compare the execution times of two routines that perform the same task, but access data differently.
Assignment: Write a main program which creates the source and destination matrices and initializes the source matrix with random data. Include functions which will allow you to measure the execution time of the copy function(s).
Objective: To gain insight into how subtle changes in how code implemented can have significant impacton the execution time. The specific assignment is to compare the execution times of two routines that perform the same task, but access data differently. Assignment: Write a main program which creates the source and destination matrices and initializes the source matrix with random data. Include functions which will allow you to measure the execution time of the copy function(s).Explanation / Answer
/*Traverse a given 2D matrix from given source to destination in such way that every cell should be visited exactly one time
(we have to cover all cells of matrix exactly once and have to reach at destination).*/
public class TwodArray {
public void parseArray(int[][] myArray)
{
for(int i=0;i<myArray.length;i++)
{
for(int j=0;j<myArray.length;j++)
{
System.out.println("parsed element--->"+myArray[i][j]);
}
}
}
public static void main(String[] args) {
TwodArray a=new TwodArray();
int[][] myArray = { {0,1,2,3}, {3,2,1,0}, {3,5,6,1}, {3,8,3,4} };
a.parseArray(myArray);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.