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

Related Python Mentoring answers

All answers ▸

How might we implement the bubble sort algorithm in Python


How can you take a list of numbers and add 3 to every number in the list using only one line of code?


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


Which four data types are used in Python? Can you give an example of each?