Question: [JAVA] Study Guide Problems 5. What is the asymptotic complexity of the following methods or code segments, in terms of the Big-O notation? a) void
[JAVA] Study Guide Problems
5. What is the asymptotic complexity of the following methods or code segments, in terms of the Big-O notation?
a) void methodA(int n) { for (int i=n; i>1; i-=2) { System.out.println(i); } }
b) void methodB(int n) { for (int i=n; i<=n; i++) { for (int j=n; j>1; j=j/2) { System.out.println(j); } } }
c) Code segment:
int sum = 0; int X = 100000; for (int i = 1; i <=4 * N; i++) { for (int j = 1; j <= X + 2; j++) { sum++ } for (int j = 1; j <= X * 100; j+= 2) { for (int k = 1; k <= X * X; k++) { sum++; } } sum++; } System.out.println(sum);
d) Code segment:
int sum = 0; int X = 100000; for (int j = 0; i < 100 * N; j++) { for (int i = N; i > 0; i /= 2) { sum++ } } System.out.println(sum);
Link to Source PDF:
https://www.dropbox.com/s/1lrjfjs38plzska/Practice_Final_Exam.pdf?dl=0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
