vault backup: 2023-09-15 16:17:18

This commit is contained in:
2023-09-15 16:17:18 +02:00
parent ffe134144f
commit 3f37a1ccb5
3 changed files with 31 additions and 7 deletions

View File

@ -119,6 +119,12 @@ Exemple with egypt (4.10) vs multiply (4.6):
The best algorithm in term of complexity is the parameter that is constant/linear or logarithmic. If you have an exponential algorithm, you can put it in trash :)
**Exemple with fibonacci algorithm**
```Ocaml
# let rec fibo = function
0|1 -> 1
| n -> fibo (n-1) + fibo(n-2);;
```
| |res|how (for human) ?|How (for function) ?|
|:----:|:----:|:----:|:----:|
@ -133,4 +139,14 @@ The best algorithm in term of complexity is the parameter that is constant/linea
<center><img src="https://imgur.com/6OWREOm.png" height=400 width=auto/></center>
This function is not optimize because the number of calls is growing exponentially
This function is not optimize because the number of calls is growing exponentially.
A good function will be:
```Ocaml
# let fibo n =
let rec fib i fi fi_1 =
if n <= i then
fi
else
fib (i+1)(fi+fi_1)fi
in fib 1 1 1
```

View File

@ -1,5 +1,5 @@
|## Exercise 2.2 (Power)
## Exercise 2.2 (Power)
```Ocaml
(*First version ; 6 multiplications*)
@ -366,3 +366,11 @@ let rec multiply x y =
eg b;;
```
## Exercise 4.11
```Ocaml
let rec puissance = function
|n when n = 0 -> 1
|n when n = 1 -> x
|n ->
```