1

I was reading dynamic programming chapter from famous book Introduction To Algorithm

In rod cutting problem it gives simple algorithm as follows:

    cutRod(p,n)
    {
       if (n == 0)
       {
          return 0
       }
       q = -∞
       for (i=1 to n)
       {
          q = max(q,p[i]+cutRod(p,n-i))
       }
       return q
    }

It then says:

T(n) be the total number of calls made to cutRod() when called with its second parameter equal to n. T(n) equals the number of nodes in a subtree whose root is labeled n in the recursion tree. The count includes the initial call at its root. Thus,

T(0) = 1 and

T(n) = ${\sum\limits_{j=0}^{n-1} T(j)}$

Exercise at the end of this chapters asks to prove from above two that in fact

T(n) = 2$^n$

How can we go about proving this?

FrankW
  • 6,609
  • 4
  • 27
  • 42
Mahesha999
  • 1,773
  • 7
  • 30
  • 45

1 Answers1

2

You can easily prove this by induction.

Base Case T(0) = 2^0 = 1.

Say T(k) = 2^k. is true for some k.

Hence T(k+1) = T(k) + sum(Ti) {i = 0 to k-1}
             = T(k) + T(k)
             = 2*2^k = 2^(k+1)

Note: By looking at the code, it seems that if you use dynamic programming and memo-ize the T(i)'s from bottom-up, you can make this algorithm into a O(n^2) algorithm.

Abhishek Bansal
  • 258
  • 3
  • 12