Question

What are the Big-Oh and Omega orders of the following code fragment? What is Tilde approximation?...

What are the Big-Oh and Omega orders of the following code fragment? What is Tilde approximation?

The fragment is prameterized on the variable n. Assume that you are measuring the number of swap calls.

for(int j=0;j<n-1;j++){

     int z = j;

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

            if(a[i] < a[z]){

                      z=i;}

}

if(z!= j){

      swap(a[j], a[z]); //count these

     }

}

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

Answer:

outer loop iterates n times.
inner loop iterates O(n) times.
so, time complexity is O(n^2)

Big-Oh: O(n^2)
Big-Omega: Ω(n^2)
Add a comment
Know the answer?
Add Answer to:
What are the Big-Oh and Omega orders of the following code fragment? What is Tilde approximation?...
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