You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: allhands/spring2025/weekeleven/teamthree/index.qmd
+14-4Lines changed: 14 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,11 @@ concrete data which can ultimately used to help inform implementation decisions.
38
38
39
39
### Generate Fibonacci using a Recursive approach
40
40
41
-
The recursive approach computes Fibonacci numbers by repeatedly calling the function itself. However, this method is highly inefficient because it recalculates the same values multiple times. For example, to compute fibonacci_recursive(5), the function computes fibonacci_recursive(2) three times:
41
+
The recursive approach computes Fibonacci numbers by repeatedly calling the function itself.
42
+
However, this method is highly inefficient because it recalculates the same values multiple
43
+
times. For example, to compute fibonacci_recursive(5), the function computes
44
+
fibonacci_recursive(2) three times:
45
+
42
46
```python
43
47
fibonacci_recursive(5)
44
48
├── fibonacci_recursive(4)
@@ -56,7 +60,10 @@ fibonacci_recursive(5)
56
60
│ ├── fibonacci_recursive(0) → 0
57
61
├── fibonacci_recursive(1) → 1
58
62
```
59
-
As shown above, even for a small input like n = 5, the function makes redundant calculations, leading to an exponential growth in execution time.
63
+
64
+
As shown above, even for a small input like n = 5, the function makes redundant calculations,
65
+
leading to an exponential growth in execution time.
66
+
60
67
```python
61
68
deffibonacci_recursive(n: int) -> int:
62
69
"""Generates the Fibonacci sequence up to the nth term using recursion without memoization."""
It takes in integer as an input and outputs an integer which is the fibonacci number's answer. There are two base cases for this approach which the input integer, in this case "n", is equal to 0 and 1. Each function call branches into two recursive calls, forming a binary tree of depth n. This results in an exponential number of operations, making the approach extremely slow for large values of n. Therefore, the worst-time complexity is O(n^2)!
78
-
84
+
It takes in integer as an input and outputs an integer which is the fibonacci number's answer.
85
+
There are two base cases for this approach which the input integer, in this case "n", is equal
86
+
to 0 and 1. Each function call branches into two recursive calls, forming a binary tree of
87
+
depth n. This results in an exponential number of operations, making the approach extremely
88
+
slow for large values of n. Therefore, the worst-time complexity is $O(n^2)$!
0 commit comments