giving a big-Oh characterization in terms of n,of the running time of following methods

icon
Related questions
Question

giving a big-Oh characterization in terms of n,of the running time of following methods 

1 /** Returns the sum of the integers in given array.
public static int example1(int[] arr) {
2
3
int n = arr.length, total = 0;
for (int j=0; j<n; j++)
total += arr[j];
return total;
4
5
6
7
8
9 /** Returns the sum of the integers with even index in given array. */
10 public static int example2(int[] arr) {
11
int n = arr.length, total = 0;
}
12
13
14
15 }
for (int j = 0; j<n; j+= 2)
total += arr[j];
// loop from 0 to n-1
return total;
// note the increment of 2
Transcribed Image Text:1 /** Returns the sum of the integers in given array. public static int example1(int[] arr) { 2 3 int n = arr.length, total = 0; for (int j=0; j<n; j++) total += arr[j]; return total; 4 5 6 7 8 9 /** Returns the sum of the integers with even index in given array. */ 10 public static int example2(int[] arr) { 11 int n = arr.length, total = 0; } 12 13 14 15 } for (int j = 0; j<n; j+= 2) total += arr[j]; // loop from 0 to n-1 return total; // note the increment of 2
Expert Solution
Step 1: Given

Answer is explained below in detail

steps

Step by step

Solved in 4 steps

Blurred answer