push final
This commit is contained in:
123
exercice_technique.c
Normal file
123
exercice_technique.c
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
//exercice 1
|
||||||
|
|
||||||
|
int racineCarree(int a){
|
||||||
|
int i =0 ;
|
||||||
|
while (i <a){
|
||||||
|
if (i*i==a ){
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
i=i +1 ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int* racineCarreeTab(int tab[],int lenght){
|
||||||
|
int newTab[lenght];
|
||||||
|
int valeur=0;
|
||||||
|
int i;
|
||||||
|
for (i=0;i<lenght;i++){
|
||||||
|
valeur=racineCarree(tab[i]);
|
||||||
|
newTab[i]=valeur;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int* creatTab(int newTab[]){
|
||||||
|
int i =0;
|
||||||
|
for (i=0;i<100000;i++){
|
||||||
|
newTab[i]=1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
//exercice 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int somme(int tab[],int lenght){
|
||||||
|
int somme =0;
|
||||||
|
for(int i =0 ; i<lenght;i++){
|
||||||
|
somme =+ tab[i];
|
||||||
|
}
|
||||||
|
return somme;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int conditionTri(int tab[],int lenght){
|
||||||
|
int valeur;
|
||||||
|
int i;
|
||||||
|
for (i=0;i<lenght;i++){
|
||||||
|
if (tab[i]==-1){
|
||||||
|
valeur=+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return valeur;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int* TriSpecial(int* tab,int lenght){
|
||||||
|
int newTab[lenght];
|
||||||
|
int condition =conditionTri(tab,lenght);
|
||||||
|
int i=0;
|
||||||
|
if (condition%2==1){
|
||||||
|
for (i;i<lenght;i++){
|
||||||
|
if(i%2==1){
|
||||||
|
newTab[i]=somme(racineCarreeTab(tab,lenght),lenght)*tab[i];
|
||||||
|
}else{
|
||||||
|
newTab[i]=racineCarree(tab[i]);
|
||||||
|
}
|
||||||
|
printf("%d ," , newTab[i]);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
for (i;i<lenght;i++){
|
||||||
|
if(i%2==1){
|
||||||
|
newTab[i]=somme(tab,lenght)*tab[i];
|
||||||
|
}else{
|
||||||
|
newTab[i]=tab[i];
|
||||||
|
}
|
||||||
|
printf("%d ," , newTab[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
int nb=7;
|
||||||
|
int i=0;
|
||||||
|
int lenght =100000;
|
||||||
|
int tabTest[lenght];
|
||||||
|
int tabTest2[]={7 ,25, 9};
|
||||||
|
int a = racineCarree(nb);
|
||||||
|
creatTab(tabTest);
|
||||||
|
racineCarreeTab(tabTest,lenght);
|
||||||
|
printf("voici la racine carre de %d est : %d \n", nb,a );
|
||||||
|
printf("voici le tableau de racine carre: ");
|
||||||
|
for (i=0;i<lenght;i++){
|
||||||
|
printf(" %d ",tabTest[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("voici le trie : ");
|
||||||
|
// TriSpecial(tabTest2,lenght);
|
||||||
|
/* for (i=0;i<lenght;i++){
|
||||||
|
printf(" %d ,",tabTest2[i]);
|
||||||
|
}
|
||||||
|
printf("\n");*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
99
question.txt
Normal file
99
question.txt
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
la methode racineCarree() a pour complexiter :
|
||||||
|
-algorithmque O(n) car on ne traverse le tableau qu'une seul fois
|
||||||
|
|
||||||
|
-cyclomatique: |
|
||||||
|
/\
|
||||||
|
WHILE (i <a)
|
||||||
|
false / \ true
|
||||||
|
| /\
|
||||||
|
| if(i*i==a)
|
||||||
|
| false / \
|
||||||
|
| / \
|
||||||
|
| | return i
|
||||||
|
| |
|
||||||
|
\ /
|
||||||
|
retunr -1
|
||||||
|
|
||||||
|
|
||||||
|
donc il y a une complexite cylomatique de 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
la methode racineCarreeTab() a pour complexiter :
|
||||||
|
-algorithmque: O(n*m) car il fait appel a racineCarree() donc il est deja de
|
||||||
|
complexité n et en plus cette appel ce passe dans un boucle de taille m donc O(n*m)
|
||||||
|
|
||||||
|
|
||||||
|
-cyclomatique:
|
||||||
|
|
||||||
|
|
|
||||||
|
/\
|
||||||
|
for (i=0;i<lenght;i++)
|
||||||
|
/ \
|
||||||
|
| /\
|
||||||
|
| valeur=racineCarree(tab[i]);
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
\ /
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
donc il y a une complexite cylomatique de 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gprof :
|
||||||
|
|
||||||
|
|
||||||
|
index % time self children called name
|
||||||
|
0.00 0.00 1/100001 main [2]
|
||||||
|
0.22 0.00 100000/100001 racineCarreeTab [3]
|
||||||
|
[1] 100.0 0.22 0.00 100001 racineCarree [1]
|
||||||
|
-----------------------------------------------
|
||||||
|
<spontaneous>
|
||||||
|
[2] 100.0 0.00 0.22 main [2]
|
||||||
|
0.00 0.22 1/1 racineCarreeTab [3]
|
||||||
|
0.00 0.00 1/100001 racineCarree [1]
|
||||||
|
0.00 0.00 1/1 creatTab [4]
|
||||||
|
-----------------------------------------------
|
||||||
|
0.00 0.22 1/1 main [2]
|
||||||
|
[3] 100.0 0.00 0.22 1 racineCarreeTab [3]
|
||||||
|
0.22 0.00 100000/100001 racineCarree [1]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pour cette exempel j'ai pris un tableua de 100000 avec des valeur 1000000
|
||||||
|
|
||||||
|
on peut voir que racineCarree a été 1000000 par racineCarreeTab qui est le nombre de fois qu'on attend qu'il appel la metode car racineCarreeTab
|
||||||
|
est de complexité O(n²) de par ses appel a racineCarree et a e qui se passe dans racineCarree. donc au vue de se qui se passe dans gprof j'en comclue que
|
||||||
|
mes methodes sont correctment coder et sont performante
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
la methode TriSpecial() pour complexiter :
|
||||||
|
|
||||||
|
-algorithmque: O(n⁵*m) car dans le pire des cas le resultat de conditionTri est pausitif et donc il y a plus de calcul
|
||||||
|
deja il réutilise racineCarreeTab donc on a n*m de complexite auquel on ajoute le n de racineCarree ce qui fais n²*m
|
||||||
|
on joute encore n pour la somme car on repsse encore une fois dans tous le tableau et une autre pour condition tri et enfin un dernier n
|
||||||
|
pour la boucle dans le if
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-cyclomatique:
|
||||||
|
|
||||||
|
il a une complexiter de 4 soit on rentre dans le premier if ou pas ca ouvre 2 route ensuite dans les boucle
|
||||||
|
for il y a encore 2 if ce qui ouvre en core 2 chemin pour chaque. ce qui fais donc une complexiter de 4
|
||||||
|
|
||||||
|
|
||||||
|
conditionTri : il a une complexiter de 3 soit tu rentre dans la boucle ou pas si tu y rentre tu rentre ou non dans le if ce qui fait 3
|
||||||
|
|
||||||
|
pour somme : il a une complexiter de 2 soit on rentre dans la boucle soit non.
|
Reference in New Issue
Block a user