Search⌘ K

Direct Vs. Indirect Recursion

Explore the concepts of direct and indirect recursion to understand how recursive calls work in Python functions. This lesson breaks down one-step recursion and mutual recursion with practical examples of printing natural numbers. By completing this lesson, you'll grasp how recursion flows in both scenarios, preparing you for more advanced recursive problem-solving.

Direct Recursion

Direct recursion occurs when a function calls itself.

This results in a one-step recursive call, meaning that the function makes a recursive call inside its own function body.

Syntax of Direct Recursion

def function1(p1, p2, ..., pn) :
  # Some code here
  function1(p1, p2, ..., pn)
  # Some code here

Printing Natural Numbers from 11 to nn

...