Question: Answer the following question for every code below. Calculate how many times the cout statement is executed in the code below. Also provide the Time
- Answer the following question for every code below. Calculate how many times the cout statement is executed in the code below. Also provide the Time complexity function in terms of n for the following codes.[12]
| Sr# | Code | Count of cout statement & Time complexity function |
| 1 | s = 0; for (oloop=1; oloop < N; oloop *= 2) for(inloop = 0; inloop < oloop; inloop++) { cout< } |
|
| 2 | for (i=n/2; i<=n; i++) for (j=1; j+n/2<=n; j++) for (k=1; k<=n; k = k * 2){ cout< |
|
| 3 | S=1; While(s<=n) { for( int i=1;i<=s;s++) cout<< hello; s*=2; } |
|
| 4 | for (j=1; j<=n; j++) for (k=1; k<=j*3; k ++) { cout< } |
|
| 5 | for (j=1; j<=n; j++) for (k=n; k>=j; k --){ for (i=1; i<=5; i++) cout< } |
|
| 6 | for (j=1; j<=n; j*=2) for (k=n; k>=n; k --) { for (i=1; i<=n; i*=3) cout< } |
|
| 7 | int m = (int)((15 + Math.round(3.2 / 2)) * (Math.floor(10 / 5.5) / 2.5) * Math.pow(2, 5)); for (int i = 0; i < m; i++) { cout< }
|
|
| 8 | for (int i = 1; i <= N * N; i *= 2) { for (int j = 0; j < i; j++) { cout< } }
|
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
