Skip to content

Commit 3683460

Browse files
authored
Release 0.1.0
Release 0.1.0
2 parents 4d66649 + 2ea664c commit 3683460

34 files changed

Lines changed: 785 additions & 1 deletion

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.class
2+
.idea
3+
untitled104.iml
4+
.DS_Store
5+
.vscode
6+
.metadata

Algorithm-Stats.algo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Tri à bulles optimisé
2+
FONCTION ENTIER Stats( min : INT, max : INT, step : INT, nbr : TABLEAU )
3+
// Définir les variables
4+
VARIABLE
5+
INT: i
6+
FLOAT: comparaisons
7+
FLOAT: echange
8+
FLOAT: affectations
9+
INT: tab[]
10+
// Début de l'algorithme
11+
DEBUT
12+
// On parcourt le tableau
13+
POUR i DE 1 A n FAIRE
14+
tab <- NombreAléatoire
15+
16+
FIN POUR
17+
18+
SI min < max ET i > nbr ALORS
19+
ECRIRE "Le nombre d'affectations pour " + min + " est de " + affectations / nbr;
20+
APPELER stat(min + step, max, step, nbr)
21+
SINON
22+
ECRIRE "Le nombre d'affectations pour " + min + " est de " + affectations / nbr;
23+
FIN SI
24+
FIN
25+
FIN FONCTION

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# Algorithm-Comparative-Sorting-Study
1+
2+
# Comparative sorting study in algorithms
3+
📒 - Exercise to learn to do comparative sorting with algorithms
4+
5+
## Contributing
6+
This repository is the result of a school exercise. It is therefore unnecessary to contribute to this project.
7+
8+
## License
9+
[MIT](https://choosealicense.com/licenses/mit/)
10+
11+
# Exercises
12+
13+
## Git
14+
- Décentraliser
15+
- Créer un dépôt local
16+
- Workflow Git
17+
- Ajout et versioning de fichiers
18+
- Obtenir des informations sur l’état de la copie de travail
19+
- Supprimer, déplacer et renommer des fichiers
20+
- Analyser l’historique des révisions
21+
- Ignorer des fichiers
22+
- Créer et gérer des branches
23+
- Merge : gérer les conflits
24+
- Push, pull, fetch
25+
- Comprendre rebase, reset
26+
- Débugger avec bisect
27+
- Gestions des dépôts avec GitHub
28+
29+
30+
## Algo : Etude comparative de tris
31+
32+
Le but de ce TP est de programmer, étudier et comparer les algorithmes élémentaires de tri
33+
34+
1. Faites les algorithmes des 4 tris :
35+
- Tri sélection
36+
- Tri insertion
37+
- Tri à bulles normal
38+
- Tri à bulles optimisé
39+
40+
2. Programmez :
41+
- Tri sélection
42+
- Tri insertion
43+
- Tri à bulles normal
44+
- Tri à bulles optimisé
45+
46+
3. Evaluez et comparez :
47+
48+
- Ajoutez un compteur des comparaisons et un des échanges/affectations dans le tableau (un
49+
échange vaut 3 affectations) ;
50+
51+
- Jeux d’essais avec meilleur et pire de cas : comptez les opérations nécessaires au mieux et au pire
52+
pour l’exécution des tris programmés ;
53+
54+
- Ecrire une méthode stat (int min, int max, int step, int nbr) qui fait varier la taille des tableaux tirés
55+
au sort de min jusqu’à max en avançant de step à chaque fois. Pour chaque taille, effectuez nbr
56+
générations aléatoires de tableaux et appelez la fonction de tri à tester. Indiquez sur la sortie
57+
standard la taille du tableau suivi du nombre moyen d’opérations effectués, avec une ligne pour
58+
chaque taille. Par exemple pour min = 10, max = 20, step = 5 et nbr = 10 on obtient quelque chose
59+
comme : 10 12.3, 15 27.4,20 32.4
60+
61+

Tri-a-bulle-normal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

Tri-a-bulle-normal/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>tri-a-bulle-normal</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
FONCTION tri-bulle tableau de 1 a n
4+
5+
DECLARER Taille = taille du tableau
6+
DECLARER temporaire = 0
7+
8+
POUR i allant de la taille du tableau-1 à 1
9+
10+
POUR j allant de 1 à taille du tableau -i
11+
12+
COMPARER 2 valeurs qui se suivent
13+
14+
SI Tab[j-1] > Tab[j]
15+
16+
ALORS temporaire = Tab[Tab-1]
17+
Tab[j-1] = Tab[j]
18+
Tab[j] = temporaire
19+
20+
FIN SI
21+
22+
FIN POUR
23+
24+
FIN POUR
25+
26+
AFFICHER tableau
27+
28+
FIN

Tri-a-bulle-normal/Algorithm-Recursif.algo

Whitespace-only changes.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.util.Arrays;
2+
import java.util.Random;
3+
4+
public class Iteratif {
5+
public static float echanges = 0;
6+
public static float comparaisons = 0;
7+
public static float affectations = 0;
8+
9+
public static void main(String[] args) {
10+
// write your code here
11+
// Clear console
12+
System.out.print("\033[H\033[2J");
13+
14+
// Tableau de test
15+
// int[] tab = { 4, 3, 2, 1};
16+
17+
// System.out.println("Tableau de test : " + Arrays.toString(tri_bulleN(tab)));
18+
19+
stat(10, 20, 5, 1);
20+
21+
}
22+
23+
public static int[] tri_bulleN(int[] tab) {
24+
int taille = tab.length;
25+
int tmp = 0;
26+
for (int i = 0; i < taille; i++) {
27+
28+
for (int j = 1; j < (taille - i); j++) {
29+
if (tab[j - 1] > tab[j]) {
30+
tmp = tab[j - 1];
31+
tab[j - 1] = tab[j];
32+
tab[j] = tmp;
33+
34+
echanges++;
35+
comparaisons++;
36+
affectations += 3;
37+
}
38+
comparaisons++;
39+
affectations++;
40+
}
41+
42+
affectations++;
43+
comparaisons++;
44+
}
45+
46+
return tab;
47+
}
48+
49+
public static void stat(int min, int max, int step, int nbr) {
50+
int i;
51+
comparaisons = 0;
52+
echanges = 0;
53+
affectations = 0;
54+
for (i = 1; i <= nbr; i++) {
55+
int Tab[] = new Random().ints(min).toArray();
56+
// int Tab[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
57+
// int Tab[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
58+
tri_bulleN(Tab);
59+
}
60+
if (min < max && i > nbr) {
61+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectations / nbr);
62+
stat((min + step), max, step, nbr);
63+
} else {
64+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectations / nbr);
65+
System.out.println("Le nombre de comparaisons est de " + comparaisons / nbr);
66+
System.out.println("Le nombre d'echanges est de " + echanges / nbr);
67+
}
68+
}
69+
}

Tri-a-bulle-normal/src/Main.class

1.73 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// import java.util.Arrays;
2+
// import java.util.Random;
3+
4+
// public class Recursif {
5+
// public static float echanges = 0;
6+
// public static float comparaisons = 0;
7+
// public static float affectations = 0;
8+
9+
// public static void main(String[] args) {
10+
// // write your code here
11+
// // Clear console
12+
// System.out.print("\033[H\033[2J");
13+
14+
// // Tableau de test
15+
// // int[] tab = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
16+
17+
// // System.out.println("Tableau de test : " + Arrays.toString(tri_bulleN(tab)));
18+
19+
// stat(10,20,5,10);
20+
21+
22+
// }

0 commit comments

Comments
 (0)