Recursion – Ackermann’s Function
Prof. Mukesh N. Tekwani
Page 1 of 3
A function may be called from another function or it may call itself. Recursion implies afunction calling itself. If a function call occurs inside the function itself, it is called
. If a function calls another function, which in turn makes a call to the first one,it is called
.Each invocation of a function causes a new allocation of the variables declared inside it.The storage for auto variables is automatically allocated and freed on function entry andreturn.
Advantages of recursive functions:
Recursive functions are more concise and understandable.
Disadvantages of recursive functions:
Recursive functions are slower than the corresponding iterative functions.
Recursive functions are slow because of the overhead of passing arguments andreturning values.
Recursive functions take up more memory. Each time the function calls itself, thecurrent status of the function must be preserved (the line being executed, thevalues so far). This information is saved onto a data structure called a “stack”. If recursion goes on for a long time, we get the “Stack Overflow” error. So it isimportant to give an “end – condition” so that recursion eventually terminates.
It takes two natural numbers as arguments and yields another natural number. Its valuegrows extremely quickly; even for small inputs. For example for (4,3), the values of theAckermann function are so large that they cannot be feasibly computed, and in fact their decimal expansions require more digits than there are particles in the entire visibleuniverse.
Definition and properties
The Ackermann function is defined recursively for non-negative integers m and n asfollowsAck (0, n) = n + 1 for n >= 0Ack (m, 0) = Ack (m
1, 1) for m >= 1Ack (m, n) = Ack (m
1, Ack (m, n
1)) for m >= 1, n >= 1This may also be represented as: