diff options
Diffstat (limited to 'sem_4/Algo/TP1')
| -rw-r--r-- | sem_4/Algo/TP1/Q1.cpp | 74 | ||||
| -rw-r--r-- | sem_4/Algo/TP1/R1 | bin | 0 -> 13510 bytes |
2 files changed, 74 insertions, 0 deletions
diff --git a/sem_4/Algo/TP1/Q1.cpp b/sem_4/Algo/TP1/Q1.cpp new file mode 100644 index 0000000..116cf84 --- /dev/null +++ b/sem_4/Algo/TP1/Q1.cpp @@ -0,0 +1,74 @@ +#include<iostream>
+#include<cstdlib>
+#include<ctime>
+
+void f1 ( int n);
+void f3 (int n);
+void g2 (int n);
+
+void f1 (int n){
+ for (int i = 1; i <=n; i ++){
+
+ }
+}
+
+void f3 (int n ) {
+ for (int i = 1; i <=n; i ++){
+ for (int i = 1; i <=n; i ++){
+ for (int i = 1; i <=n; i ++){
+ }
+ }
+ }
+}
+
+void g2 (int n){
+ if ( n != 1){
+ g2(n-1);
+ g2(n-1);
+ }
+}
+void g3 (int n){
+ if ( n != 1){
+ g3(n-1);
+ g3(n-1);
+ g3(n-1);
+ }
+}
+
+int main ( int argc, char ** argv){
+ if ( argc != 2){
+ std::cout<<"Syntaxe attendue : ./R1 n"<<std::endl;
+ return 0;
+ }
+ int N = atoi(argv[1]);
+ std::cout<<"N vaut : "<< N<<std::endl;
+ time_t timer =time(NULL);
+ f1(N);
+ int tmpf1= time(NULL)-timer;
+ std::cout<<"Temps exec f1 : "<<tmpf1<<std::endl;
+ timer= time(NULL);
+ f3(N);
+ int tmpf3 = time(NULL)-timer;
+ std::cout<<"Temps exec f3 : "<<tmpf3<<std::endl;
+ timer = time(NULL);
+ g2(N);
+ int tmpg2= time(NULL)-timer;
+ std::cout<<"Temps exec g2 : "<<tmpg2<<std::endl;
+ timer = time(NULL);
+ g3(N);
+ int tmpg3 = time(NULL)-timer;
+ std::cout<<"Temps exec g3 : "<<tmpg3<<std::endl;
+ return 0;
+}
+/*
+ Pour n = 1000, f1 mets 0 secondes, contre 2 secondes pour f3;
+Vers n= 30 on voit que g2 mets plus de temps que f3
+A partir de n = 20, g3 commence a mettre drastiquement plus de temps que g2 ( 4 secondes sur ma machine!)
+
+Concernant les complexités de l'exec successives de fonctions, exemple pour la premiere :
+O(n^3) et O ( n + n^3) appartiennent tout deux a teta(n^3) il existe un difference de complexité lineaire, mais elle est negligeable face a n^3
+Ce principe s'applique de maniere similaire aux autres questions, a chaque fois la complexité de la premiere fonction est negligeable face a celle de la secone.
+
+*/
+
+//g++ Q1.cpp -o R1
diff --git a/sem_4/Algo/TP1/R1 b/sem_4/Algo/TP1/R1 Binary files differnew file mode 100644 index 0000000..2e2afd8 --- /dev/null +++ b/sem_4/Algo/TP1/R1 |
