RecursionExamples with Iterative Versions Numerical examples: FACTORIAL /* recursive */ int fact (n) { if (n == 1) return 1; return n * fact(n-1); | /* iterative */ int fact(n) { retValue = 1; for (int i = n; i > 0; i--) { retValue *= i; } return retValue; } // tail recursion version int factorial(n) { return tfact(n, 1); } int tfact(n, acc){ if (n==0) return acc; return tfact(n-1, n*acc); } /* iterative version of tail recursion */ int iTfact(n) { acc = 1; for (i = 1; i <= n; i++) { acc = i * acc; } return acc; } /********************************************/ LIST EXAMPLES Definition of list: empty list: () an element pushed onto a list: push a onto () -> (a) Definition of list from the perspective of dynamic linked list: a list is linked nodes. head points to the first element of the list. Each node points to the following node in the list. The final node in the list has null in the next field. Operations on a list: head(list) returns the first element of the list tail(list) returns the list with the first element removed append(a, list) returns the list formed by adding a as the new first element Examples: list = ( 1, 2, 3 ) head(list) --> 1 tail(list) --> ( 2, 3 ) append(4, list) --> ( 4, 1, 2, 3 ) /*******************************************************/ NUMBER OF ELEMENTS IN A LIST // recursive int length(list) { if ( isEmpty(list) ) return 0; return 1 + length ( tail(list) ); } // iterative int length(list) { retValue = 0;