remove old stuff

master
Michael Reber 3 years ago
parent f4fa9cdf8e
commit 74d8503a20
  1. 70
      c++/11_Numerical_Problems/C++ Perform to a 2D FFT Inplace Given a Complex 2D Array.cpp
  2. 40
      c++/11_Numerical_Problems/C++ Program to Check Multiplicability of Two Matrices.cpp
  3. 76
      c++/11_Numerical_Problems/C++ Program to Check if a Matrix is Invertible.cpp
  4. 54
      c++/11_Numerical_Problems/C++ Program to Check if it is a Sparse Matrix.cpp
  5. 65
      c++/11_Numerical_Problems/C++ Program to Compute DFT Coefficients Directly.cpp
  6. 69
      c++/11_Numerical_Problems/C++ Program to Compute Determinant of a Matrix.cpp
  7. 84
      c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using Naive Approach.cpp
  8. 73
      c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach.cpp
  9. 25
      c++/11_Numerical_Problems/C++ Program to Emulate N Dice Roller.cpp
  10. 74
      c++/11_Numerical_Problems/C++ Program to Find Basis and Dimension of a Matrix.cpp
  11. 137
      c++/11_Numerical_Problems/C++ Program to Find Closest Pair of Points in an Array.cpp
  12. 83
      c++/11_Numerical_Problems/C++ Program to Find Factoial of Large Numbers.cpp
  13. 55
      c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Dynamic Programming.cpp
  14. 49
      c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Iteration.cpp
  15. 47
      c++/11_Numerical_Problems/C++ Program to Find Factorial of a Number using Recursion.cpp
  16. 71
      c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Dynamic Programming.cpp
  17. 68
      c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Iteration.cpp
  18. 92
      c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Matrix Exponentiation.cpp
  19. 62
      c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Recursion.cpp
  20. 35
      c++/11_Numerical_Problems/C++ Program to Find GCD of Two Numbers Using Recursive Euclid Algorithm.cpp
  21. 565
      c++/11_Numerical_Problems/C++ Program to Find Inverse of a Matrix.cpp
  22. 109
      c++/11_Numerical_Problems/C++ Program to Find Path Between Two Nodes in a Graph.cpp
  23. 57
      c++/11_Numerical_Problems/C++ Program to Find the GCD and LCM of n Numbers.cpp
  24. 179
      c++/11_Numerical_Problems/C++ Program to Generate N Number of Passwords of Length M Each.cpp
  25. 72
      c++/11_Numerical_Problems/C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram.cpp
  26. 18
      c++/11_Numerical_Problems/C++ Program to Generate Random Hexadecimal Bytes.cpp
  27. 45
      c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Middle Square Method.cpp
  28. 31
      c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Multiply with Carry Method.cpp
  29. 34
      c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Probability Distribution Function.cpp
  30. 26
      c++/11_Numerical_Problems/C++ Program to Generate Randomized Sequence of Given Range of Numbers.cpp
  31. 141
      c++/11_Numerical_Problems/C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers.cpp
  32. 129
      c++/11_Numerical_Problems/C++ Program to Implement Coppersmith Freivald’s Algorithm.cpp
  33. 37
      c++/11_Numerical_Problems/C++ Program to Implement Euler Theorem.cpp
  34. 55
      c++/11_Numerical_Problems/C++ Program to Implement Extended Eucledian Algorithm.cpp
  35. 67
      c++/11_Numerical_Problems/C++ Program to Implement Fermat Primality Test.cpp
  36. 49
      c++/11_Numerical_Problems/C++ Program to Implement Fermat’s Little Theorem.cpp
  37. 48
      c++/11_Numerical_Problems/C++ Program to Implement Fisher-Yates Algorithm for Array Shuffling.cpp
  38. 80
      c++/11_Numerical_Problems/C++ Program to Implement Gauss Seidel Method.cpp
  39. 98
      c++/11_Numerical_Problems/C++ Program to Implement Miller Rabin Primality Test.cpp
  40. 48
      c++/11_Numerical_Problems/C++ Program to Implement Modular Exponentiation Algorithm.cpp
  41. 35
      c++/11_Numerical_Problems/C++ Program to Implement Naor-Reingold Pseudo Random Function.cpp
  42. 51
      c++/11_Numerical_Problems/C++ Program to Implement Park-Miller Random Number Generation Algorithm.cpp
  43. 38
      c++/11_Numerical_Problems/C++ Program to Implement Russian Peasant Multiplication.cpp
  44. 91
      c++/11_Numerical_Problems/C++ Program to Implement Segmented Sieve.cpp
  45. 92
      c++/11_Numerical_Problems/C++ Program to Implement Sieve of Atkins.cpp
  46. 30
      c++/11_Numerical_Problems/C++ Program to Implement Sieve of Eratosthenes.cpp
  47. 110
      c++/11_Numerical_Problems/C++ Program to Implement Solovay-Strassen Primality Test.cpp
  48. 229
      c++/11_Numerical_Problems/C++ Program to Implement Strassen’s Algorithm.cpp
  49. 52
      c++/11_Numerical_Problems/C++ Program to Implement the Bin Packing Algorithm.cpp
  50. 62
      c++/11_Numerical_Problems/C++ Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers.cpp
  51. 95
      c++/11_Numerical_Problems/C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation.cpp
  52. 84
      c++/11_Numerical_Problems/C++ Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range.cpp
  53. 113
      c++/11_Numerical_Problems/C++ Program to Optimize Wire Length in Electrical Circuit.cpp
  54. 27
      c++/11_Numerical_Problems/C++ Program to Perform Addition Operation Using Bitwise Operators.cpp
  55. 77
      c++/11_Numerical_Problems/C++ Program to Perform Encoding of a Message Using Matrix Multiplication.cpp
  56. 103
      c++/11_Numerical_Problems/C++ Program to Perform LU Decomposition of any Matrix.cpp
  57. 112
      c++/11_Numerical_Problems/C++ Program to Perform Matrix Multiplication.cpp
  58. 65
      c++/11_Numerical_Problems/C++ Program to Perform Optimal Paranthesization Using Dynamic Programming.cpp
  59. 80
      c++/11_Numerical_Problems/C++ Program to Perform Partition of an Integer in All Possible Ways.cpp
  60. 81
      c++/11_Numerical_Problems/C++ Program to Perform the Unique Factorization of a Given Number.cpp
  61. 49
      c++/11_Numerical_Problems/C++ Program to Represent Linear Equations in Matrix Form.cpp
  62. 65
      c++/11_Numerical_Problems/C++ Program to Solve Knapsack Problem Using Dynamic Programming.cpp
  63. 647
      c++/11_Numerical_Problems/C++ Program to Solve any Linear Equation in One Variable.cpp
  64. 61
      c++/11_Numerical_Problems/C++ Program to Solve the 0-1 Knapsack Problem.cpp
  65. 78
      c++/11_Numerical_Problems/C++ Program to Solve the Fractional Knapsack Problem.cpp
  66. 20
      c++/11_Numerical_Problems/C++ Program to Use rand and srand Functions.cpp
  67. 82
      c++/11_Numerical_Problems/C++ Program to implement Gauss Jordan Elimination algorithm..cpp
  68. 189
      c++/11_Sets_&_Strings/C++ Program to Construct DFA from NFA.cpp
  69. 121
      c++/11_Sets_&_Strings/C++ Program to Decode a Message Encoded Using Playfair Cipher.cpp
  70. 158
      c++/11_Sets_&_Strings/C++ Program to Encode a Message Using Playfair Cipher.cpp
  71. 48
      c++/11_Sets_&_Strings/C++ Program to Find Length of Longest Common Substring.cpp
  72. 59
      c++/11_Sets_&_Strings/C++ Program to Find the Longest Increasing Subsequence of a Given Sequence.cpp
  73. 57
      c++/11_Sets_&_Strings/C++ Program to Implement Affine Cipher.cpp
  74. 146
      c++/11_Sets_&_Strings/C++ Program to Implement Aho-Corasick Algorithm for String Matching.cpp
  75. 64
      c++/11_Sets_&_Strings/C++ Program to Implement Bitap Algorithm for String Matching.cpp
  76. 61
      c++/11_Sets_&_Strings/C++ Program to Implement Boyer-Moore Algorithm for String Matching.cpp
  77. 40
      c++/11_Sets_&_Strings/C++ Program to Implement Caesar Cypher.cpp
  78. 39
      c++/11_Sets_&_Strings/C++ Program to Implement Kadane’s Algorithm.cpp
  79. 72
      c++/11_Sets_&_Strings/C++ Program to Implement Knuth–Morris–Pratt Algorithm (KMP).cpp
  80. 42
      c++/11_Sets_&_Strings/C++ Program to Implement Levenshtein Distance Computing Algorithm.cpp
  81. 120
      c++/11_Sets_&_Strings/C++ Program to Implement Longest Prefix Matching.cpp
  82. 63
      c++/11_Sets_&_Strings/C++ Program to Implement Rabin-Karp Algorithm.cpp
  83. 97
      c++/11_Sets_&_Strings/C++ Program to Implement String Matching Using Vectors.cpp
  84. 41
      c++/11_Sets_&_Strings/C++ Program to Implement Wagner and Fisher Algorithm for online String Matching.cpp
  85. 62
      c++/11_Sets_&_Strings/C++ Program to Implement Z-Algorithm.cpp
  86. 110
      c++/11_Sets_&_Strings/C++ Program to Implement the Hill Cypher.cpp
  87. 88
      c++/11_Sets_&_Strings/C++ Program to Implement the Monoalphabetic Cypher.cpp
  88. 92
      c++/11_Sets_&_Strings/C++ Program to Implement the One Time Pad Algorithm.cpp
  89. 183
      c++/11_Sets_&_Strings/C++ Program to Implement the RSA Algorithm.cpp
  90. 52
      c++/11_Sets_&_Strings/C++ Program to Implement the String Search Algorithm for Short Text Sizes.cpp
  91. 71
      c++/11_Sets_&_Strings/C++ Program to Implement the Vigenere Cypher.cpp
  92. 163
      c++/11_Sets_&_Strings/C++ Program to Perform Cryptography Using Transposition Technique.cpp
  93. 74
      c++/11_Sets_&_Strings/C++ Program to Perform Finite State Automaton based Search.cpp
  94. 38
      c++/11_Sets_&_Strings/C++ Program to Perform Naive String Matching.cpp
  95. 32
      c++/11_Sets_&_Strings/C++ Program to Perform String Matching Using String Library.cpp
  96. 49
      c++/11_Sets_&_Strings/C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure).cpp
  97. 31
      c++/1_Overview/C++ Program to Compare Two Strings Using Pointers.cpp
  98. 31
      c++/1_Overview/C++ program to add two complex numbers.cpp
  99. 20
      c++/1_Overview/C++ program to generate random numbers.cpp
  100. 38
      c++/1_Overview/C++ program to reverse a number.cpp
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1,70 +0,0 @@
/*This is a C++ Program to perform 2D FFT. A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.*/
#include <iostream>
#include <math.h>
using namespace std;
#define PI 3.14159265
int n;
int main(int argc, char **argv)
{
cout << "Enter the size: ";
cin >> n;
double inputData[n][n];
cout << "Enter the 2D elements ";
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> inputData[i][j];
double realOut[n][n];
double imagOut[n][n];
double amplitudeOut[n][n];
int height = n;
int width = n;
// Two outer loops iterate on output data.
for (int yWave = 0; yWave < height; yWave++)
{
for (int xWave = 0; xWave < width; xWave++)
{
// Two inner loops iterate on input data.
for (int ySpace = 0; ySpace < height; ySpace++)
{
for (int xSpace = 0; xSpace < width; xSpace++)
{
// Compute real, imag, and ampltude.
realOut[yWave][xWave] += (inputData[ySpace][xSpace] * cos(
2 * PI * ((1.0 * xWave * xSpace / width) + (1.0
* yWave * ySpace / height)))) / sqrt(
width * height);
imagOut[yWave][xWave] -= (inputData[ySpace][xSpace] * sin(
2 * PI * ((1.0 * xWave * xSpace / width) + (1.0
* yWave * ySpace / height)))) / sqrt(
width * height);
amplitudeOut[yWave][xWave] = sqrt(
realOut[yWave][xWave] * realOut[yWave][xWave]
+ imagOut[yWave][xWave]
* imagOut[yWave][xWave]);
}
cout << realOut[yWave][xWave] << " + " << imagOut[yWave][xWave]
<< " i (" << amplitudeOut[yWave][xWave] << ")\n";
}
}
}
}
/*
Enter the size:
2
Enter the 2D elements
2 3
4 2
2.5 + 0.0 i
5.5 + 0.0 i
-0.5 + -1.8369701987210297E-16 i
0.5 + -3.0616169978683826E-16 i
2.5 + 0.0 i
-0.5 + -3.6739403974420594E-16 i
-0.5 + -1.8369701987210297E-16 i
-1.5 + -1.8369701987210297E-16 i

@ -1,40 +0,0 @@
#include<conio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(int argc, char **argv)
{
cout<<"Enter the dimension of the matrix:\n ";
int rowA;
cin>>rowA;
int colA;
cin>>colA;
cout<<"Enter the dimension of the other matrix:\n ";
int rowB;
cin>>rowB;
int colB;
cin>>colB;
if(colA == rowB)
{
cout<<"Matrices are multipilcable";
}
else
{
cout<<"Matrices are not multipilcable";
}
}
/*
Enter the dimension of the matrix:
2 4
Enter the dimension of the other matrix:
2 5
Matrices are not multipilcable
Enter the dimension of the matrix:
4 5
Enter the dimension of the other matrix:
5 6
Matrices are multipilcable

@ -1,76 +0,0 @@
#include<conio.h>
#include<iostream>
#include<math.h>
using namespace std;
double d = 0;
double det(int n, double mat[10][10]);
double det(int n, double mat[10][10])
{
double submat[10][10];
if (n == 2)
return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));
else
{
for (int c = 0; c < n; c++)
{
int subi = 0; //submatrix's i value
for (int i = 1; i < n; i++)
{
int subj = 0;
for (int j = 0; j < n; j++)
{
if (j == c)
continue;
submat[subi][subj] = mat[i][j];
subj++;
}
subi++;
}
d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));
}
}
return d;
}
int main(int argc, char **argv)
{
cout << "Enter the dimension of the matrix:\n";
int n;
cin >> n;
double mat[10][10];
cout << "Enter the elements of the matrix:\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> mat[j][i];
}
}
if (det(n, mat) != 0)
{
cout << "The given matrix is invertible";
}
else
{
cout << "The given matrix is not invertible";
}
}
/*
Enter the dimension of the matrix:
3
Enter the elements of the matrix:
1 2 3
4 5 6
7 8 9
The given matrix is not invertible
Enter the dimension of the matrix:
5
Enter the elements of the matrix:
1 2 3 4 5
6 7 8 9 0
0 9 8 7 6
5 4 3 2 1
1 3 5 7 9
The given matrix is invertible

@ -1,54 +0,0 @@
#include <iostream>
#include <conio.h>
using namespace std;
int main(int argc, char **argv)
{
cout<<"Enter the dimensions of the matrix: ";
int m, n;
cin>>m>>n;
double mat[m][n];
int zeros = 0;
cout<<"Enter the elements of the matrix: ";
for(int i=0; i<m; i++)
{
for(int j=0; j<n; j++)
{
cin>>mat[i][j];
if(mat[i][j] == 0)
{
zeros++;
}
}
}
if(zeros > (m*n)/2)
{
cout<<"The matrix is a sparse matrix";
}
else
{
cout<<"The matrix is not a sparse matrix";
}
}
/*
Enter the dimensions of the matrix:
3 3
Enter the elements of the matrix:
1 2 3
4 5 6
0 0 0
The matrix is not a sparse matrix
Enter the dimensions of the matrix:
3 3
Enter the elements of the matrix:
1 1 0
0 0 1
1 0 0
The matrix is a sparse matrix

@ -1,65 +0,0 @@
/*This is a C++ Program to compute the coefficients of the DFT (Discrete Fourier Transform) directly. In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.*/
#include<iostream>
#include<math.h>
using namespace std;
#define PI 3.14159265
class DFT_Coefficient
{
public:
double real, img;
DFT_Coefficient()
{
real = 0.0;
img = 0.0;
}
};
int main(int argc, char **argv)
{
int N = 10;
cout << "Calculation DFT Coefficients\n";
cout << "Enter the coefficient of simple linear function:\n";
cout << "ax + by = c\n";
double a, b, c;
cin >> a >> b >> c;
double function[N];
for (int i = 0; i < N; i++)
{
function[i] = (((a * (double) i) + (b * (double) i)) - c);
//System.out.print( " "+function[i] + " ");
}
cout << "Enter the max K value: ";
int k;
cin >> k;
double cosine[N];
double sine[N];
for (int i = 0; i < N; i++)
{
cosine[i] = cos((2 * i * k * PI) / N);
sine[i] = sin((2 * i * k * PI) / N);
}
DFT_Coefficient dft_val;
cout << "The coefficients are: ";
for (int i = 0; i < N; i++)
{
dft_val.real += function[i] * cosine[i];
dft_val.img += function[i] * sine[i];
}
cout << "(" << dft_val.real << ") - " << "(" << dft_val.img << " i)";
}
/*
Calculation DFT Coefficients
Enter the coefficient of simple linear funtion:
ax + by = c
1 2 3
Enter the max K value:
2
The coefficients are: (-15) - (-20.6457 i)
------------------
(program exited with code: 0)
Press return to continue

@ -1,69 +0,0 @@
#include<conio.h>
#include<iostream>
#include<math.h>
using namespace std;
double d = 0;
double det(int n, double mat[10][10]);
double det(int n, double mat[10][10])
{
double submat[10][10];
if (n == 2)
return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));
else
{
for (int c = 0; c < n; c++)
{
int subi = 0; //submatrix's i value
for (int i = 1; i < n; i++)
{
int subj = 0;
for (int j = 0; j < n; j++)
{
if (j == c)
continue;
submat[subi][subj] = mat[i][j];
subj++;
}
subi++;
}
d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));
}
}
return d;
}
int main(int argc, char **argv)
{
cout << "Enter the dimension of the matrix:\n";
int n;
cin >> n;
double mat[10][10];
cout << "Enter the elements of the matrix:\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> mat[j][i];
}
}
cout << "The determinant of the given matrix is: " << det(n, mat);
return 0;
}
/*
Enter the dimension of the matrix:
3
Enter the elements of the matrix:
3 5 2
8 4 8
2 4 7
The determinant of the given matrix is: -164
Enter the dimension of the matrix:
4
Enter the elements of the matrix:
9 5 2 5
9 5 3 7
6 5 4 8
1 5 3 7
The determinant of the given matrix is: 0

@ -1,84 +0,0 @@
/*This is a C++ Program to perform Discrete Fourier Transform using Naive approach. In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.*/
#include<iostream>
#include<math.h>
using namespace std;
#define PI 3.14159265
class DFT_Coefficient
{
public:
double real, img;
DFT_Coefficient()
{
real = 0.0;
img = 0.0;
}
};
int main(int argc, char **argv)
{
int N = 10;
cout << "Discrete Fourier Transform using naive method\n";
cout << "Enter the coefficient of simple linear function:\n";
cout << "ax + by = c\n";
double a, b, c;
cin >> a >> b >> c;
double function[N];
for (int i = 0; i < N; i++)
{
function[i] = (((a * (double) i) + (b * (double) i)) - c);
//System.out.print( " "+function[i] + " ");
}
cout << "Enter the max K value: ";
int k;
cin >> k;
double cosine[N];
double sine[N];
for (int i = 0; i < N; i++)
{
cosine[i] = cos((2 * i * k * PI) / N);
sine[i] = sin((2 * i * k * PI) / N);
}
DFT_Coefficient dft_val[k];
cout << "The coefficients are: ";
for (int j = 0; j < k; j++)
{
for (int i = 0; i < N; i++)
{
dft_val[j].real += function[i] * cosine[i];
dft_val[j].img += function[i] * sine[i];
}
cout << "(" << dft_val[j].real << ") - " << "(" << dft_val[j].img << " i)\n";
}
}
/*
Discrete Fourier Transform using naive method
Enter the coefficient of simple linear function:
ax + by = c
1 2 3
Enter the max K value: 20
The coefficients are:
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)
(105) - (-1.03386e-005 i)

@ -1,73 +0,0 @@
/*This is a C++ Program to perform Fast Fourier Transform. A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.*/
#include <iostream>
#include <complex>
#include <cmath>
#include <iterator>
using namespace std;
unsigned int bitReverse(unsigned int x, int log2n)
{
int n = 0;
int mask = 0x1;
for (int i = 0; i < log2n; i++)
{
n <<= 1;
n |= (x & 1);
x >>= 1;
}
return n;
}
const double PI = 3.1415926536;
template<class Iter_T>
void fft(Iter_T a, Iter_T b, int log2n)
{
typedef typename iterator_traits<iter_t>::value_type complex;
const complex J(0, 1);
int n = 1 << log2n;
for (unsigned int i = 0; i < n; ++i)
{
b[bitReverse(i, log2n)] = a[i];
}
for (int s = 1; s <= log2n; ++s)
{
int m = 1 << s;
int m2 = m >> 1;
complex w(1, 0);
complex wm = exp(-J * (PI / m2));
for (int j = 0; j < m2; ++j)
{
for (int k = j; k < n; k += m)
{
complex t = w * b[k + m2];
complex u = b[k];
b[k] = u + t;
b[k + m2] = u - t;
}
w *= wm;
}
}
}
int main(int argc, char **argv)
{
typedef complex cx;
cx a[] = { cx(0, 0), cx(1, 1), cx(3, 3), cx(4, 4), cx(4, 4), cx(3, 3), cx(
1, 1), cx(0, 0)
};
cx b[8];
fft(a, b, 3);
for (int i = 0; i < 8; ++i)
cout << b[i] << "\n";
}
/*
(16,16)
(-4.82843,-11.6569)
(0,0)
(-0.343146,0.828427)
(0,0)
(0.828427,-0.343146)
(0,0)
(-11.6569,-4.82843)

@ -1,25 +0,0 @@
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv)
{
cout << "Enter the number of dice: ";
int n;
cin >> n;
cout << "The values on dice are: ( ";
for (int i = 0; i < n; i++)
cout << (rand() % 6) + 1<<" ";
cout<<")";
}
/*
Enter the number of dice: 5
The values on dice are: ( 6 6 5 5 6 )
Enter the number of dice: 1
The values on dice are: ( 6 )
Enter the number of dice: 3
The values on dice are: ( 6 6 5 )

@ -1,74 +0,0 @@
#include<conio.h>
#include<iostream>
#include<math.h>
using namespace std;
double d = 0;
double det(int n, double mat[10][10]);
double det(int n, double mat[10][10])
{
double submat[10][10];
if (n == 2)
return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));
else
{
for (int c = 0; c < n; c++)
{
int subi = 0; //submatrix's i value
for (int i = 1; i < n; i++)
{
int subj = 0;
for (int j = 0; j < n; j++)
{
if (j == c)
continue;
submat[subi][subj] = mat[i][j];
subj++;
}
subi++;
}
d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat));
}
}
return d;
}
int main(int argc, char **argv)
{
cout << "Enter the number of vectors:\n";
int n;
cin >> n;
double mat[10][10];
cout << "Enter the vectors one by one:\n";
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> mat[j][i];
}
}
d = det(n, mat);
if (d != 0)
cout << "The vectors forms the basis of R" << n
<< " as the determinant is non-zero";
else
cout << "The vectors doesn't form the basis of R" << n
<< " as the determinant is zero";
}
/*
Enter the number of vectors:
3
Enter the vectors one by one:
1 2 3
2 3 4
3 4 5
The vectors doesn't form the basis of R3 as the determinant is zero
Enter the number of vectors:
4
Enter the vectors one by one:
2 3 5 8
1 6 2 9
3 4 2 7
2 5 3 9
The vectors forms the basis of R4 as the determinant is non-zero

@ -1,137 +0,0 @@
/*
* C++ Program to Find Closest Pair of Points in an Array
*/
#include <iostream>
#include <cfloat>
#include <cstdlib>
#include <cmath>
using namespace std;
/*
* Point Declaration
*/
struct Point
{
int x, y;
};
/*
* sort array of points according to X coordinate
*/
int compareX(const void* a, const void* b)
{
Point *p1 = (Point *)a, *p2 = (Point *)b;
return (p1->x - p2->x);
}
/*
* sort array of points according to Y coordinate
*/
int compareY(const void* a, const void* b)
{
Point *p1 = (Point *)a, *p2 = (Point *)b;
return (p1->y - p2->y);
}
/*
* find the distance between two points
*/
float dist(Point p1, Point p2)
{
return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
/*
* return the smallest distance between two points
*/
float small_dist(Point P[], int n)
{
float min = FLT_MAX;
for (int i = 0; i < n; ++i)
{
for (int j = i + 1; j < n; ++j)
{
if (dist(P[i], P[j]) < min)
min = dist(P[i], P[j]);
}
}
return min;
}
/*
* find the distance beween the closest points of strip of given size
*/
float stripClosest(Point strip[], int size, float d)
{
float min = d;
for (int i = 0; i < size; ++i)
{
for (int j = i + 1; j < size && (strip[j].y - strip[i].y) < min; ++j)
{
if (dist(strip[i],strip[j]) < min)
min = dist(strip[i], strip[j]);
}
}
return min;
}
/*
* find the smallest distance.
*/
float closestUtil(Point Px[], Point Py[], int n)
{
if (n <= 3)
return small_dist(Px, n);
int mid = n / 2;
Point midPoint = Px[mid];
Point Pyl[mid + 1];
Point Pyr[n - mid - 1];
int li = 0, ri = 0;
for (int i = 0; i < n; i++)
{
if (Py[i].x <= midPoint.x)
Pyl[li++] = Py[i];
else
Pyr[ri++] = Py[i];
}
float dl = closestUtil(Px, Pyl, mid);
float dr = closestUtil(Px + mid, Pyr, n-mid);
float d = min(dl, dr);
Point strip[n];
int j = 0;
for (int i = 0; i < n; i++)
{
if (abs(Py[i].x - midPoint.x) < d)
strip[j] = Py[i], j++;
}
return min(d, stripClosest(strip, j, d));
}
/*
* finds the smallest distance
*/
float closest(Point P[], int n)
{
Point Px[n];
Point Py[n];
for (int i = 0; i < n; i++)
{
Px[i] = P[i];
Py[i] = P[i];
}
qsort(Px, n, sizeof(Point), compareX);
qsort(Py, n, sizeof(Point), compareY);
return closestUtil(Px, Py, n);
}
/*
* Main
*/
int main()
{
Point P[] = {{2, 3}, {12, 30}, {40, 50}, {5, 1}, {12, 10}, {3, 4}};
int n = sizeof(P) / sizeof(P[0]);
cout << "The smallest distance is " << closest(P, n);
return 0;
}
/*
The smallest distance is 1.41421
------------------
(program exited with code: 1)
Press return to continue

@ -1,83 +0,0 @@
/*
* C++ Program to Find Factorial of Large Numbers
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
int fact[101][200] = {0};
/*
* Find Factorial of Large Numbers
* fact[i][0] is used to store the number of digits
*/
void fact_large(int n)
{
int i;
fact[1][0] = 1;
fact[1][1] = 1;
if (fact[n][0] == 0)
{
for (i = n - 1; i > 0 ; i--)
{
if (fact[i][0] != 0)
break;
}
for ( ; i < n; i++)
{
int j = 1;
int carry = 0;
int len = fact[i][0];
while (len--)
{
int temp = (i + 1) * fact[i][j] + carry;
fact[i + 1][j] = temp % 10;
carry = temp / 10;
j++;
}
while (carry > 0)
{
fact[i + 1][j] = carry % 10;
carry /= 10;
j++;
}
fact[i + 1][0] = j - 1;
}
}
for (i = fact[n][0]; i > 0; i--)
{
cout << fact[n][i];
}
cout<<endl;
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter interger to compute factorial(0 to exit): ";
cin>>n;
if (n == 0)
break;
fact_large(n);
}
return 0;
}
/*
Enter interger to compute factorial(0 to exit): 100
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
Enter interger to compute factorial(0 to exit): 50
30414093201713378043612608166064768844377641568960512000000000000
Enter interger to compute factorial(0 to exit): 72
61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000
Enter interger to compute factorial(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,55 +0,0 @@
/*
* C++ Program to Find Factorial of a Number using Dynamic Programming
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
int result[1000] = {0};
/*
* Find Factorial of a Number using Dynamic Programming
*/
ll fact_dp(int n)
{
if (n >= 0)
{
result[0] = 1;
for (int i = 1; i <= n; ++i)
{
result[i] = i * result[i - 1];
}
return result[n];
}
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter interger to compute factorial(0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fact_dp(n)<<endl;
}
return 0;
}
/*
Enter interger to compute factorial(0 to exit): 10
3628800
Enter interger to compute factorial(0 to exit): 20
2432902008176640000
Enter interger to compute factorial(0 to exit): 15
1307674368000
Enter interger to compute factorial(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,49 +0,0 @@
/*
* C++ Program to Find Factorial of a Number using Iteration
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
/*
* Find Factorial of a Number using Iteration
*/
ll fact_iter(int n)
{
ll result = 1;
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter interger to compute factorial(0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fact_iter(n)<<endl;
}
return 0;
}
/*
Enter interger to compute factorial(0 to exit): 10
3628800
Enter interger to compute factorial(0 to exit): 20
2432902008176640000
Enter interger to compute factorial(0 to exit): 15
1307674368000
Enter interger to compute factorial(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,47 +0,0 @@
/*
* C++ Program to Find Factorial of a Number using Recursion
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
/*
* Find Factorial of a Number using Recursion
*/
ll fact_recur(int n)
{
if (n == 0 || n == 1)
return 1;
else
return n * fact_recur(n - 1);
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter interger to compute factorial(0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fact_recur(n)<<endl;
}
return 0;
}
/*
Enter interger to compute factorial(0 to exit): 10
3628800
Enter interger to compute factorial(0 to exit): 20
2432902008176640000
Enter interger to compute factorial(0 to exit): 15
1307674368000
Enter interger to compute factorial(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,71 +0,0 @@
/*
* C++ Program to Find Fibonacci Numbers using Dynamic Programming
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
ll fib[1000] = {0};
/*
* Fibonacci Numbers using Dp
*/
ll fibo_dp(int n)
{
fib[1] = 1;
fib[2] = 1;
if (fib[n] == 0)
{
for (int j = 3; j <= n; ++j)
{
if (fib[n] == 0)
fib[j] = fib[j - 1] + fib[j - 2];
else
continue;
}
}
return fib[n];
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fibo_dp(n)<<endl;
}
return 0;
}
/*
Enter the integer n to find nth fibonnaci no.(0 to exit): 10
55
Enter the integer n to find nth fibonnaci no.(0 to exit): 9
34
Enter the integer n to find nth fibonnaci no.(0 to exit): 8
21
Enter the integer n to find nth fibonnaci no.(0 to exit): 7
13
Enter the integer n to find nth fibonnaci no.(0 to exit): 6
8
Enter the integer n to find nth fibonnaci no.(0 to exit): 5
5
Enter the integer n to find nth fibonnaci no.(0 to exit): 4
3
Enter the integer n to find nth fibonnaci no.(0 to exit): 3
2
Enter the integer n to find nth fibonnaci no.(0 to exit): 2
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,68 +0,0 @@
/*
* C++ Program to Find Fibonacci Numbers using Iteration
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
/*
* Iterative function to find Fibonacci Numbers
*/
ll fibo_iter(int n)
{
int previous = 1;
int current = 1;
int next = 1;
for (int i = 3; i <= n; ++i)
{
next = current + previous;
previous = current;
current = next;
}
return next;
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fibo_iter(n)<<endl;
}
return 0;
}
/*
Enter the integer n to find nth fibonnaci no.(0 to exit): 1
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 2
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 3
2
Enter the integer n to find nth fibonnaci no.(0 to exit): 4
3
Enter the integer n to find nth fibonnaci no.(0 to exit): 5
5
Enter the integer n to find nth fibonnaci no.(0 to exit): 6
8
Enter the integer n to find nth fibonnaci no.(0 to exit): 7
13
Enter the integer n to find nth fibonnaci no.(0 to exit): 8
21
Enter the integer n to find nth fibonnaci no.(0 to exit): 9
34
Enter the integer n to find nth fibonnaci no.(0 to exit): 10
55
Enter the integer n to find nth fibonnaci no.(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,92 +0,0 @@
/*
* C++ Program to Find Fibonacci Numbers using Matrix Exponentiation
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
/*
* function to multiply two matrices
*/
void multiply(ll F[2][2], ll M[2][2])
{
ll x = F[0][0] * M[0][0] + F[0][1] * M[1][0];
ll y = F[0][0] * M[0][1] + F[0][1] * M[1][1];
ll z = F[1][0] * M[0][0] + F[1][1] * M[1][0];
ll w = F[1][0] * M[0][1] + F[1][1] * M[1][1];
F[0][0] = x;
F[0][1] = y;
F[1][0] = z;
F[1][1] = w;
}
/*
* function to calculate power of a matrix
*/
void power(ll F[2][2], int n)
{
if (n == 0 || n == 1)
return;
ll M[2][2] = {{1,1},{1,0}};
power(F, n / 2);
multiply(F, F);
if (n % 2 != 0)
multiply(F, M);
}
/*
* function that returns nth Fibonacci number
*/
ll fibo_matrix(ll n)
{
ll F[2][2] = {{1,1},{1,0}};
if (n == 0)
return 0;
power(F, n - 1);
return F[0][0];
}
/*
* Main
*/
int main()
{
int n;
while (1)
{
cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): ";
cin>>n;
if (n == 0)
break;
cout<<fibo_matrix(n)<<endl;
}
return 0;
}
/*
Enter the integer n to find nth fibonnaci no.(0 to exit): 1
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 2
1
Enter the integer n to find nth fibonnaci no.(0 to exit): 3
2
Enter the integer n to find nth fibonnaci no.(0 to exit): 4
3
Enter the integer n to find nth fibonnaci no.(0 to exit): 5
5
Enter the integer n to find nth fibonnaci no.(0 to exit): 6
8
Enter the integer n to find nth fibonnaci no.(0 to exit): 7
13
Enter the integer n to find nth fibonnaci no.(0 to exit): 8
21
Enter the integer n to find nth fibonnaci no.(0 to exit): 9
34
Enter the integer n to find nth fibonnaci no.(0 to exit): 10
55
Enter the integer n to find nth fibonnaci no.(0 to exit): 0
------------------
(program exited with code: 1)
Press return to continue

@ -1,62 +0,0 @@
/*
* C++ Program to Find Fibonacci Numbers using Recursion
*/
#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
/*
* Recursive function to find Fibonnaci Numbers
*/
ll fibo_recur(int n)
{