Question: Given code, what is the running time in terms of big O / big ? Please mention operations int sample_code_01 (int n) { int s
Given code, what is the running time in terms of big O / big ? Please mention operations
| int sample_code_01 (int n) { int s = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) ++s; for (int j = 0; j < n; j++) ++s; for (int j = 0; j < n; j++) ++s; } return s; } |
| int sample_code_02 (int n) { int s = 0; s += sample_code_01(n) * sample_code_01(n); // Above s += sample_code_01(n/2); return s; } |
| int sample_code_03 (int n) { int s = 0; int t = 0; while (t < n * n * n) { for (int i = n; i > 0; i--) s++; for (int i = n; i > 1; i = i/2) s++; t += 2; } return s; } |
| int sample_code_04 (int n) { int s = 0; int t = n; while (t > 1) { int u = 0; while (u < n/2) u++; S++; u = n / 2; while (u > 0) { u--; s++; } t = t / 2; } return s; } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
