MCPcopy Create free account
hub / github.com/anupam-kumar-krishnan/Competitive_Programming / main

Function main

All Algorithms/strassen.cpp:249–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249int main() {
250 clock_t start, end;
251 int r1, c1 = 0, r2 = 1, c2;
252 int **A, **B, **C;
253
254 while (c1 != r2) {
255 cout << "Column of Matrix A needs to be equal to row of matrix B" << endl;
256 cout << "Enter the row of matrix A: ";
257 cin >> r1;
258 cout << "Enter the column of matrix A: ";
259 cin >> c1;
260 cout << "Enter the row of matrix B: ";
261 cin >> r2;
262 cout << "Enter the column of matrix B: ";
263 cin >> c2;
264 }
265
266 // Converting dimension to 2^n because Strassen's Matrix Multiplication Algorithm works only on square
267 // matrices whose dimension is a power of 2.
268 int n = highestPowerof2(max(r1, max(c1, c2)));
269 A = initializeMatrix(n);
270 B = initializeMatrix(n);
271 setToZero(A, n, n);
272 setToZero(B, n, n);
273
274 input(A, r1, c1);
275
276 // printMatrix(A, r1, c1);
277
278 input(B, r2, c2);
279
280
281 start = clock();
282 C = multiply(A, B, n, n, n);
283 end = clock();
284 double time_taken = double(end - start) / CLOCKS_PER_SEC;
285 printMatrix(C, n, n);
286 cout << "Normal Multipliction of TC O(n^3): " << time_taken << " sec" << endl;
287
288
289 int** D = initializeMatrix(n);
290 setToZero(D, n , n);
291 start = clock();
292 D = strassenMultiply(A, B, n);
293 end = clock();
294 time_taken = double(end - start) / CLOCKS_PER_SEC;
295 cout << "divideAndConquer O(n^3): " << time_taken << " sec" << endl;
296
297 int** E = initializeMatrix(n);
298 setToZero(E, n , n);
299 start = clock();
300 E = strassenMultiply(A, B, n);
301 end = clock();
302 time_taken = double(end - start) / CLOCKS_PER_SEC;
303 cout << "strassenMultiply of TC O(n^2.8): " << time_taken << " sec" << endl;
304
305
306 for (int i = 0; i < r1; i++)

Callers

nothing calls this directly

Calls 8

highestPowerof2Function · 0.85
maxFunction · 0.85
initializeMatrixFunction · 0.85
setToZeroFunction · 0.85
inputFunction · 0.85
multiplyFunction · 0.85
strassenMultiplyFunction · 0.85
printMatrixFunction · 0.70

Tested by

no test coverage detected