sicp-ex-5.28



<< Previous exercise (5.27) | Index | Next exercise (5.29) >>


meteorgan

  
  
  
                          total-pushes             maximum-depth 
 recursion             37n + 33                  3n + 14 
 iteration              34n - 16                    8n + 3 
  
  
  
  
 -------------------------------------------------------------------------- 
 Either this one is backwards or the one above. 
  
                   Maximum depth    Number of pushes 
  +----------+-----------------+------------------+ 
   Recursive |           8n+3  | 34n-16 
   Factorial |                 | 
  +----------+-----------------+------------------+ 
   Iterative |           3n+14 | 37n+33 
   Factorial |                 |            
                            
                          

codybartfast

Reproduced the same results (except for constants):



┌─────────────────────┬──────────────────┬──────────────────┐
│                     │   Maximum Depth  │ Number of Pushes │
├─────────────────────┼──────────────────┼──────────────────┤
│ Recursive Factorial │     34n +  -8    │      8n +   6    │
├─────────────────────┼──────────────────┼──────────────────┤
│ Iterative Factorial │     37n +  41    │      3n +  17    │
└─────────────────────┴──────────────────┴──────────────────┘