15 Commits

Author SHA1 Message Date
abraham 3a34aa916b information pc test 2026-10-21 12:34:23 +02:00
abraham 3acfa79dcd EXO 4 - optimisation F5 2026-10-21 12:07:28 +02:00
abraham 22d249dd5e information sup 2026-10-21 11:51:47 +02:00
abraham 7c09526d0a fonction 10 : O(L) 2026-10-21 11:49:58 +02:00
abraham b40a1c2081 fonction 8 : O(S x k) 2026-10-21 11:44:36 +02:00
abraham dc5f6dbbd9 EXO 4 - optimisation F3 2026-10-21 11:39:59 +02:00
abraham 1b9c2aace2 prepare le merge 2026-10-21 11:36:11 +02:00
abraham 1ada0848f4 merge 2026-10-21 11:27:32 +02:00
abraham a5882012df fusion 2026-10-21 11:27:00 +02:00
Ozvann Abraham 310c57d1ff Merge pull request 'EXO 4 - optimisation F1' (#1) from framery/2026_TD3_DEV51_Qualite_Algo:main into main
Reviewed-on: abraham/2026_TD3_DEV51_Qualite_Algo#1
2026-10-21 11:25:48 +02:00
Ozvann Abraham 97155f2688 Merge branch 'main' into main 2026-10-21 11:24:55 +02:00
abraham 1e3ac9d8d2 fonction 4 : O(n + J) 2026-10-21 11:19:08 +02:00
Karl Framery a5e748e993 EXO 4 - optimisation F1 2026-10-21 11:17:43 +02:00
abraham df4e8876fb fonction 2 : O(n + C) 2026-10-21 11:10:03 +02:00
abraham 1f17823a2c Palier 1 : objectifs 2026-10-21 10:59:57 +02:00
7 changed files with 6413 additions and 40 deletions
+108
View File
@@ -0,0 +1,108 @@
# Groupe :
- Karl FRAMERY
- Ozvann ABRAHAM
CPU: Intel(R) Pentium(R) Silver N5030 (4) @ 3.10 GHz
# 1.Mesurer
```
gcc -O2 banque.c -o banque && time ./banque
```
```
Empreinte : ff68d260a7a58441
real 0m4,793s
user 0m4,772s
sys 0m0,005s
```
Le temps d'éxecution du programme est de 4.793 seconde et l'emprunte est : [ff68d260a7a58441]
# 2.Profiler
La fonction F1 : <trier_par_montant> est d'une complexité <span style="color:yellow">[O(n²)]</span> pour une utilisation du temps de 43.77% du temps totale d'exécution pour 1 call.
La fonction F7 : <nb_paires_opposees> est d'une complexité <span style="color:yellow">[O(n²)]</span> pour une utilisation du temps de 15.32% du temps totale d'exécution pour 1 call.
La fonction F8 : <nb_facons_rendre> est d'une complexité <span style="color:red">[O(2^n)]</span> pour une utilisation du temps de 12.84% du temps totale d'exécution pour 1 call.
La fonction F6 : <rechercher_par_id> est d'une complexité <span style="color:blue">[O(n)]</span> pour une utilisation du temps de 12.21% du temps totale d'exécution pour 30000 calls.
On peut voir que les fonctions les plus coûteuse ont les plus grande complexité.
# 3.Calculer
### Fonction F1
La complexité de la fonction est de <span style="color:yellow">[O(n²)]</span> pour un M de 6
### Fonction F2
La complexité de la fonction est de <span style="color:yellow">[O(n²)]</span> pour un M de 5
### Fonction F3
La complexité de la fonction est de <span style="color:yellow">[O(n²)]</span> pour un M de 4
### Fonction F4
La complexité de la fonction est de <span style="color:yellow">[O(n²)]</span> pour un M de 4
### Fonction F5
La complexité de la fonction est de <span style="color:yellow">[O(n³)]</span> pour un M de 5
### Fonction F6
La complexité de la fonction est de <span style="color:blue">[O(n)]</span> pour un M de 3
### Fonction F7
La complexité de la fonction est de <span style="color:yellow">[O(n²)]</span> pour un M de 4
### Fonction F8
La complexité de la fonction est de <span style="color:red">[O(2^n)]</span> pour un M de 4
### Fonction F9
La complexité de la fonction est de <span style="color:blue">[O(1)]</span> pour un M de 14
### Fonction F10
La complexité de la fonction est de <span style="color:blue">[O(n)]</span> pour un M de 2
# 4. Optimisation
- Optimisation de la fonction 1 nom du commit : "EXO 4 - optimisation F1". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 2 nom du commit : "fonction 2 : O(n + C)". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 3 nom du commit : "EXO 4 - optimisation F3". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 4 nom du commit : "fonction 4 : O(n + J)". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 5 nom du commit : "EXO 4 - optimisation F5". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 6 nom du commit : "". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 7 nom du commit : "". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 8 nom du commit : "fonction 8 : O(S x k)". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 9 nom du commit : "". Emprunte : ff68d260a7a58441
- Optimisation de la fonction 10 nom du commit : "fonction 10 : O(L)". Emprunte : ff68d260a7a58441
Le temps minimal atteint avec les modification est de 1.651 secondes.
Executable
BIN
View File
Binary file not shown.
+68 -40
View File
@@ -73,44 +73,43 @@ Transaction *generer_transactions(int n)
/* F1 : trie les transactions par montant croissant, puis par id */
void trier_par_montant(Transaction *t, int n)
{
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (t[j].montant > t[j + 1].montant ||
(t[j].montant == t[j + 1].montant && t[j].id > t[j + 1].id)) {
Transaction tmp = t[j];
t[j] = t[j + 1];
t[j + 1] = tmp;
}
for (int i = 1; i < n; i++) {
Transaction cle = t[i];
int j = i - 1;
while (j >= 0 && (t[j].montant > cle.montant ||
(t[j].montant == cle.montant && t[j].id > cle.id))) {
t[j + 1] = t[j];
j--;
}
t[j + 1] = cle;
}
}
/* F2 : nombre de clients ayant au moins une transaction */
int nb_clients_distincts(const Transaction *t, int n)
{
int clients_vus[NB_CLIENTS] = {0};
int nb = 0;
for (int i = 0; i < n; i++) {
int deja_vu = 0;
for (int j = 0; j < i; j++) {
if (t[j].client == t[i].client) {
deja_vu = 1;
break;
}
}
if (!deja_vu)
int client = t[i].client;
if (!clients_vus[client]) {
clients_vus[client] = 1;
nb++;
}
}
return nb;
}
/* F3 : solde total de chaque client */
/* F3 : solde total de chaque client en O(n + c) */
void total_par_client(const Transaction *t, int n, long *totaux)
{
for (int c = 0; c < NB_CLIENTS; c++) {
totaux[c] = 0;
for (int i = 0; i < n; i++)
if (t[i].client == c)
totaux[c] += t[i].montant;
}
for (int i = 0; i < n; i++) {
totaux[t[i].client] += t[i].montant;
}
}
@@ -119,10 +118,10 @@ void total_par_jour(const Transaction *t, int n, long *totaux)
{
for (int j = 0; j < NB_JOURS; j++) {
totaux[j] = 0;
for (int i = 0; i < n; i++)
if (t[i].jour == j)
totaux[j] += t[i].montant;
}
for (int i = 0; i < n; i++)
totaux[t[i].jour] += t[i].montant;
}
/* F5 : période de jours consécutifs dont la somme des soldes est maximale */
@@ -131,16 +130,20 @@ long meilleure_periode(const long *totaux, int nb_jours, int *debut, int *fin)
long meilleur = totaux[0];
*debut = 0;
*fin = 0;
for (int i = 0; i < nb_jours; i++) {
for (int j = i; j < nb_jours; j++) {
long somme = 0;
for (int k = i; k <= j; k++)
somme += totaux[k];
if (somme > meilleur) {
meilleur = somme;
*debut = i;
*fin = j;
}
long somme_courante = totaux[0];
int debut_courant = 0;
for (int j = 1; j < nb_jours; j++) {
if (somme_courante < 0) {
somme_courante = totaux[j];
debut_courant = j;
} else {
somme_courante += totaux[j];
}
if (somme_courante > meilleur) {
meilleur = somme_courante;
*debut = debut_courant;
*fin = j;
}
}
return meilleur;
@@ -172,12 +175,31 @@ static const int PIECES[] = {1, 2, 5, 10, 20, 50, 100, 200};
long nb_facons_rendre(int somme, int nb_pieces)
{
if (somme < 0 || nb_pieces < 0)
return 0;
if (somme == 0)
return 1;
if (somme < 0 || nb_pieces == 0)
if (nb_pieces == 0)
return 0;
return nb_facons_rendre(somme - PIECES[nb_pieces - 1], nb_pieces) +
nb_facons_rendre(somme, nb_pieces - 1);
if (nb_pieces > NB_PIECES)
nb_pieces = NB_PIECES;
long *combinaisons = malloc((somme + 1) * sizeof(long));
if (combinaisons == NULL)
return 0;
for (int montant = 0; montant <= somme; montant++)
combinaisons[montant] = 0;
combinaisons[0] = 1;
for (int i = 0; i < nb_pieces; i++) {
for (int montant = PIECES[i]; montant <= somme; montant++)
combinaisons[montant] += combinaisons[montant - PIECES[i]];
}
long resultat = combinaisons[somme];
free(combinaisons);
return resultat;
}
/* F9 : catégorie d'une transaction (pour les statistiques) */
@@ -217,10 +239,16 @@ int categorie(const Transaction *t)
/* F10 : ajoute une ligne à la fin du rapport */
int longueur(const char *s)
{
int n = 0;
while (s[n] != '\0')
n++;
return n;
static const char *chaine_connue = NULL;
static int n_connu = 0;
if (s != chaine_connue || s[0] == '\0') {
chaine_connue = s;
n_connu = 0;
}
while (s[n_connu] != '\0')
n_connu++;
return n_connu;
}
void ajouter_ligne(char *rapport, const char *ligne)
Executable
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+220
View File
@@ -0,0 +1,220 @@
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
43.77 5.20 5.20 1 5.20 5.20 trier_par_montant
15.32 7.02 1.82 1 1.82 1.82 nb_paires_opposees
12.84 8.54 1.52 1 1.52 1.52 nb_facons_rendre
12.21 9.99 1.45 30000 0.00 0.00 rechercher_par_id
6.06 10.71 0.72 6017 0.00 0.00 longueur
4.04 11.20 0.48 1 0.48 0.48 meilleure_periode
1.94 11.43 0.23 1 0.23 0.23 nb_clients_distincts
1.60 11.62 0.19 1 0.19 0.19 total_par_client
1.01 11.73 0.12 _init
0.84 11.84 0.10 1 0.10 0.10 total_par_jour
0.38 11.88 0.04 30000 0.00 0.00 categorie
0.00 11.88 0.00 149998 0.00 0.00 alea
0.00 11.88 0.00 6017 0.00 0.00 ajouter_ligne
0.00 11.88 0.00 1 0.00 0.00 empreinte
0.00 11.88 0.00 1 0.00 0.00 generer_transactions
% the percentage of the total running time of the
time program used by this function.
cumulative a running sum of the number of seconds accounted
seconds for by this function and those listed above it.
self the number of seconds accounted for by this
seconds function alone. This is the major sort for this
listing.
calls the number of times this function was invoked, if
this function is profiled, else blank.
self the average number of milliseconds spent in this
ms/call function per call, if this function is profiled,
else blank.
total the average number of milliseconds spent in this
ms/call function and its descendents per call, if this
function is profiled, else blank.
name the name of the function. This is the minor sort
for this listing. The index shows the location of
the function in the gprof listing. If the index is
in parenthesis it shows where it would appear in
the gprof listing if it were to be printed.
Copyright (C) 2012-2026 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
Call graph (explanation follows)
granularity: each sample hit covers 4 byte(s) for 0.08% of 11.88 seconds
index % time self children called name
<spontaneous>
[1] 99.0 0.00 11.76 main [1]
5.20 0.00 1/1 trier_par_montant [2]
1.82 0.00 1/1 nb_paires_opposees [3]
1.52 0.00 1/1 nb_facons_rendre [4]
1.45 0.00 30000/30000 rechercher_par_id [5]
0.00 0.72 6017/6017 ajouter_ligne [6]
0.48 0.00 1/1 meilleure_periode [8]
0.23 0.00 1/1 nb_clients_distincts [9]
0.19 0.00 1/1 total_par_client [10]
0.10 0.00 1/1 total_par_jour [12]
0.04 0.00 30000/30000 categorie [13]
0.00 0.00 1/1 generer_transactions [16]
0.00 0.00 1/1 empreinte [15]
-----------------------------------------------
5.20 0.00 1/1 main [1]
[2] 43.8 5.20 0.00 1 trier_par_montant [2]
-----------------------------------------------
1.82 0.00 1/1 main [1]
[3] 15.3 1.82 0.00 1 nb_paires_opposees [3]
-----------------------------------------------
266723738 nb_facons_rendre [4]
1.52 0.00 1/1 main [1]
[4] 12.8 1.52 0.00 1+266723738 nb_facons_rendre [4]
266723738 nb_facons_rendre [4]
-----------------------------------------------
1.45 0.00 30000/30000 main [1]
[5] 12.2 1.45 0.00 30000 rechercher_par_id [5]
-----------------------------------------------
0.00 0.72 6017/6017 main [1]
[6] 6.1 0.00 0.72 6017 ajouter_ligne [6]
0.72 0.00 6017/6017 longueur [7]
-----------------------------------------------
0.72 0.00 6017/6017 ajouter_ligne [6]
[7] 6.1 0.72 0.00 6017 longueur [7]
-----------------------------------------------
0.48 0.00 1/1 main [1]
[8] 4.0 0.48 0.00 1 meilleure_periode [8]
-----------------------------------------------
0.23 0.00 1/1 main [1]
[9] 1.9 0.23 0.00 1 nb_clients_distincts [9]
-----------------------------------------------
0.19 0.00 1/1 main [1]
[10] 1.6 0.19 0.00 1 total_par_client [10]
-----------------------------------------------
<spontaneous>
[11] 1.0 0.12 0.00 _init [11]
-----------------------------------------------
0.10 0.00 1/1 main [1]
[12] 0.8 0.10 0.00 1 total_par_jour [12]
-----------------------------------------------
0.04 0.00 30000/30000 main [1]
[13] 0.4 0.04 0.00 30000 categorie [13]
-----------------------------------------------
0.00 0.00 149998/149998 generer_transactions [16]
[14] 0.0 0.00 0.00 149998 alea [14]
-----------------------------------------------
0.00 0.00 1/1 main [1]
[15] 0.0 0.00 0.00 1 empreinte [15]
-----------------------------------------------
0.00 0.00 1/1 main [1]
[16] 0.0 0.00 0.00 1 generer_transactions [16]
0.00 0.00 149998/149998 alea [14]
-----------------------------------------------
This table describes the call tree of the program, and was sorted by
the total amount of time spent in each function and its children.
Each entry in this table consists of several lines. The line with the
index number at the left hand margin lists the current function.
The lines above it list the functions that called this function,
and the lines below it list the functions this one called.
This line lists:
index A unique number given to each element of the table.
Index numbers are sorted numerically.
The index number is printed next to every function name so
it is easier to look up where the function is in the table.
% time This is the percentage of the `total' time that was spent
in this function and its children. Note that due to
different viewpoints, functions excluded by options, etc,
these numbers will NOT add up to 100%.
self This is the total amount of time spent in this function.
children This is the total amount of time propagated into this
function by its children.
called This is the number of times the function was called.
If the function called itself recursively, the number
only includes non-recursive calls, and is followed by
a `+' and the number of recursive calls.
name The name of the current function. The index number is
printed after it. If the function is a member of a
cycle, the cycle number is printed between the
function's name and the index number.
For the function's parents, the fields have the following meanings:
self This is the amount of time that was propagated directly
from the function into this parent.
children This is the amount of time that was propagated from
the function's children into this parent.
called This is the number of times this parent called the
function `/' the total number of times the function
was called. Recursive calls to the function are not
included in the number after the `/'.
name This is the name of the parent. The parent's index
number is printed after it. If the parent is a
member of a cycle, the cycle number is printed between
the name and the index number.
If the parents of the function cannot be determined, the word
`<spontaneous>' is printed in the `name' field, and all the other
fields are blank.
For the function's children, the fields have the following meanings:
self This is the amount of time that was propagated directly
from the child into the function.
children This is the amount of time that was propagated from the
child's children to the function.
called This is the number of times the function called
this child `/' the total number of times the child
was called. Recursive calls by the child are not
listed in the number after the `/'.
name This is the name of the child. The child's index
number is printed after it. If the child is a
member of a cycle, the cycle number is printed
between the name and the index number.
If there are any cycles (circles) in the call graph, there is an
entry for the cycle-as-a-whole. This entry shows who called the
cycle (as parents) and the members of the cycle (as children.)
The `+' recursive calls entry shows the number of function calls that
were internal to the cycle, and the calls entry for each member shows,
for that member, how many times it was called from other members of
the cycle.
Copyright (C) 2012-2026 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
Index by function name
[11] _init [16] generer_transactions [3] nb_paires_opposees
[6] ajouter_ligne [7] longueur [5] rechercher_par_id
[14] alea [8] meilleure_periode [10] total_par_client
[13] categorie [9] nb_clients_distincts [12] total_par_jour
[15] empreinte [4] nb_facons_rendre [2] trier_par_montant
+6017
View File
File diff suppressed because it is too large Load Diff