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 ▸

What is Object-Oriented Programming?


[Exam style] Python is an interpreted language. Explain what this means and how interpreted languages differ from compiled languages.


What is the outcome of the following code? print(2*[3,4,5])


Define a function that takes in the age of the user and adds it to an output sentence such as "You are ..... old".