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 could I write a program to convert Km/h to m/s in python


Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour


Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


Write a Python script to take a product name as input and then automatically google search reviews for it and open the top 3 search results in different tabs