Académique Documents
Professionnel Documents
Culture Documents
MSI 1 U-FOAD
MSI 1 U-FOAD 2
STRUCTURES
ALGORITHMIQUES
Structures de contrôle :
Séquence
Embranchement (ou sélection)
Boucle (ou itération)
Structures de données :
Constantes
Variables
Tableaux
Structures récursives (Listes, arbres, graphes)
MSI 1 U-FOAD 3
COMPLEXITE DES
ALGORITHMES
On veut:
Evaluer l’efficacité de la méthode M
Comparer M avec une autre méthode M’, indépendamment de
l’environnement (machine, système, compilateur,…)
MSI 1 U-FOAD 4
COMPLEXITE DES
ALGORITHMES
MSI 1 U-FOAD 5
EVALUATION T(n)
(SEQUENCE)
MSI 1 U-FOAD 6
EVALUATION T(n)
(EMBRANCHEMENT)
MSI 1 U-FOAD 7
EVALUATION T(n)
(BOUCLE)
MSI 1 U-FOAD 8
EVALUATION T(n)
(FONCTIONS
RECURSIVES)
MSI 1 U-FOAD 9
NOTION DE LANDAU
O(f(n))
c x f(n)
T(n) = O(f(n))
n0 n
Caractérise le comportement asymptotique (i.e quand n→ ∞ ).
T(n)=O(f(n)) si ∃𝑐∃𝑛𝑜 tels que ∀𝑛>no, T(n) ≤ 𝑐 ∗ 𝑓(𝑛)
MSI 1 U-FOAD 10
NOTATION
𝜃(𝑓 𝑛 )
C2*f(n)
T(n)
C1*f(n)
n0 n
T(n)= 𝜃(f(n)) si ∃𝑐1, 𝑐2, 𝑛𝑜 tels que ∀𝑛>no, 𝑐1 ∗ 𝑓(𝑛) ≤ 𝑐2 ∗ 𝑓(𝑛)
MSI 1 U-FOAD 11
EXEMPLES
MSI 1 U-FOAD 12
PRINCIPALES CLASSES
DE COMPLEXITE
MSI 1 U-FOAD 13
Exemple: Permutation
fonction permutation( S, i, j)
1 tmp := S[i], coût c1
2 S[i] := S[j], coût c2
3 S[j] := tmp, coût c3
4 Renvoyer S coût c4
MSI 1 U-FOAD 14
Exemple: recherche
séquentielle
fonction permutation( S, i, j)
1 tmp := S[i], coût c1
2 S[i] := S[j], coût c2
3 S[j] := tmp, coût c3
4 Renvoyer S coût c4
MSI 1 U-FOAD 15
Exemple: tri à bulle
fonction Tri( S, n)
1 pour i := n à 2 faire (n-1 fois)
2 pour j := 1 à i-1 faire (n-1 fois)
3 Si (S[j]>S[j+1] alors
4 Permuter S[j] et S[j+1] dans S
𝐶𝑝𝑒𝑟𝑚 ∗𝑛∗(𝑛−1)
T(n) = Cperm+σ𝑛−1
𝑖=1 𝑖 = =𝑂(𝑛2 )
2
MSI 1 U-FOAD 16
EQUATION
RECURSIVE
MSI 1 U-FOAD 17
Par Substitution
MSI 1 U-FOAD 18
Par Substitution
MSI 1 U-FOAD 19
Par Substitution:
Equations récursives
MSI 1 U-FOAD 20
Méthode itérative: Rappel
sommations
𝑛−1 𝑛 ∗ (𝑛 − 1)
𝑖= = 𝑜(𝑛2)
𝑖=1 2
𝑛 𝑛+1 − 1
𝑥
𝑥𝑖 =
𝑖=0 𝑥−1
𝑛
2𝑛+1 − 1
𝑖=0
MSI 1 U-FOAD 21
Méthode itérative:
Equations récursives
MSI 1 U-FOAD 22
Méthode itérative:
Equations récursives
T(1)=1
T(n) = 2n+1+2T(n/2)
MSI 1 U-FOAD 23
Méthode itérative:
Equations récursives
T(1)=1
T(n) = 2n+1+2T(n/2)
donc T(n/2)=n+1+2T(n/4)
T(n)=(2n+1)+(2n+2)+4T(n/4)
MSI 1 U-FOAD 24
Méthode itérative:
Equations récursives
T(1)=1
T(n) = 2n+1+2T(n/2)
donc T(n/2)=n+1+2T(n/4)
T(n)=(2n+1)+(2n+2)+4T(n/4)
or T(n/4)=n/2+1+2T(n/8)
T(n)=(2n+1)+(2n+2)+(2n+4)+8T(n/8)
…
MSI 1 U-FOAD 25
Méthode itérative:
Equations récursives
T(1)=1
T(n) = 2n+1+2T(n/2)
donc T(n/2)=n+1+2T(n/4)
T(n)=(2n+1)+(2n+2)+4T(n/4)
or T(n/4)=n/2+1+2T(n/8)
T(n)=(2n+1)+(2n+2)+(2n+4)+8T(n/8)
…
log 𝑛−1
T(n)=σ𝑖=0 2𝑛 + 2𝑖 + 2log 𝑛
MSI 1 U-FOAD 26
Méthode itérative:
Equations récursives
T(1)=1
T(n) = 2n+1+2T(n/2)
donc T(n/2)=n+1+2T(n/4)
T(n)=(2n+1)+(2n+2)+4T(n/4)
or T(n/4)=n/2+1+2T(n/8)
T(n)=(2n+1)+(2n+2)+(2n+4)+8T(n/8)
…
log 𝑛−1
T(n)=σ𝑖=0 2𝑛 + 2𝑖 + 2log 𝑛
log 𝑛−1 𝑖
T(n)= 2n log n + 𝑖=0
σ 2 +𝑛
MSI 1 U-FOAD 27
Méthode itérative:
Equations récursives
T(1)=1
T(n) = 2n+1+2T(n/2)
donc T(n/2)=n+1+2T(n/4)
T(n)=(2n+1)+(2n+2)+4T(n/4)
or T(n/4)=n/2+1+2T(n/8)
T(n)=(2n+1)+(2n+2)+(2n+4)+8T(n/8)
…
log 𝑛−1
T(n)=σ𝑖=0 2𝑛 + 2𝑖 + 2log 𝑛
log 𝑛−1 𝑖
T(n)= 2n log n + 𝑖=0
σ 2 + 𝑛 et comme
+ 1 − 1, log 𝑛
σ𝑛𝑖=0 2𝑖
= 2 𝑛 𝑎 𝑜𝑛 σlog
𝑖=0
𝑛−1 𝑖
2 =2 −1
T(n)=2nlog n + 2n-1 = O(n log n)
MSI 1 U-FOAD 28
Méthode itérative:
Equations récursives
MSI 1 U-FOAD 29
Méthode générale:
Equations récursives
MSI 1 U-FOAD 30
Méthode par substitution:
Equations récursives
MSI 1 U-FOAD 31
Temps de Calcul:
Simulation
1000 0.01 ms 1 ms 10 ms 1s
MSI 1 U-FOAD 32
Temps de Calcul:
Simulation
MSI 1 U-FOAD 33