Question: What is the running time for these methods? 1- public static void m4(int[] arr) { for (int i=0; i System.out.println(arr[i] * 10); } for (int

What is the running time for these methods?

1-

public static void m4(int[] arr) {

for (int i=0; i

System.out.println(arr[i] * 10); }

for (int j=arr.length-1; j>=0; j--) {

System.out.println(arr[j] / 10); }

}

2-

public static void m5(int[] arr) {

for (int i=0; i<15; i++) {

for (int j=0; j

System.out.println(Math.max(arr[i],

arr[j])); }}

}

3-

public static int mystery(int n) {

int count = 0;

int cur = 1;

while (cur < n) {

count++;

cur = cur * 2;

}

return cur;

}

4-

int pow(int m, int n) {

int ret = 1;

for (int i = 0; i < n; i++) {

ret *= m;

}

return ret;

}

5-

int pow(int m, int n) {

int ret = 1;

int k = m;

int i = n;

while (i > 0) {

if (i % 2 == 1) ret *= k;

k *= k;

i /= 2;

}

return ret;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!