简体   繁体   中英

Is Bottom Up Dynamic programming recursive?

In this approach smaller subproblems are computed and results are cached, then we compute the bigger subproblems for which we use the already computed optimized values of the smaller subproblems from a table which cached the earlier computed values. So, is this approach recursive or iterative?

The approch we use in dynamic programming is actually inductive . One can turn constructive inductive proofs either to a recursive algorithm or to an iterative algorithm. It is just matter of taste. Eg memoization is a recursive implementation, while for every memoized algorithm there is an iterative approach.

Simple example is the fibonacci number. One can write it iterative:

Fib (n)
{
    F_1=F_2=1;
    For i =3..n 
         F_i = F_i-1 + F_i-2;
   Return F_n;
}

One can write it recursively:

  Define array F of size n;
  F [1]=F [2]=1;
  Fib (n)
  {
       If (F [n-1]==0)
            F [n-1] = Fib (n-1);

      If (F [n-2]==0)
            F [n-2] = Fib (n-2);
     F [n]= F[n-2]+F [n-1];
     Return  F[n];
  }

Both of them are dynamic programing and they have same order. In some circumstances writing it recursive is easier. In some cases iterative is faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM