Self-assessment quiz
Presentation & objectives
The following quizzes are here to help you check that you understood the articles you had to study. They are provided for self-assessment and will not be graded or stored.
Don’t hesitate to reach out on the Discord server for any precision/explanation!
Quizzes
---
secondary_color: lightgray
---
# Recursive algorithms
What is a base case in a recursive function?
- [x] The part of the function where the recursion stops and a result is returned.
- [ ] The part of the function that calls itself.
- [ ] The maximum depth the recursion can reach.
- [ ] The initial call to the recursive function.
# Recursive algorithms
Given the following recursive function, what will be the output of `foo(3)`?
```python
def foo (n: int) -> int:
if n == 0:
return 1
else:
return n - 1 * foo(n)
```
- [ ] 6.
- [x] The input is not getting "smaller", this leads to infinite recursion.
- [ ] The base case is incorrect, this leads to infinite recursion.
- [ ] The recursive call is not always connected to the base: this may lead to infinite recursion.
# Recursive algorithms
Given the following recursive function, what will be the output of `bar(4)`?
```python
def bar (n: int) -> int:
if n == 0:
return 1
else:
return n + bar(n - 2)
```
- [x] 7.
- [ ] The input is not getting "smaller", this leads to infinite recursion.
- [ ] The base case is incorrect, this leads to infinite recursion.
- [ ] The recursive call is not always connected to the base: this may lead to infinite recursion.
# Recursive algorithms
Given the following recursive function, what will be the output of `bar(3)`?
```python
def bar (n: int) -> int:
if n == 0:
return 1
else:
return n + bar(n - 2)
```
- [ ] 4.
- [ ] The input is not getting "smaller", this leads to infinite recursion.
- [ ] The base case is incorrect, this leads to infinite recursion.
- [x] The recursive call is not always connected to the base: this may lead to infinite recursion.