MCQs about Time and Space Complexity Of a Program

1 B
2 C
3 B
4 B
5 C
6 D
7 C
8 C
9 C
10 B
11 A
12 C
13 C
14 B
15 B
16 B
17 B
18 D
19 B
20 B
21 C

Harmonic sum bounded by ln(n). See the link time complexity - Finding Big O of the Harmonic Series - Stack Overflow

option is correct

I guess in 17 there is worst case when all elements are same [4,4,4,4,4,4,4] then it will make O(n) tim e complexity

Why can’t it be O(max(n, m)) for the fifth question.

can anyone explain me the 19th question

taran_1407

Jan '18

1 B
2 C
3 B
4 B
5 C
6 D
7 C
8 C
9 C
10 B
11 A
12 C
13 C
14 B
15 B
17 B
18 D
19 B
20 B
21 C

explain 6th question plz

In this Question the outer for loop run n times (1 to n) and inner one runs m times(1 to m )
since for each iteration of outer loop ,the inner one runs m times
when i=1 ,j= 1to m
i=2,j=1 to m and so on …
hence its time complexity is O(n*m ).

1 B
2 C
3 B
4 B
5 C
6 C
7 C
8 C
9 C
10 B
11 A
12 C
13 C
14 B
15 B
16 B
17 -
18 -
19 -
20 -
21 -

3 B
4 B
5 C
6 D
7 C
8 C
9 C
10 B
11 A
12 C
13 C
14 B
16 B
17 B
18 D
19 B
20 B
21 A

time complexity is depend on both ‘n’ and ‘m’ variable. So , time complexity should express in term of both variable. This is same as O(n+n) => O(2n) that’s nothing but O(n) but in this case we don’t know whether ‘m’ equal to ‘n’ or not. So best way to express is O(m+n)

1b
2c
3b
4b
5c
6d
7c
8c
9c
10b
11a
12c
13c
14b
15b
16b
17b
18d
19b (liked this one)
20b
21c

Hi,
Can anyone explain me for Question 7,8,9 answers is C not B.As its going to n square times as per my understanding.
Please elaborate.

Why the same logic does not apply to question 7,8,9.I think they are similar to 21…Their ans also need to be nlogn according to your logic

No, because on 7,8,9 they are not increasing by i, but rather by 1. The inner loop will run n times and the outer loop will run n times, so it will be n^2. 8 is the same. For 9 when i =1 it will run n times, the n-1 then n-2 and so on. It is common knowledge that sum of natural numbers is (n^2 - n )/2

Ok Thanks @evenrule1.
Sorry i have not seen increment by i in that question i.e,21 so i got a doubt.I have understood the difference.

1- b
2-c
3-b
4-b
5-c
6-c(pls someone explain why this is d)
7-c
8-c
9-c
10-b
11-a
12-c
13-c
14-b
15-b
16-b
17-b
18-d
19-a
20-d
21-d

pls someone explain 19,20

  1. size of array is n+1 and each entry will turn from -1 to value>0 once in O(1).
  2. i will go from 0 to n-1 and j will also go from 0 n ( It won’t reset to 0 again). Hence this is also O(n).