fonction 2 : O(n + C)

This commit is contained in:
abraham
2026-10-21 11:10:03 +02:00
parent 1f17823a2c
commit df4e8876fb
3 changed files with 15 additions and 10 deletions
+8 -2
View File
@@ -6,7 +6,9 @@
# 1.Mesurer
```gcc -O2 banque.c -o banque && time ./banque```
```
gcc -O2 banque.c -o banque && time ./banque
```
```
Empreinte : ff68d260a7a58441
@@ -16,7 +18,7 @@ user 0m4,772s
sys 0m0,005s
```
Le temps d'éxecution du programme est de 4.793 seconde et l'emprunte est <ff68d260a7a58441>
Le temps d'éxecution du programme est de 4.793 seconde et l'emprunte est : [ff68d260a7a58441]
# 2.Profiler
@@ -80,6 +82,10 @@ La complexité de la fonction est de <span style="color:blue">[O(n)]</span> pour
# 4. Optimisation
Optimisation de la fonction 2 nom du commit : "fonction 2 : O(n + C)"
BIN
View File
Binary file not shown.
+7 -8
View File
@@ -88,18 +88,17 @@ void trier_par_montant(Transaction *t, int n)
/* 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;
}