analyze the time complexity and space complexity of the following algorithm

icon
Related questions
Question
analyze the time complexity and space complexity of the following algorithm
1 /** Returns the sum of the integers in given array. */
2 public static int example1(int[] arr) {
3 int n = arr.length, total = 0;
for (int j=0; j<n; j++)
total += arr[j];
6 return total;
7 }
45
// loop from 0 to n-1
Transcribed Image Text:1 /** Returns the sum of the integers in given array. */ 2 public static int example1(int[] arr) { 3 int n = arr.length, total = 0; for (int j=0; j<n; j++) total += arr[j]; 6 return total; 7 } 45 // loop from 0 to n-1
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer