Can I have help with these 4 questions please? thanks! 1. Characterize the follo
ID: 3742839 • Letter: C
Question
Can I have help with these 4 questions please? thanks!
1. Characterize the following algorithm in terms of Big-O notation. (Assume that all variables are properly declared.)
for (int i = 1; i <= 2 * n; i++)
for (int j = 1; j <= n; j++)
cout << 2 * i + j;
cout << endl;
2.Characterize the following algorithm in terms of Big-O notation. Also find the exact number of additions executed by the loop. (Assume that all variables are properly declared.)
for (int i = 1; i <= n; i++)
sum = sum + i * (i + 1)
3.In the software maintenance process, the program is modified to fix the (identified) problems and/or to enhance it.
TRUE OR FALSE
4.If g(n) = 1, the growth rate is constant and does not depend on the size of the problem.
TRUE OR FALSE
Explanation / Answer
1. Characterize the following algorithm in terms of Big-O notation. (Assume that all variables are properly declared.)
Answer :O(n2)
for (int i = 1; i <= 2 * n; i++) ---------> Loop runs for (2n + 1) times
for (int j = 1; j <= n; j++)---------> Loop runs for (2n)*(n+1) times
cout << 2 * i + j;---------> runs for (2n)*(n) times
cout << endl;
Hence we can say that 2n*n = 2n2 = O(n2)
2.Characterize the following algorithm in terms of Big-O notation. Also find the exact number of additions executed by the loop. (Assume that all variables are properly declared.)
Answer :O(n)
for (int i = 1; i <= n; i++)------> Loop runs for (n + 1) times
sum = sum + i * (i + 1)-----> runs for (n) times
Hence we can say that n = O(n)
Number of Addition is n +1 + n + n= 3n+ 1
[i is incremented n+1 times and sum will be done n times and again i+1]
3.In the software maintenance process, the program is modified to fix the (identified) problems and/or to enhance it.
TRUE
4.If g(n) = 1, the growth rate is constant and does not depend on the size of the problem.
TRUE
Answer are highlighted in BOLD. PLEASE UPVOTE if helpful
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.