• edited by
821 views
0 0 votes

2. What is asymptotical complexity of the following program:
```
n= readInt()
n = readInt()
t = m
s = 4
for (int 1 = 0;1 for (Int j = 0; j< n/ 10000; J++)
while ( }n>0
5 += =
m/= 2
n=t
writeInt(s)
```
$O\left(n^{2} \times \log _{2}(m)\right)$
$O\left(n^{2}\right)$
$O\left(n \times \log _{2}(m)\right)$
$O(n \times m)$

1 Answer

2 2 votes
The inner most loop will run for O(log(m)) as m is getting halved in every iteration of the while loop. Now, the loop with iterator j runs for n/1000 which is independent of the value of i. So, j runs for O(n) every time and then the outermost loop with iterator as i runs for O(n) time.

Therefore, total complexity = $O(n^{2}log(m))$ . So, (a) should be the correct answer.
Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
981
981 views
Parshu gate asked Sep 17, 2017
981 views
What is the time complexity of the following code snippet? int j = 0;For (i=0;i
1 1 vote
1 answers 1 answer
2.2k
2.2k views
Rishabh Gupta 2 asked Aug 31, 2017
2,245 views
Consider the following program segment: count = 0;for 1-1 to n{M= floor(n/1);for j-1 to mcount = count + 1;} The order of magnitude of the program segment is$\theta(n...
2 2 votes
1 answers 1 answer
1.6k
1.6k views
gauravkc asked Apr 5, 2018
1,628 views
What is the time complexity of this code?What is the time complexity of the following code?for (int $\mathrm{i}=\mathbf{1} ; \mathrm{i}0 ; \mathrm{h}=\mathrm{h} / 2$ )sum...
3 3 votes
1 1 answer
1.5k
1.5k views
pranab ray asked Jan 15, 2018
1,464 views
Consider the following statements:\[\begin{array}{l}S_{1}: f(n)=\mathrm{O}\left((f(n))^{2}\right) \\S_{2}: \text { If } f(n)=\mathrm{O}(g(n)) \text { then } 2^{f(n)}=\mat...