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
147b13b0
Commit
147b13b0
authored
1 year ago
by
Mamadu-lamarana Bah
Browse files
Options
Downloads
Patches
Plain Diff
code review
parent
695fef09
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/BTree.py
+32
-13
32 additions, 13 deletions
src/BTree.py
src/Node.py
+48
-7
48 additions, 7 deletions
src/Node.py
with
80 additions
and
20 deletions
src/BTree.py
+
32
−
13
View file @
147b13b0
...
...
@@ -9,6 +9,14 @@ class Btree() :
def
search
(
self
,
value
):
"""
Rechercher une valeur dans l
'
arbre
Params :
value : (int), valeur à rechercher
Return :
(Node, index) : renvoie le noeud qui contient la valeur recherchée et son indice
dans ce noeud.
ne renvoie rien si valeur inéxistante
Exemple(s):
>>>
Btree
(
2
,
Node
([
5
,
25
])).
search
(
25
)
(
Node
([
5
,
25
]),
1
)
...
...
@@ -20,23 +28,30 @@ class Btree() :
def
insertion
(
self
,
value
):
"""
insérer une valeur dans l
'
arbre
Params :
value : (int), valeur à insérer
Return :
bool : (true) si insertion réussi, false sinon.
Exemple(s):
#
>>> a =Btree(2, Node([12, 42], [Node([2, 3]), Node([25]), Node([50])]))
#
>>> a.insertion(1)
#
True
#
>>> a.search(1)
#
(Node([1]), 0)
#
>>> b= Btree(3, Node([12,25,50], [Node([1,11]), Node([20]), Node([100])]))
#
>>> b.insertion(10)
#
True
#
>>> b.search(10)
#
(Node([1, 10, 11]), 1)
#
>>> Btree(2, Node([4, 10], [Node([1, 3]), Node([25]), Node([50])])).insertion(4)
#
True
>>>
a
=
Btree
(
2
,
Node
([
12
,
42
],
[
Node
([
2
,
3
]),
Node
([
25
]),
Node
([
50
])]))
>>>
a
.
insertion
(
1
)
True
>>>
a
.
search
(
1
)
(
Node
([
1
]),
0
)
>>>
b
=
Btree
(
3
,
Node
([
12
,
25
,
50
],
[
Node
([
1
,
11
]),
Node
([
20
]),
Node
([
100
])]))
>>>
b
.
insertion
(
10
)
True
>>>
b
.
search
(
10
)
(
Node
([
1
,
10
,
11
]),
1
)
>>>
Btree
(
2
,
Node
([
4
,
10
],
[
Node
([
1
,
3
]),
Node
([
25
]),
Node
([
50
])])).
insertion
(
4
)
True
>>>
c
=
Btree
(
2
,
Node
([
1
,
10
]))
>>>
c
.
insertion
(
15
)
True
"""
fini
,
milieu
,
g
,
d
=
self
.
root
.
insert
(
value
,
self
.
k
)
if
(
not
fini
):
...
...
@@ -47,7 +62,11 @@ class Btree() :
def
linearisation
(
self
):
"""
linéarise l
'
arbre en une liste triée dans l
'
order croissant
Return :
list : int
Exemple(s):
>>>
a
=
Btree
(
2
,
Node
([
12
,
42
],
[
Node
([
2
,
3
]),
Node
([
25
]),
Node
([
50
])]))
>>>
a
.
linearisation
()
...
...
This diff is collapsed.
Click to expand it.
src/Node.py
+
48
−
7
View file @
147b13b0
from
util
import
recherche_dichotomique
#from Visualization import *
#from BTree import *
class
Node
()
:
...
...
@@ -10,6 +8,11 @@ class Node() :
def
isLeaf
(
self
):
"""
verifie si un noeud est une feuille
Return :
bool : (true) si feuille, false sinon
Exemple(s):
>>>
Node
([
12
,
42
]).
isLeaf
()
True
>>>
Node
([
12
,
42
],
[
Node
([
1
]),
Node
([
25
]),
Node
([
50
])]).
isLeaf
()
...
...
@@ -22,6 +25,16 @@ class Node() :
def
search
(
self
,
value
):
"""
Rechercher une valeur dans un noeud
Params :
value : (int), valeur à rechercher
Return :
(Node, index) : renvoie le noeud qui contient la valeur recherchée et son indice
dans ce noeud.
ne renvoie rien si valeur inéxistante
Exemple(s):
>>>
Node
([
5
,
25
]).
search
(
5
)
(
Node
([
5
,
25
]),
0
)
...
...
@@ -43,7 +56,15 @@ class Node() :
def
is_ArbreB
(
self
,
k
,
is_root
=
False
):
"""
Verification de l
'
équilibrage de l
'
arbre
Verification de l
'
équilibrage d
'
un noeud
• Toutes les feuilles ont la même profondeur, à savoir la hauteur h de l’arbre.
• k/2 ≤ n ≤ k. Taux de remplissage min = 50%, et moyen 75%.
n = nombre de clés contenus dans le nœud x
• Si x n’est pas une feuille :
• pour 2<=i<=n, pour toute clef x du filsi : clesi <= x <=clesi+1
• Pour toute clef x du fils1 : x <= cles1
• Si x n’est pas la racine, n est compris entre k/2 et k.
Params :
k => number of keys in node
Return :
...
...
@@ -86,9 +107,16 @@ class Node() :
def
insert
(
self
,
value
,
k
):
"""
Return : (node, index) or Nothing
Exemple(s):
insérer une valeur dans un noeud
Params :
value : (int), valeur à insérer
Return : (True, _,_,_) si insertion réussi où (true) si valeur déjà présente
(False, _,_,_) si l
'
insertion a été faite mais que l
'
arbre n
'
est pas équilibré,
dans ce cas on délègue le travail restant au père.
Exemple(s):
>>>
node
=
Node
([])
>>>
node
.
insert
(
5
,
1
)
(
True
,
None
,
None
,
None
)
...
...
@@ -117,8 +145,6 @@ class Node() :
>>>
node
=
Node
([
12
,
42
],
[
Node
([
2
,
3
,
4
]),
Node
([
25
]),
Node
([
50
])])
>>>
node
.
insert
(
1
,
3
)
(
True
,
None
,
None
,
None
)
"""
(
found
,
index
)
=
recherche_dichotomique
(
value
,
self
.
keys
)
if
(
not
found
)
:
...
...
@@ -146,6 +172,7 @@ class Node() :
def
suppression
(
self
,
value
,
k
,
is_root
=
False
)
:
"""
supprime une
Exemple(s):
>>>
node
=
Node
([
42
],
[
Node
([
14
]),
Node
([
50
])])
>>>
node
.
suppression
(
14
,
2
)
...
...
@@ -195,6 +222,12 @@ class Node() :
def
splitNode
(
self
)
:
"""
Divise un noeud
Return :
(milieu, gauche, droite) : la valuer du milieu, de gauche et de droite.
Exemple(s):
>>>
Node
([
10
,
20
,
25
]).
splitNode
()
(
20
,
Node
([
10
]),
Node
([
25
]))
>>>
Node
([
12
,
20
,
22
,
40
]).
splitNode
()
...
...
@@ -210,6 +243,11 @@ class Node() :
def
linearisation
(
self
):
"""
linéarise un noeud en une liste triée dans l
'
order croissant
Return :
list : int
Exemple(s):
>>>
Node
([
12
,
42
],
[
Node
([
2
,
3
]),
Node
([
13
,
15
]),
Node
([
45
])]).
linearisation
()
[
2
,
3
,
12
,
13
,
15
,
42
,
45
]
...
...
@@ -228,6 +266,9 @@ class Node() :
def
__repr__
(
self
)
:
"""
répresentation d
'
un noeud et de ces fils.
"""
return
(
f
"
Node(
{
self
.
keys
}
"
+
(
f
"
,
{
self
.
childs
}
)
"
if
len
(
self
.
childs
)
>
0
else
"
)
"
))
...
...
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