Between the iterative routine sum-iter and recursive routine sum-rec, which is more efficient and why?

Sum-iter function is more efficient than the recursive function sum-rec. Ever time a recursive function calls itself all the local variables are saved in a stack. At the time of returning the values stored in stack are poped out. Thus recursive functions consume more memory space and time.

Post a Comment

0 Comments