Question

Determine the runtime complexity of the following. Use O() notation, but the function that you place within the parenthe...

Determine the runtime complexity of the following. Use O() notation, but the function that you place within the parentheses of O() should be the upper bound on the runtime of the algorithm or function. Unless otherwise specified, N is the problem size or the number of elements in the container (even if N does not appear in the code or algorithm you are given), and all other values are constants.

For graphs, use |V| and |E| for the size of the graph/problem. For the code segments, you should assume that all variables and functions exist and are defined appropriately to make the code work properly. And that’s always the case with algorithms.

a) for (i=0; i for (j=0; j matrix[i][j] = 0.0;

b) for (i=N; i>0; i/=3)
cout << i << endl;

c) HALVE-ME(i) {
if (i == 0) return;
HALVE-ME(i/2);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

7,576 answers

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

1)

Since it has 2 nested loops both over n. So, the big time complexity is O(n^2)

2)

Since at every iteration it is dividing i by 3. So, total iterations will be log3(n). o, it is O(log(n))

3)

Recurrence of it is

T(n)=T(n/2)+1

So, it is also O(log(n))

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Determine the runtime complexity of the following. Use O() notation, but the function that you place within the parenthe...
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