Artificial Intelligence Algorithms
Learning Objectives
Tools
Let's look at an example of a function that calls another.
Recursive Function
The recursive function consists of two states:
Recursion Common Examples
Now let's calculate the factorial of a number using a factorial function.
Table 2.2: Advantages and disadvantages of recursion
Recursion and Iteration
Table 2.3: Recursion and Iteration
When do you use recursion?
In the next program, you will create a recursive function to calculate the power of a number.
Infinite Recursive Function
Read the sentences and tick True or False.
What are the differences between iteration and recursion?
When should recursion be used?
List the advantages and disadvantages of using recursion.
Write a Python recursive function to calculate the nth largest number in a list.
Write a Python recursive function to calculate the sum of all the even numbers in a list.