forked from menault/TD4_DEV51_Qualite_Algo
exo3
This commit is contained in:
BIN
exo3$1.class
Normal file
BIN
exo3$1.class
Normal file
Binary file not shown.
BIN
exo3.class
Normal file
BIN
exo3.class
Normal file
Binary file not shown.
52
exo3.java
Normal file
52
exo3.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class exo3 {
|
||||||
|
private static int calculSomme(int[] ligne) {
|
||||||
|
int somme = 0;
|
||||||
|
for (int element : ligne) {
|
||||||
|
somme += element;
|
||||||
|
}
|
||||||
|
return somme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[][] trierTab(int[][] tab) {
|
||||||
|
Arrays.sort(tab, (val1, val2) -> Integer.compare(calculSomme(val1), calculSomme(val2)));
|
||||||
|
|
||||||
|
for (int[] val : tab) {
|
||||||
|
Arrays.sort(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[][] orginalTab = {
|
||||||
|
{0, 3, 2},
|
||||||
|
{9, 4, 5},
|
||||||
|
{4, 1, 3},
|
||||||
|
};
|
||||||
|
// int[][] orginalTab = {
|
||||||
|
// {7, 2, 9, 1},
|
||||||
|
// {3, 8, 4},
|
||||||
|
// {6, 1, 5, 2, 3},
|
||||||
|
// {2, 9},
|
||||||
|
// {4, 7, 1, 8},
|
||||||
|
// };
|
||||||
|
|
||||||
|
afficherTab(orginalTab);
|
||||||
|
System.out.println("-----");
|
||||||
|
|
||||||
|
int[][] resultTab = trierTab(orginalTab);
|
||||||
|
|
||||||
|
afficherTab(resultTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void afficherTab(int[][] tab) {
|
||||||
|
for (int i = 0; i < tab.length; i++) {
|
||||||
|
for (int j = 0; j < tab[i].length; j++) {
|
||||||
|
System.out.print(tab[i][j] + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
exo3.pdf
Normal file
5
exo3.pdf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Complexité algorithmique de la fonction trierTab:
|
||||||
|
Ici il y a deux principales instructions qu'on va calculer, le tri par somme et le tri de chaque sous-tableau
|
||||||
|
Le tri O(N * M Log N)
|
||||||
|
Le tri de chaque sous tableau O(N * M Log M)
|
||||||
|
Donc le calcul total correspond à l'addition des deux : O(N * M Log N) + O(N * M Log M)
|
Reference in New Issue
Block a user