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.
Expert Solution
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