Please give the reason of the answer public double a (double k []) { double resu
ID: 3792670 • Letter: P
Question
Please give the reason of the answer
public double a (double k []) { double result = 1.0; for (int i = 1; i = 0; i = i - 1) result = result + j [i]/p(i); return result; } Suppose that the method p has a return type of double and requires time O(r) time, where r is independent of i. If we let n = length, what is the time complexity of method b in the worst case O(n) O(nr) O(r) O(n^2) O(r log n) Again suppose that the method p has a return type of double and requires time O(r) time, where r is independent of i. If we let m = k.length, what is the time complexity of method a in the worst case? O(mr) O(r log m) O(mr log m) O(r^2 log m) O(mr^2)Explanation / Answer
3)
Answer is (b) O(nr) .
Reason is that b method has a loop which runs for n times. And, everytime the function p has to be called which in return requires more O(r) time. Therefore, the worst case time complexity is the total time i.e O(nr)
4)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.