What are recursive functions and when should they be used?

A recursive function is one that calls itself from within its own code, usually in order to perform the same operation on a smaller part of the original input, or on an edited version of the input. Recursive functions are often used in tree search algorithms to search the root node and it's child nodes and then their child nodes and so on. They can also be used in sorting algorithms to break an array up in to smaller pieces and use a divide and conquer approach.

JB
Answered by Joseph B. Python tutor

1539 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

When do we use a for-loop and when a while-loop?


Write a function that takes a list of numbers as input, and outputs the average of the numbers. The function should catch any errors.


Give a segment of python code that will print the numbers 1 to 7, each one on a new line


Write a recursive function that takes any integer n and prints the nth Fibonacci number.


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2025 by IXL Learning