Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
782aaaed52 |
BIN
TrieSelection.class
Normal file
BIN
TrieSelection.class
Normal file
Binary file not shown.
60
TrieSelection.java
Normal file
60
TrieSelection.java
Normal file
@@ -0,0 +1,60 @@
|
||||
public class TrieSelection {
|
||||
public static void Tri(int[][] a) {
|
||||
if (a == null) throw new IllegalArgumentException("Tableau null");
|
||||
int n = a.length;
|
||||
if (n == 0) throw new IllegalArgumentException("Tableau vide");
|
||||
|
||||
int m = a[0].length;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (a[i] == null || a[i].length != m)
|
||||
throw new IllegalArgumentException("Tous les sous-tableaux doivent avoir la même taille");
|
||||
}
|
||||
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
int min = i;
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (sum(a[j]) < sum(a[min])) min = j;
|
||||
}
|
||||
int[] tmp = a[i];
|
||||
a[i] = a[min];
|
||||
a[min] = tmp;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) selection(a[i]);
|
||||
}
|
||||
|
||||
public static void selection(int[] arr) {
|
||||
int n = arr.length;
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
int min = i;
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (arr[j] < arr[min]) min = j;
|
||||
}
|
||||
int tmp = arr[i];
|
||||
arr[i] = arr[min];
|
||||
arr[min] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
public static int sum(int[] arr) {
|
||||
int s = 0;
|
||||
for (int x : arr) s += x;
|
||||
return s;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[][] t = {
|
||||
{0, 3, 2},
|
||||
{9, 4, 5},
|
||||
{4, 1, 3},
|
||||
{77, 12, 56},
|
||||
{687, 25},
|
||||
{5, 4, 9}
|
||||
};
|
||||
Tri(t);
|
||||
for (int[] r : t) {
|
||||
for (int x : r) System.out.print(x + " ");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
21
reponse.txt
Normal file
21
reponse.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
Ex2 :
|
||||
|
||||
Function_1
|
||||
la première boucle parcour le tableau1 -> n = len(tableau1)
|
||||
La deuxième boucle parcour le tableau2 -> m = len(tableau2)
|
||||
Ce qui donne (On*m)
|
||||
|
||||
Function_2 :
|
||||
Comme il s'agit d'une foncion while la complexité est de : 0(n)
|
||||
|
||||
|
||||
Function_3 :
|
||||
Comme il n'y a pas de boucle les instrucions vont être executée une fois donc ce qui donne une complexité de 0(1)
|
||||
|
||||
|
||||
Ex3 :
|
||||
|
||||
Sum = O(n)
|
||||
selection = o(m²)
|
||||
Tri = O(n²*m+n*m²)
|
||||
total = O(n²*m+n*m²)
|
Reference in New Issue
Block a user