Data Structures & Algorithm - Time Complexity I have written my own answer, can
ID: 3664410 • Letter: D
Question
Data Structures & Algorithm - Time Complexity
I have written my own answer, can anyone please help me to check whether my answer is correct or not, if it is not, please explain why so that I can improve my concept about time complexity. Thank you.
My answer for question above:
I have 1 more extra question, what if QUESTION 2's f2 function has been modified, instead of sum += f1(n), sum+= f1(n/2) and sum += f1(n/3),
the code has been modified as sum = f1(n), sum = f1(n/2) and sum = f1(n/3), will it running on same time complexity? In my own opinion, it should be the same, even though the sum is assigned as the value return by either f1/f2/f3 function, the time complexity remain the same because it still run through the function loops and the time complexity is same as the answer for Q2.
Appreciate for anyone who willing to help out.
Best Regards.
Give () running times for each of the following functions, as a functon of their input parameter. HINT if you are having trouble with finding (), first find 0(), then (). For partial credit, just find 0() 1. (2 points) public static int fi(int n) int sum = 0; for (int i 0; iExplanation / Answer
the answers you have written are correct,
however in question 2 the time complexity will be O(n) since we will be assigning sum to every function again and again and no sum will be calculated it will be assigned like a variable only.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.