708 views
3 votes
3 votes

Need some clarification regarding this answer Do comment please:
 

1 Answer

Best answer
8 votes
8 votes

There are $6$ instances of addition

  • $i++$
  • $j++$
  • $k++$
  • $i+j(\text{let it be s})$
  • $s+k$
  • $d+1$

We have to count how many times each of them is calculated.

d=d+1

First of all we will calculate number of additions of $d+1$, it will on the other hand signify the overall time complexity of the code.

it will be $\frac{n \times n \times n }{2}=O(n^3) \Rightarrow \frac{20 \times 20 \times 20 }{2} =4000$


i+j+k

Number of addition =$2 \times n \times n \times n=16000$


i++

$20 \text{times}$


j++

$20 \times 20=400\text{times}$


k++

$20 \times 20 \times 20=8000\text{times}$


Total number of additions$=4000+16000+20+400+8000=28420$

selected by

Related questions

1 votes
1 votes
1 answer
1
Pranavpurkar asked Sep 27, 2022
328 views
DOUBT:suppose a memory space of 16B is given and it is asked that what is the maximum length of string it can store.then do we have to consider the space taken by the �...
0 votes
0 votes
1 answer
3
srestha asked Mar 1, 2019
518 views
void print(int i){ static int x=4; if(i!=0){ print( x); } printf("%d",x); }What will be output printed for print(10)?Will it print value as call by value or call by refer...