From 734a200a42ac9c07c4b187b71338c92f509dafa9 Mon Sep 17 00:00:00 2001 From: Rishu Bhardwaj Date: Fri, 22 Oct 2021 23:21:02 +0530 Subject: [PATCH 1/7] factorial --- GeeksForGeeks/factorial.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 GeeksForGeeks/factorial.cpp diff --git a/GeeksForGeeks/factorial.cpp b/GeeksForGeeks/factorial.cpp new file mode 100644 index 00000000..c8e0acdf --- /dev/null +++ b/GeeksForGeeks/factorial.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; +int fact(int n){ + int ans=1; + for(int i=1;i>n; + int ans=fact(n); + cout< Date: Sat, 23 Oct 2021 00:12:01 +0530 Subject: [PATCH 2/7] insertionsort --- GeeksForGeeks/insertionsort.cpp | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 GeeksForGeeks/insertionsort.cpp diff --git a/GeeksForGeeks/insertionsort.cpp b/GeeksForGeeks/insertionsort.cpp new file mode 100644 index 00000000..103b3fac --- /dev/null +++ b/GeeksForGeeks/insertionsort.cpp @@ -0,0 +1,45 @@ + +#include +using namespace std; + + +void insertionSort(int arr[], int n) +{ + int i, key, j; + for (i = 1; i < n; i++) + { + key = arr[i]; + j = i - 1; + + + while (j >= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } +} + + +void printArray(int arr[], int n) +{ + int i; + for (i = 0; i < n; i++) + cout << arr[i] << " "; + cout << endl; +} + + +int main() +{ + int arr[] = { 12, 11, 13, 5, 6 }; + int n = sizeof(arr) / sizeof(arr[0]); + + insertionSort(arr, n); + printArray(arr, n); + + return 0; +} + + From 56925e39af9246e41f6a682f63bbb7db92cc143c Mon Sep 17 00:00:00 2001 From: Rishu Bhardwaj Date: Sat, 23 Oct 2021 09:33:14 +0530 Subject: [PATCH 3/7] Matrix_multiplication --- GeeksForGeeks/Matrix_multiplication.cpp | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 GeeksForGeeks/Matrix_multiplication.cpp diff --git a/GeeksForGeeks/Matrix_multiplication.cpp b/GeeksForGeeks/Matrix_multiplication.cpp new file mode 100644 index 00000000..629b799a --- /dev/null +++ b/GeeksForGeeks/Matrix_multiplication.cpp @@ -0,0 +1,62 @@ + //Matrix Multiplication +#include +using namespace std; +int main() +{ + int n,m,i,j,k,sum=0; + cout<<"Enter the number of rows and columns in matrix 1: "; + cin>>n>>m; + int a,b; + cout<<"Enter the number of rows and columns in matrix 2: "; + cin>>a>>b; + int m1[n][m],m2[a][b],m3[n][b]; + if(m!=a) + { + cout<<"We cannot multiply these two matrices"<>m1[i][j]; + } + } + cout<<"Enter the elements of matrix 2 : "<>m2[i][j]; + } + } + for(i = 0; i < n; ++i){ + for(j = 0; j < b; ++j) + { + m3[i][j]=0; + }} + for(i=0;i Date: Sat, 23 Oct 2021 09:36:28 +0530 Subject: [PATCH 4/7] lcs --- GeeksForGeeks/lcs.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 GeeksForGeeks/lcs.cpp diff --git a/GeeksForGeeks/lcs.cpp b/GeeksForGeeks/lcs.cpp new file mode 100644 index 00000000..fd41bfaa --- /dev/null +++ b/GeeksForGeeks/lcs.cpp @@ -0,0 +1,34 @@ +// The longest common subsequence in C++ + +#include +using namespace std; + +void lcsAlgo(char *S1, char *S2, int m, int n) { + int LCS_table[m + 1][n + 1]; + + + // Building the mtrix in bottom-up way + for (int i = 0; i <= m; i++) { + for (int j = 0; j <= n; j++) { + if (i == 0 || j == 0) + LCS_table[i][j] = 0; + else if (S1[i - 1] == S2[j - 1]) + LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1; + else + LCS_table[i][j] = max(LCS_table[i - 1][j], LCS_table[i][j - 1]); + } + } + cout<<"Length of longest common subsequence : "<>S1>>S2; + int m = strlen(S1); + int n = strlen(S2); + + lcsAlgo(S1, S2, m, n); +} \ No newline at end of file From 0c55c34f7cacfda5efa1121286b817e844da85cc Mon Sep 17 00:00:00 2001 From: Rishu Bhardwaj Date: Sat, 23 Oct 2021 11:35:18 +0530 Subject: [PATCH 5/7] insertion Sort --- GeeksForGeeks/Matrix_multiplication.cpp | 62 ------------------------- GeeksForGeeks/lcs.cpp | 34 -------------- 2 files changed, 96 deletions(-) delete mode 100644 GeeksForGeeks/Matrix_multiplication.cpp delete mode 100644 GeeksForGeeks/lcs.cpp diff --git a/GeeksForGeeks/Matrix_multiplication.cpp b/GeeksForGeeks/Matrix_multiplication.cpp deleted file mode 100644 index 629b799a..00000000 --- a/GeeksForGeeks/Matrix_multiplication.cpp +++ /dev/null @@ -1,62 +0,0 @@ - //Matrix Multiplication -#include -using namespace std; -int main() -{ - int n,m,i,j,k,sum=0; - cout<<"Enter the number of rows and columns in matrix 1: "; - cin>>n>>m; - int a,b; - cout<<"Enter the number of rows and columns in matrix 2: "; - cin>>a>>b; - int m1[n][m],m2[a][b],m3[n][b]; - if(m!=a) - { - cout<<"We cannot multiply these two matrices"<>m1[i][j]; - } - } - cout<<"Enter the elements of matrix 2 : "<>m2[i][j]; - } - } - for(i = 0; i < n; ++i){ - for(j = 0; j < b; ++j) - { - m3[i][j]=0; - }} - for(i=0;i -using namespace std; - -void lcsAlgo(char *S1, char *S2, int m, int n) { - int LCS_table[m + 1][n + 1]; - - - // Building the mtrix in bottom-up way - for (int i = 0; i <= m; i++) { - for (int j = 0; j <= n; j++) { - if (i == 0 || j == 0) - LCS_table[i][j] = 0; - else if (S1[i - 1] == S2[j - 1]) - LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1; - else - LCS_table[i][j] = max(LCS_table[i - 1][j], LCS_table[i][j - 1]); - } - } - cout<<"Length of longest common subsequence : "<>S1>>S2; - int m = strlen(S1); - int n = strlen(S2); - - lcsAlgo(S1, S2, m, n); -} \ No newline at end of file From 0e696a7e4bd4e0684f298a8870f99f00117fab9d Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 23 Oct 2021 12:19:29 +0530 Subject: [PATCH 6/7] lcs --- GeeksForGeeks/lcs.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 GeeksForGeeks/lcs.cpp diff --git a/GeeksForGeeks/lcs.cpp b/GeeksForGeeks/lcs.cpp new file mode 100644 index 00000000..fd41bfaa --- /dev/null +++ b/GeeksForGeeks/lcs.cpp @@ -0,0 +1,34 @@ +// The longest common subsequence in C++ + +#include +using namespace std; + +void lcsAlgo(char *S1, char *S2, int m, int n) { + int LCS_table[m + 1][n + 1]; + + + // Building the mtrix in bottom-up way + for (int i = 0; i <= m; i++) { + for (int j = 0; j <= n; j++) { + if (i == 0 || j == 0) + LCS_table[i][j] = 0; + else if (S1[i - 1] == S2[j - 1]) + LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1; + else + LCS_table[i][j] = max(LCS_table[i - 1][j], LCS_table[i][j - 1]); + } + } + cout<<"Length of longest common subsequence : "<>S1>>S2; + int m = strlen(S1); + int n = strlen(S2); + + lcsAlgo(S1, S2, m, n); +} \ No newline at end of file From e6cf226ac9e0d13685a257633ef63ece193feafd Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 23 Oct 2021 12:46:11 +0530 Subject: [PATCH 7/7] Matrix_multiplication --- Matrix_multiplication.cpp | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Matrix_multiplication.cpp diff --git a/Matrix_multiplication.cpp b/Matrix_multiplication.cpp new file mode 100644 index 00000000..629b799a --- /dev/null +++ b/Matrix_multiplication.cpp @@ -0,0 +1,62 @@ + //Matrix Multiplication +#include +using namespace std; +int main() +{ + int n,m,i,j,k,sum=0; + cout<<"Enter the number of rows and columns in matrix 1: "; + cin>>n>>m; + int a,b; + cout<<"Enter the number of rows and columns in matrix 2: "; + cin>>a>>b; + int m1[n][m],m2[a][b],m3[n][b]; + if(m!=a) + { + cout<<"We cannot multiply these two matrices"<>m1[i][j]; + } + } + cout<<"Enter the elements of matrix 2 : "<>m2[i][j]; + } + } + for(i = 0; i < n; ++i){ + for(j = 0; j < b; ++j) + { + m3[i][j]=0; + }} + for(i=0;i