Problem
This function takes a number and calculates its factorial using recursion.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
Solution
Input Size | Recursions |
---|---|
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
How does the running time increase w.r.t the input?
The number of recursions is determined by the size of the input: .
What is the time complexity?
This workbook was created by Jad and Rayan Slim. Feel free to explore some of their courses:
The Complete Java Development Bootcamp
The Complete Spring Boot Development Bootcamp – Become a Java Web Developer
Feedback Summary
0.0
0 students
5
0%
4
0%
3
0%
2
0%
1
0%
Written Reviews
There are no written reviews yet.