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": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": false
|
"source": false
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "backlink",
|
"type": "backlink",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||||
"collapseAll": false,
|
"collapseAll": false,
|
||||||
"extraContext": false,
|
"extraContext": false,
|
||||||
"sortOrder": "alphabetical",
|
"sortOrder": "alphabetical",
|
||||||
@ -114,7 +114,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outgoing-link",
|
"type": "outgoing-link",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md",
|
"file": "Algo/Séminaire/Exercices seminaire.md",
|
||||||
"linksCollapsed": false,
|
"linksCollapsed": false,
|
||||||
"unlinkedCollapsed": true
|
"unlinkedCollapsed": true
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "outline",
|
"type": "outline",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "Algo/Séminaire/Chapter 5 - Recursivity.md"
|
"file": "Algo/Séminaire/Exercices seminaire.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -170,8 +170,8 @@
|
|||||||
},
|
},
|
||||||
"active": "0d2d422aa24bb900",
|
"active": "0d2d422aa24bb900",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
"Algo/Séminaire/Exercices seminaire.md",
|
|
||||||
"Algo/Séminaire/Chapter 5 - Recursivity.md",
|
"Algo/Séminaire/Chapter 5 - Recursivity.md",
|
||||||
|
"Algo/Séminaire/Exercices seminaire.md",
|
||||||
"Algo/Séminaire/Introduction.md",
|
"Algo/Séminaire/Introduction.md",
|
||||||
"Algo/Séminaire/Chapter 3 - Case analysis.md",
|
"Algo/Séminaire/Chapter 3 - Case analysis.md",
|
||||||
"Algo/Séminaire/Chapter 2 - Functions.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 :)
|
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**
|
**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) ?|
|
| |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>
|
<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
|
```Ocaml
|
||||||
(*First version ; 6 multiplications*)
|
(*First version ; 6 multiplications*)
|
||||||
@ -366,3 +366,11 @@ let rec multiply x y =
|
|||||||
eg b;;
|
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