(30%) Assume you have a multidimensional array M x N and you wish to write a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(30%) Assume you have a multidimensional array M x N and you wish to write a function that produces an average of the items in the entire array using a sum/count approach. You have two alternatives: a) int sumArray (int ( ) ( ) array) { int sum, count = 0 ; for (int i = 0; i < array[0].length; i++) for (j = 0; j < array.length; j++) return sum; sum += a[i][j]; 'm } OR: b) int sumArray (int[] [] array) { wwwwwwmo int sum = 0; for (int i = 0; i < array.length; w w wwwwwwwoom i++) www. for (j = 0; j < array [0].length; j++) sum += a[i][j]; return sum; } Which approach will be faster and why (you can assume each row is contiguous in memory)? (30%) Assume you have a multidimensional array M x N and you wish to write a function that produces an average of the items in the entire array using a sum/count approach. You have two alternatives: a) int sumArray (int ( ) ( ) array) { int sum, count = 0 ; for (int i = 0; i < array[0].length; i++) for (j = 0; j < array.length; j++) return sum; sum += a[i][j]; 'm } OR: b) int sumArray (int[] [] array) { wwwwwwmo int sum = 0; for (int i = 0; i < array.length; w w wwwwwwwoom i++) www. for (j = 0; j < array [0].length; j++) sum += a[i][j]; return sum; } Which approach will be faster and why (you can assume each row is contiguous in memory)?
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
Here are definitions of sequences and trees with integer elements: type iseq = Nil | Cons of int * (unit -> iseq) type itree = Leaf of int | Branch of itree * itree (a) In an ascending sequence such...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Use a software package such as Matlab or Mathematica to program the example described in section 7.3. (a) Assume the environmental regulator ignores the impact on the labor market and sets an...
-
In what sense is real GDP per capita a measure of the standard of living?
-
The critical resolved shear stress for iron is 27 MPa (4000 psi). Determine the maximum possible yield strength for a single crystal of Fe pulled in tension.
-
List the sources and briefly discuss the various strategies associated with each source for integrating cost and value in projects.
-
Sherry Hopson owns a retail family clothing store. Her store is located at 4321 Heather Drive, Henderson, NV 89002. Her employer identification number is 95 1234321 and her Social Security number is...
-
Prove lim(5x-17) = -2 x3
-
Consider the recorded transactions below. Transaction Account Name Debit Credit 1 . Accounts Receivable 9 , 0 0 0 Service Revenue 9 , 0 0 0 2 . Supplies 1 , 5 0 0 Accounts Payable 1 , 5 0 0 3 . Cash...
-
address the following: Describe any experience with Microsoft PowerPoint, whether in school, on the job, or in your personal life. Explain how mastering Microsoft PowerPoint will impact your ability...
-
(1) How did Peter Brand (Jonah Hill ), a recent college grad, find himself in the position to directly influence the HR decision-making of the Oakland A's? (2) One version of the screenplay has this...
-
What are 2-3 key differences in how Korean and U.S. media talk about the shooting? The first difference was that the Korean media labeled the attack as racially motivated while the U.S media...
-
Using any software tool of your choice (e.g., Visio, PowerPoint, MS Word, yED, Lucidchart, etc.) create, draw and submit... OPTION #1 A data flow diagram for an ATM system OR OPTION #2 A Level 0 DFD...
-
College Name Boston University Average GPA Average SAT 3.7 1930 Drexel University 2.48 1765 George Washington University 3.62 1950 Northeastern University 3.69 2070 University of Southern California...
-
What are organization expenses? Provide a couple of examples.
-
If the annual fixed costs are 54,000 dinars, the occupation expense represents 20%, the contribution margin is 25%, and the unit selling price is 40 dinars. Required: Calculate the closing point of...
-
_____________ is also used as requirement finding and feasibility testing tool. (a) Prototype (b) Reports (c) System (d) Procedure
-
A prototype can be ___________. (a) Complete system with partial requirements (b) Working model (c) Full-fledged system (d) All of these
-
Which of the following systems development approach is adopted if information requirements are not well defined? (a) SDLC (b) Prototype (c) Structured approach (d) Agile
Study smarter with the SolutionInn App