Skip to content
Snippets Groups Projects
Commit a2f3c6eb authored by Dominik Zobel's avatar Dominik Zobel Committed by Tobias Koelling
Browse files

Adjust Fibonacci example slides

parent bce19ef9
No related branches found
No related tags found
1 merge request!24complexity lecture
...@@ -63,7 +63,9 @@ Tree[^1] $\mathcal{O}(\log{n})$ $\mathcal{O}(\log{n})$ ...@@ -63,7 +63,9 @@ Tree[^1] $\mathcal{O}(\log{n})$ $\mathcal{O}(\log{n})$
# an example # an example
*(Fibonacci)* *(Fibonacci)*
## Fibonacci series ## Fibonacci series example (1/3) {.leftalign}
:::{.smaller}
$$ $$
f(0) = 0 \\ f(0) = 0 \\
...@@ -71,7 +73,11 @@ f(1) = 1 \\ ...@@ -71,7 +73,11 @@ f(1) = 1 \\
f(n) = f(n-2) + f(n-1) f(n) = f(n-2) + f(n-1)
$$ $$
## fib1 :::
:::{.fragment}
Direct implementation
```{python} ```{python}
#| echo: true #| echo: true
...@@ -88,7 +94,13 @@ def fib1(n): ...@@ -88,7 +94,13 @@ def fib1(n):
fib1(30) fib1(30)
``` ```
## fib2 :::
## Fibonacci series example (2/3) {.leftalign}
Alternative implementation
```{python} ```{python}
#| echo: true #| echo: true
def fib2(n): def fib2(n):
...@@ -100,12 +112,19 @@ def fib2(n): ...@@ -100,12 +112,19 @@ def fib2(n):
[fib2(i) for i in range(10)] [fib2(i) for i in range(10)]
``` ```
:::{.fragment}
```{python} ```{python}
#| echo: true #| echo: true
%%time %%time
fib2(30) fib2(30)
``` ```
$\Rightarrow$ Substantially faster
:::
## fib3 ## fib3
$$ $$
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment