Question



Find the best case, worst case and average case complexity for numbers of comparison and assignment operations for the follow
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANS:

Comparison:

   map[i][j]<0

it will run for every value of i,j;

So, it will run (n * n) times.Means O(n2).

it's complexity is equal in all the cases.

BEST: O(n2);

WORST: O(n2);

AVERAGE: O(n2);

assignment:

map[i][j]=-map[i][j];

it will run when the condition become true.

So, when map[i][j] is less than 0; then assignment will run.

BEST: if all the value of map[i][j] >=0;then the assignment will not run any time.

time complexity =O(1)

AVERAGE: if half of the value of map[i][j] is less than 0; then assignment will run (n * n) / 2 time;

time complexity = O([n* n]/2)=O(n2).

WORST: if all the value of map[i][j] is less than 0 , then assignment will run (n * n) times (i.e O(n2)).

time comlexity=O(n2).

Add a comment
Know the answer?
Add Answer to:
Find the best case, worst case and average case complexity for numbers of comparison and assignment...
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