(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) 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
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;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe2671d74-f92c-4fa2-b1b7-82cf1a92220d%2F97d15e92-c28e-4da4-954e-ed3cb485fbf0%2Fqhmugf_processed.jpeg&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Knowledge Booster
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.Recommended textbooks for you

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning