Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-Dahmane-lynda
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
Lynda Dahmane
AP-Dahmane-lynda
Commits
6ca6fcef
Commit
6ca6fcef
authored
1 year ago
by
Dahmane Lynda
Browse files
Options
Downloads
Patches
Plain Diff
Tp2
parent
dd22dd28
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
Tp2/recursivite.py
+17
-2
17 additions, 2 deletions
Tp2/recursivite.py
with
17 additions
and
2 deletions
Tp2/recursivite.py
+
17
−
2
View file @
6ca6fcef
...
...
@@ -292,7 +292,9 @@ def puissance_calbuth_v2(x: int|float, n: int) -> int|float:
#Q6:
# le gain dépend du nombre de fois ou la puissance est dévisée par 2.
#Q7:
# la fonction de n
# lorque n est un nombre pair
#si n est impair, pour se ramener au cas ou n est pair , on peut utiliser un appel recursif en decrementant
#n de 1, ainsi on obtient un nouveau n pair sur lequel on peut appliquer la fonction puissance_calbuth
...
...
@@ -314,7 +316,13 @@ def puissance_calbuth_v2_amelioree(x: int|float, n: int) -> int|float:
1024
"""
...
if
n
==
0
:
return
1
elif
n
%
2
==
0
:
temps
=
puissance_calbuth_v2_amelioree
(
x
,
n
//
2
)
return
temps
*
temps
else
:
return
x
*
puissance_calbuth_v2_amelioree
(
x
,
n
-
1
)
def
puissance_erronee
(
x
:
int
|
float
,
n
:
int
)
->
int
|
float
:
"""
...
...
@@ -341,6 +349,13 @@ def puissance_erronee(x: int|float, n: int) -> int|float:
q
=
n
//
2
return
puissance_erronee
(
x
,
r
)
*
puissance_erronee
(
puissance_erronee
(
x
,
q
),
2
)
#Q8:
#oui son idée améliorée permet en effet de diminuer la complexité en nombre
#de multiplications dans le calcul de la puissance . cette approche utilise le récursion pour déviser les problèmes
#en sous-problèmes plus petits et évite ainsi derépeter les multiplications inutilement.
# la fonction puissance calbuth v2 amelioree effectue seulement les multiplications nécessaires pour obtenir le résultat final.
def
puissance_reparee
(
x
:
int
|
float
,
n
:
int
)
->
int
|
float
:
"""
calcule x élevé à la puissance n
...
...
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