factorial of trace of fact' execution for small value of is presented in section static long fact(int /compute nrecursively /fact( is the largest value that fits in long assert ( > &( < " out of range"if ( < return /base casereturn base solution return fact( - )/recursive call for the first two lines of the function constitute the base cases if < then one of the base cases computes solution for the problem if then fact calls function that knows how to find the factorial of of coursethe function that knows how to compute the factorial of happens to be fact itself but we should not think too hard about this while writing the algorithm the design for recursive algorithms can always be approached in this way first write the base cases then think about solving the problem by combining the results of one or more smaller -but similar -subproblems if the algorithm you write is correctthen certainly you can rely on it (recursivelyto solve the smaller subproblems the secret to success isdo not worry about how the recursive call solves the subproblem simply accept that it will solve it correctlyand use this result to in turn correctly solve the original problem what could be simplerrecursion has no counterpart in everyday problem solving the concept can be difficult to grasp because it requires you to think about problems in new way to use recursion effectivelyit is necessary to train yourself to stop analyzing the recursive process beyond the recursive call the subproblems will take care of themselves you just worry about the base cases and how to recombine the subproblems the recursive version of the factorial function might seem unnecessarily complicated to you because the same effect can be achieved by using while loop here is another example of recursionbased on famous puzzle called "towers of hanoi the natural algorithm to solve this problem has multiple recursive calls it cannot be rewritten easily using while loops the towers of hanoi puzzle begins with three poles and ringswhere all rings start on the leftmost pole (labeled pole the rings each have different sizeand are stacked in order of decreasing size with the largest ring at the bottomas shown in figure the problem is to move the rings from the leftmost pole to the rightmost pole (labeled pole in series of steps at each step the top ring on some pole is moved to another pole there is one limitation on where rings may be moveda ring can never be moved on top of smaller ring