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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started