1/7
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
recursive function
a function that calls itself, usually involves if-else to control number of times it repeats
depth of recursion
the number of times a function
calls itself
problem solve with recursion
powerful tool when solving repetitive problems, can be solved with a loop, less efficient overall
base case
can be solved without recursion (if start index> end index return 0)
recursive case
reduce problem to smaller problem of the
same structure and call the function again to solve the
smaller problem (return current_number + sum(list, start+1, end))
calculate factorial of number with recursion
n=0 is base case, n>0 is recursive case (factorial(n)=n*factorial(n-1))
def factorial(num):, if num == 0:, return 1, else:, return num*factorial(num-1)
direct recursion
when a function directly calls itself
indirect recursion
when function A calls function B,
which in turn calls function A