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
394e0378
Verified
Commit
394e0378
authored
3 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added search
parent
26736b38
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#15035
passed
3 years ago
Stage: test
Changes
2
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
slides/cours_11.md
+87
-12
87 additions, 12 deletions
slides/cours_11.md
slides/figs/sorted_list_position.svg
+1202
-0
1202 additions, 0 deletions
slides/figs/sorted_list_position.svg
with
1289 additions
and
12 deletions
slides/cours_11.md
+
87
−
12
View file @
394e0378
...
...
@@ -416,10 +416,23 @@ Une liste chaînée triée est:
# Les listes triées
## Quelle structure de données?
## Quel but?
*
Permet de retrouver rapidement un élément.
*
Utile pour la recherche de plus court chemin dans des graphes.
*
Ordonnancement de processus par degré de priorité.
## Comment?
*
Les implémentations les plus efficaces se basent sur les tableaux.
*
Possibles aussi avec des listes chaînées.
# Les listes triées
## Quelle structure de données dans notre cas?
Une liste chaînée bien sûr!
Une liste chaînée bien sûr (oui c'est pour vous entraîner)!
```
C
typedef struct _element { // chaque élément
...
...
@@ -614,19 +627,81 @@ element* sorted_list_search(sorted_list list, int val);
. . .
```
C
element* recherche(liste lst,int val) {
element* pos = position(lst,val);
if (est_vide(lst)) {
return NULL;
element* sorted_list_search(sorted_list list, int val) {
// search for element smaller than val
element* pos = sorted_list_position(list, val);
if (NULL == pos && val == list->data) {
return list; // first element contains val
} else if (NULL != pos->next && val == pos->next->data) {
return pos->next; // non-first element contains val
} else {
return NULL; // well... val's not here
}
if (NULL == pos && val == lst->n) {
return lst;
} else if (NULL != pos->suivant && val == pos->suivant->n) {
return pos->suivant;
}
```
# La recherche
## La fonction `sorted_list_position`
```
C
element* sorted_list_position(sorted_list list, int val);
```

# La recherche
## Exercice: implémenter
```
C
element* sorted_list_position(sorted_list list, int val);
```
. . .
```
C
element* sorted_list_position(sorted_list list, int val) {
element* pos = list;
if (sorted_list_is_empty(list) || val <= list->data) {
pos = NULL;
} else {
return NULL;
while (NULL != pos->next && val > pos->next>data) {
pos = pos->next;
}
}
return pos;
}
```
# Exercice: recherche sans position
# Complexité de la liste chaînée triée
## L'insertion?
. . .
$$
\m
athcal{O}(N).
$$
## L'extraction?
. . .
$$
\m
athcal{O}(N).
$$
## La recherche?
. . .
$$
\m
athcal{O}(N).
$$
# Liste doublement chaînée
This diff is collapsed.
Click to expand it.
slides/figs/sorted_list_position.svg
0 → 100644
+
1202
−
0
View file @
394e0378
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