Question

Analyze the following programs and show their time complexity functions and big-O notations. for(int i =...

Analyze the following programs and show their time complexity functions and big-O notations.

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

{

for(int j=1; j <= n; j++)

{

if (j % 3 == 0)

{

// 4 assignments

}

if (2*i + 3 == 5)

{

// 17 assignments

}

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
As i is incremented by 3 every time 
Number of values for i are n/3

As j is incremented by 1 every time
Number of values for j are n

So, Time complexity = O(Product of time complexities of two nested loops)
                    = O((n/3) * n)
                    = 

Add a comment
Know the answer?
Add Answer to:
Analyze the following programs and show their time complexity functions and big-O notations. for(int i =...
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