You are on page 1of 1

INDIRECT RECURSION

Let’s say the value of n = 10;

funA(10)

def funA(n):

if(n > 0):


10
print(n)
9
funB(n – 1) // 10 subtracts to 1 results to 9, then pass its answer to funB(n)

def funB(n)

if(n > 1)
9
print(n)
4
funA(n // 2) // 9 divided by 2 results to 4.5/4, then pass its answer to funA(n)

def funA(n):

if(n > 0):


4
print(n)
3
funB(n – 1) // 4 subtracts to 1 results to 3, then pass its answer to funB(n)

def funB(n)

if(n > 1)
3
print(n)
1
funA(n // 2) // 3 divided by 2 results to 1.5/1, then pass its answer to funA(n)

def funA(n):

if(n > 0):


1
print(n)
0
funB(n – 1) // 1 subtracts to 1 results to 0, then the program will terminated since
funB(n) will not accept due to its condition, the value of n is greater than 1

Output:
 10 9 4 3 1
 The yellow highlighted text represents the answer.
 While the purple highlighted text represents the new value of n, passing onto another function.
 And the sky blue highlighted text is where the program will be terminated because zero [0] doesn’t pass the
condition of funB().

You might also like