Question

Could someone please show how to find the order of growth (big O) for the swim...

Could someone please show how to find the order of growth (big O) for the swim and sink functions on binary heaps? I need to check my work. Thank you!

1.) Swim

private void swim(int k) {
   while (k > 1 && less(k/2, k)) {
      exch(k, k/2);
      k = k/2;
   }
}

2.) Sink

private void sink(int k) {
   while (2*k <= N) {
      int j = 2*k;
      if (j < N && less(j, j+1)) j++;
      if (!less(k, j)) break;
      exch(k, j);
      k = j;
   }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. Swim() - O(log n) time complexity. Because in each iteration k's value is getting half, that is value of k is decreasing exponentially.
  2. Sink() - O(log n) time complexity. Because in each iteration k's value is getting doubled, so again k's value is increasing exponentially.
Add a comment
Know the answer?
Add Answer to:
Could someone please show how to find the order of growth (big O) for the swim...
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