In: Computer Science
I need the following answered for an Operating Systems course
Describe the order in which the elements of the A array are accessed in the rows() and columns() functions. What is the main difference?
Include the output of each run and show what the average throughput is
Is there a difference in the throughput or time required to execute “rows()” versus “columns()”? If there is a difference, explain the cause of the difference
Array:
The order in which the elements of the A array are accessed in the rows() and columns() functions:
Programe to access element of array by cloumn and row:
#include<iostream>
using namespace std;
int main()
{
int A[3][3] ={{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
for (int i = 0; i < 3; i++)
{
cout<<"\n";
for (int j = 0; j < 3; j++)
{
cout<<"\t";
cout << A[i][j];
}
}
return 0;
}
The Output of each run and show what the average throughput is:
By row:
By column:
Process:
Difference: " Showed in the process"
Time required to execute “rows()” versus “columns()” function:
Programe :
#include <stdio.h> /* Library files*/
#include <time.h>
#include <conio.h>
#define MAX 100 /*define array capacity*/
int A[MAX][MAX] = {0}; /* declaration of array*/
void row() { /* row function*/
int i, j;
for (i = 0; i < MAX; i++) {
for (j = 0; j < MAX; j++) {
A[i][j]++;
}
}
} /* Ending of row function*/
void column() { /* column function*/
int i, j;
for (i = 0; i < MAX; i++) {
for (j = 0; j < MAX; j++) {
A[j][i]++;
}
}
} /* ending of row function*/
int main() { /* main function*/
int i, j;
clock_t t = clock();
row();
t = clock() - t;
printf("Row access time :%f s\n",
t / (float)CLOCKS_PER_SEC);
t = clock();
column();
t = clock() - t;
printf("Column access time :%f s\n",
t / (float)CLOCKS_PER_SEC);
return 0;
}
Output:
Here we can see the difference in time required to execute “rows()” versus “columns()” function Because the reason is same as diffrenece:
Note:- Excuation time depends on your system capacity.