Question: 6. Consider the following algorithm. Give a function with one term and coefficient 1 g(n) such that the running time of this algorithm is
6. Consider the following algorithm. Give a function with one term and coefficient 1 g(n) such that the running time of this algorithm is (g(n)), and briefly explain. public static int funkySum (int[] arr) { int sum = 0; for (int i=0; i < arr.length; i+= 2){ for (int j=1; j < arr.length; j+= 2) { sum = sum + arr[i] + arr[j]; } } return sum; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
