Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 734. Ackermann's Function

Created by Richard Zapor

Ackermann's Function is a recursive function that is not 'primitive recursive.'

Ackermann Function

The first argument drives the value extremely fast.

A(m, n) =

  • n + 1 if m = 0
  • A(m − 1, 1) if m > 0 and n = 0
  • A(m − 1,A(m, n − 1)) if m > 0 and n > 0

A(2,4)=A(1,A(2,3)) = ... = 11.

% Range of cases
% m=0 n=0:1024
% m=1 n=0:1024
% m=2 n=0:128
% m=3 n=0:6
% m=4 n=0:1

There is some deep recusion.

Input: m,n

Out: Ackerman value

Ackermann(2,4) = 11

Practical application of Ackermann's function is determining compiler recursion performance.

Problem Group

Solution Statistics

14 correct solutions 59 incorrect solutions
Last solution submitted on May 01, 2016

Problem Comments