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 ▸

[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


Write a python function that takes a string as parameter and returns the character in the string with the most occurrences, along with the number of times this character occurs


Sales is real Customers is integer startmainprog input Sales input Customers if ((Sales > 500) OR ((Sales > 300) AND (Customers>9))) then output “Bonus Awarded” else output “No Bonus” end if end subroutine. Sales = 600 Customers = 9, answer:


Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10