36 /** Returns the number of times second array stores sum of prefix sums from first. 37 public static int example5(int[] first, int[] second) { // assume equal-length arrays 38 int n = first.length, count = 0; for (int i=0; i
36 /** Returns the number of times second array stores sum of prefix sums from first. 37 public static int example5(int[] first, int[] second) { // assume equal-length arrays 38 int n = first.length, count = 0; for (int i=0; i
Related questions
Question
Give a big-Oh characterization, in terms of n, of the running time of the following
method.
![36 /** Returns the number of times second array stores sum of prefix sums from first. */
37 public static int example5(int[] first, int[] second) { // assume equal-length arrays
38
39
// loop from 0 to n-1
40
41
// loop from 0 to n-1
42
// loop from 0 to j
43
44
45
46
47 }
int n = first.length, count = 0;
for (int i=0; i<n; i++) {
int total = 0;
for (int j=0; j<n; j++)
for (int k=0; k<=j; k++)
total += first[k]:
if (second[i] == total) count++;
}
return count;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2ae76079-938b-4b5d-8ceb-1dfbc10f88ce%2Fcb672e11-bf55-4082-8862-96bfa663b726%2Fggt9ou_processed.png&w=3840&q=75)
Transcribed Image Text:36 /** Returns the number of times second array stores sum of prefix sums from first. */
37 public static int example5(int[] first, int[] second) { // assume equal-length arrays
38
39
// loop from 0 to n-1
40
41
// loop from 0 to n-1
42
// loop from 0 to j
43
44
45
46
47 }
int n = first.length, count = 0;
for (int i=0; i<n; i++) {
int total = 0;
for (int j=0; j<n; j++)
for (int k=0; k<=j; k++)
total += first[k]:
if (second[i] == total) count++;
}
return count;
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
Step 1: Code Introduction
ASOLUTION -
In the given code -
1public static int example5(int[] first, int[] second) {
2 int n = first.length, count = 0;
3
4 for (int i = 0; i < n; i++) {
5 int total = 0;
6
7 for (int j = 0; j < n; j++) {
8 for (int k = 0; k <= j; k++) {
9 total += first[k];
10 }
11 }
12
13 if (second[i] == total) {
14 count++;
15 }
16 }
17
18 return count;
19}
20
This method is used to we will returns the number of times second array stores sum of prefix sums from first
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)