Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projet_s6_loic.scoth.etu_mamadulamarana.bah.etu
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
Loic Scoth
projet_s6_loic.scoth.etu_mamadulamarana.bah.etu
Commits
141276f7
Commit
141276f7
authored
1 year ago
by
Mamadu-lamarana Bah
Browse files
Options
Downloads
Patches
Plain Diff
ajout docs de monsieur pour rech_dicho
parent
32ea3562
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/util.py
+26
-13
26 additions, 13 deletions
src/util.py
with
26 additions
and
13 deletions
src/util.py
+
26
−
13
View file @
141276f7
...
...
@@ -26,22 +26,30 @@ def compare(a, b):
return
res
def
recherche_dichotomique
(
x
,
l
,
cmp
=
compare
):
"""
:param x: (any) un élément
:param l: (list) une liste
:return: (bool) True si x appartient à l, False sinon
:CU: x doit être comparable aux éléments de l
,
l est triée
:Exemples:
"""
Renvoie l
'
unique `index` vérifiant :
* 0 ≤ index ≤ len(liste)
* ∀j ∈ [0 ; len(liste)[, si j < index alors liste[j] < x
sinon liste[j] ≥ x
Cet indice `index` indiquera soit la place de l
'
élément x dans la liste
,
soit la place du fils susceptible de contenir l
'
élément x recherché
dans un arbre de recherche.
>>>
recherche_dichotomique
(
1
,
[])
Précondition : `liste` est triée par ordre croissant
Exemple(s) :
>>>
recherche_dichotomique
(
3
,
[
1
,
3
,
5
])
(
True
,
1
)
>>>
recherche_dichotomique
(
4
,
[
1
,
3
,
5
])
(
False
,
2
)
>>>
recherche_dichotomique
(
0
,
[
1
,
3
,
5
])
(
False
,
0
)
>>>
recherche_dichotomique
(
42
,
[
1
,
3
,
5
])
(
False
,
3
)
>>>
recherche_dichotomique
(
42
,
[])
(
False
,
0
)
>>>
l
=
list
(
range
(
10
))
>>>
recherche_dichotomique
(
5
,
l
)
(
True
,
5
)
>>>
recherche_dichotomique
(
5.5
,
l
)
(
False
,
6
)
"""
# précondition : liste triée
assert
all
(
l
[
k
]
<=
l
[
k
+
1
]
for
k
in
range
(
len
(
l
)
-
1
))
# votre code ici sans le return
taille
=
len
(
l
)
debut
,
fin
=
0
,
taille
index
=
0
...
...
@@ -55,6 +63,11 @@ def recherche_dichotomique(x, l, cmp = compare):
else
:
fin
=
milieu
index
=
milieu
# postcondition
assert
0
<=
index
<=
len
(
l
)
assert
all
(
j
<
index
and
l
[
j
]
<
x
or
l
[
j
]
>=
x
for
j
in
range
(
len
(
l
)))
# retour
return
(
False
,
index
)
## LOIC
...
...
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