Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
algorithmique
cours
Commits
126d9c93
Verified
Commit
126d9c93
authored
3 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
updated with search
parent
cc33d36f
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#15687
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slides/cours_15.md
+60
-4
60 additions, 4 deletions
slides/cours_15.md
with
60 additions
and
4 deletions
slides/cours_15.md
+
60
−
4
View file @
126d9c93
...
@@ -764,15 +764,71 @@ sous-arbres de gauche et de droite.
...
@@ -764,15 +764,71 @@ sous-arbres de gauche et de droite.
```
python
```
python
arbre
recherche
(
clé
,
arbre
)
arbre
recherche
(
clé
,
arbre
)
tante
que
est_non_vide
(
arbre
)
tante
_
que
est_non_vide
(
arbre
)
si
clé
<
arbre
.
clé
si
clé
<
clé
(
arbre
)
arbre
=
gauche
(
arbre
)
arbre
=
gauche
(
arbre
)
sinon
si
clé
>
arbre
.
clé
sinon
si
clé
>
clé
(
arbre
)
arbre
=
droite
(
arbre
)
arbre
=
droite
(
arbre
)
sinon
sinon
retourne
arbre
retourne
arbre
retourne
NULL
retourne
NULL
```
```
# Algorithme de recherche, implémentation (live)
\f
ootnotesize
. . .
```
C
typedef int key_t;
typedef struct _node {
key_t key;
struct _node* left;
struct _node* right;
} node;
typedef node* tree_t;
tree_t search(key_t key, tree_t tree) {
tree_t current = tree;
while (NULL != courant && !success) {
if (current->key > X) {
current = courant->gauche;
} else if (current->key < X){
current = courant->droite;
} else {
return current;
}
}
return NULL;
}
```
# Exercice (5-10min)
Écrire le code de la fonction
```
C
int tree_size(tree_t tree);
```
qui retourne le nombre total de noeuds d'un arbre et poster le résutat sur
matrix.
Indication: la taille, est 1 + le nombre de noeuds du sous-arbre de gauche
additionné au nombre de noeuds dans le sous-arbre de droite.
. . .
```
C
int arbre_size(tree_t tree) {
if (NULL == tree) {
return 0;
} else {
return 1 + tree_size(tree->left) + tree_size(tree->right);
}
}
```
[
^1
]:
Copyright
cours de mathématiques pendant trop d'années.
[
^1
]:
Copyright
cours de mathématiques pendant trop d'années.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment