Question

Show how to get the big-Oh for the following code: void CountSort (int A[N], int range)...

Show how to get the big-Oh for the following code:

void CountSort (int A[N], int range) {
// assume 0 <= A[i] < range for any element A[i] int *pi = new int[range];
for ( int i = 0; i < N; i++ ) pi[A[i]]++;
for ( int j = 0; j < range; j++ )

for ( int k = 1; k <= pi[j]; k++ ) cout << j << endl;

}

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

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Since there are 2 loops but, they are not nested. So, first for loop has complexity of

O(n)

Second for loop will have complexity of O(N+range)

So,

total complexity is O(N+range)

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Show how to get the big-Oh for the following code: void CountSort (int A[N], int range)...
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