2

In CLRS (2/e, page 191, section 9.3) the analysis of the SELECT algorithm for finding the ith smallest element in an array is presented with the following induction proof:

1.  T(n) <= c celing(n/5) + c(7n/10 + 6) + an
2.       <= cn/5 + c + 7cn/10 + 6c + an
3.       = 9cn/10 + 7c + an
4.       = cn + (-cn/10 + 7c + an)
5.       = cn,  when -cn/10 + 7c + an <= 0

I understand the algorithm, but two manipulations in the proof have me stumped a bit.

Question 1: in line 2, where did the extra c term comee from (second term)? c multiplied through the (7n/10 + 6) term gives 7cn/10 + 6c.

Question 2: in line 4, how did we get from 9cn/10 to cn + (-cn/10 ...)? Where did the 9 coefficient go?

This is not homework

Thank you!

iDev
  • 23,310
  • 7
  • 60
  • 85

2 Answers2

0
  1. The extra c is from c*celing(n/5) - consider n/5 = 10.2 - then c * ceiling(n/5) = 11c > cn/5 so we need to add an extra c.
  2. 9cn/10 = (10-1)cn/10 = 10cn/10 - cn/10 = cn - cn/10 ... = cn + (-cn/10 ...)
amit
  • 175,853
  • 27
  • 231
  • 333
  • Amit, thank you. Exactly what I was missing. CLRS is an amazing resource, but sometimes lacks narrative on some of the analysis examples. – David Arsenault Oct 11 '12 at 23:39
  • @DavidArsenault: CLRS assumes some mathematical background, it could be tough understanding the book without it I am afraid.. I am happy I could help you out with your problem. Don't forget to [accept an answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) later on :) – amit Oct 11 '12 at 23:42
0

Just for adding more information for the line 2. We have ceiling(x) <= x + 1.Because x is round to the next integer.Assume m <= x < m+1,then ceiling(x) = m+1,x+1 >= m+1,so we have ceiling(x) <= x + 1. And in that case, c * ceiling(n/5) must be less than or equal to c*(n/5+1),then you got the extra c.

Reporter
  • 3,897
  • 5
  • 33
  • 47