(c) Consider the following two C functions sum2Darray1 and sum2Darray2. Both of them compute the sum of all the elements of an input 2-dimensional matrix. Which one of them will be able to exploit memory hierarchy and thus achieve faster com- putation time? Explain your answer. 1 int sum2Darray1 (int a [N] [M]) 2 { 3 4 5 6 780 8} int i, j, sum=0; for(i=0; i

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter13: Structures
Section: Chapter Questions
Problem 4PP
icon
Related questions
Question
Don’t post same answer I will rate unhelpful, tutors are posting wrong answer How to know which one is the inner loop and outer loop
(c) Consider the following two C functions sum2Darray1 and sum2Darray2. Both of
them compute the sum of all the elements of an input 2-dimensional matrix. Which
one of them will be able to exploit memory hierarchy and thus achieve faster com-
putation time? Explain your answer.
1 int sum2Darray1 (int a [N] [M])
2 {
3
4
5
6
7
8
int i, j, sum=0;
for(i=0; i<M; i++)
for(j=0; j<N; j++)
sum sum + a[j] [i];
return sum;
1 int sum2Darray2 (int a [N] [M])
2 {
3
4
5
6
7
8}
int i, j, sum=0;
for(i=0; i<n; i++)
for(j=0; j<M; j++)
sum sum + a[i][j];
return sum;
Transcribed Image Text:(c) Consider the following two C functions sum2Darray1 and sum2Darray2. Both of them compute the sum of all the elements of an input 2-dimensional matrix. Which one of them will be able to exploit memory hierarchy and thus achieve faster com- putation time? Explain your answer. 1 int sum2Darray1 (int a [N] [M]) 2 { 3 4 5 6 7 8 int i, j, sum=0; for(i=0; i<M; i++) for(j=0; j<N; j++) sum sum + a[j] [i]; return sum; 1 int sum2Darray2 (int a [N] [M]) 2 { 3 4 5 6 7 8} int i, j, sum=0; for(i=0; i<n; i++) for(j=0; j<M; j++) sum sum + a[i][j]; return sum;
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Matrix multiplication
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning