Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Ackermann Function

Ackermann Function

Ratings: (0)|Views: 352|Likes:
Published by mukeshnt
recursion, ackermann's function, c, c++, c# program
recursion, ackermann's function, c, c++, c# program

More info:

Published by: mukeshnt on Oct 23, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/16/2013

pdf

text

original

 
Recursion – Ackermann’s Function
Prof. Mukesh N. Tekwani
Page 1 of 3 
Recursion
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
 direct recursion
. If a function calls another function, which in turn makes a call to the first one,it is called
indirect recursion
.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.
Ackermann function
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:
 
Recursion – Ackermann’s Function
Prof. Mukesh N. Tekwani
Page 2 of 3 The evaluation of these functions always terminates. The recursion is bounded because ineach recursion either m decreases, or m remains the same and n decreases. Each time thatn reaches zero, m decreases, so m eventually reaches zero as well. However, when mdecreases there is no upper bound on how much n can increase.For small values of m like 1, 2, or 3, the Ackermann function grows relatively slowlywith respect to n. For m
4, however, it grows much more quickly. The expansion of A(4, 3) cannot be recorded in the known physical universe.Computing A(1, n) takes linear time in n. Computing A(2, n) takes quadratic time in n.The time required for higher values of m, is much more.
Explanation 
We now illustrate the expansion of the function for m = 1, and n = 2. Theevaluation of 
 A
(1, 2) proceeds as follows:A(1, 2) = A(0, A(1, 1))= A(0, A(0, A(1, 0)))= A(0, A(0, A(0, 1)))= A(0, A(0, 2))= A(0, 3)= 4
Applications of Ackermann’s function 
The Ackermann function, due to its definition in terms of extremely deep recursion, can be used as a benchmark of a compiler's ability to optimize recursion. This function can beused to compare the amount of time required to evaluate this function for fixed argumentsin many different programming language implementations.

Activity (4)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Tapas Trivedi liked this
yonny_septian liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->