vault backup: 2023-09-15 16:17:18
This commit is contained in:
parent
ffe134144f
commit
3f37a1ccb5
10
.obsidian/workspace.json
vendored
10
.obsidian/workspace.json
vendored
@ -13,7 +13,7 @@
|
||||
"state": {
|
||||
"type": "markdown",
|
||||
"state": {
|
||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||
"mode": "source",
|
||||
"source": false
|
||||
}
|
||||
@ -97,7 +97,7 @@
|
||||
"state": {
|
||||
"type": "backlink",
|
||||
"state": {
|
||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||
"collapseAll": false,
|
||||
"extraContext": false,
|
||||
"sortOrder": "alphabetical",
|
||||
@ -114,7 +114,7 @@
|
||||
"state": {
|
||||
"type": "outgoing-link",
|
||||
"state": {
|
||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||
"linksCollapsed": false,
|
||||
"unlinkedCollapsed": true
|
||||
}
|
||||
@ -137,7 +137,7 @@
|
||||
"state": {
|
||||
"type": "outline",
|
||||
"state": {
|
||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md"
|
||||
"file": "Algo/Séminaire/Exercices seminaire.md"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -170,8 +170,8 @@
|
||||
},
|
||||
"active": "0d2d422aa24bb900",
|
||||
"lastOpenFiles": [
|
||||
"Algo/Séminaire/Exercices seminaire.md",
|
||||
"Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||
"Algo/Séminaire/Exercices seminaire.md",
|
||||
"Algo/Séminaire/Introduction.md",
|
||||
"Algo/Séminaire/Chapter 3 - Case analysis.md",
|
||||
"Algo/Séminaire/Chapter 2 - Functions.md",
|
||||
|
@ -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
|
||||
```
|
||||
|
@ -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 ->
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user