Write a function F(n) which returns the total number of operations (additions an
ID: 3638511 • Letter: W
Question
Write a function F(n) which returns the total number of operations (additions and assignments) done on the variable sum. Use Big-O asymptotic notation to classify each of these algorithms with respect n. Assume that int sum = 0.(a) for (int i = 0; i < n; i++) sum = sum + 4;
(b) for (int i = 0; i < 2*n; i++)
for (int j = 0; j < 2 * n; j++)
sum = sum + 1;
(c) for( int i = 0; i < n; i++) sum = sum + 1;
for( int j = 0; j < n; j++) sum = sum + 1;
(d) for (int i = 1; i < n; i*=4) sum = sum + 1;
Explanation / Answer
public static String method1(int N) { if (N == 0) return ""; String temp = method1(N / 2); if (N % 2 == 0) return temp + temp; else return temp + temp + "x"; } public static String method2(int N) { String s = ""; for (int i = 0; iRelated 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.