Question

Provide the Big‐O notation for the following lines of Java code, make sure you include all...

Provide the Big‐O notation for the following lines of Java code, make sure you include all the necessary steps to reach your answer to receive any credit:

a. for (i = 10; i < n – 8; i++)

{

for( j = 1; j < m; j *= 2)

x = i + j;

}

b. for(k = 0; k <= m; k += 2)

{

l = 0;

while(l < n/2)

{ y = l * 4 – x; l++; }

}

c. k = n;

while (k > 1)

{

for(j = 4; j < n; j++) ;

for(i = 1; i <= n; i++)

{

System.out.println(i+k);

z = i * k;

}

k /= 2;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
a.
Number of values for i are n-8-10 = n-18
Number of values for j are log(m) as j is incrementing twice every time.
So, Total time complexity = O(nlog(m))

b.
Number of values for k are m/2
Number of values for l are n
So, Total time complexity = O(mn)

c.
Number of values for k are log(n) as k is decrementing by 2 every time.
Number of values for i are n
Number of values for j are n-4
As two for loop as are not nested (They are parallel)
So, Total time complexity = O(log(n)(n+n-4)) = O(nlog(n))

Add a comment
Know the answer?
Add Answer to:
Provide the Big‐O notation for the following lines of Java code, make sure you include all...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT