TCS NQT Time Complexity Quiz- 1

Question 1

Time: 00:00:00
The worst-case complexity of quicksort is

O(n)

O(n)

O(log n)

O(log n)

O(n^2)

O(n^2)

O(n log n)

O(n log n)

Question 2

Time: 00:00:00
The complexity of merge sort algorithm is

O(n)

O(n)

O(log n)

O(log n)

O(n^2)

O(n^2)

O(n log n)

O(n log n)

Question 3

Time: 00:00:00
The worst-case complexity for insertion sort is

O(n)

O(n)

O(log n)

O(log n)

O(n^2)

O(n^2)

O(n log n)

O(n log n)

Question 4

Time: 00:00:00
In data structure, time and space complexity by asymptotic notation. Which one of the following notation is not used to represent the same?

Big theta  

Big theta  

Big omega  

Big omega  

Big oh  

Big oh  

Big game

Big game

Question 5

Time: 00:00:00
The worst-case occurs in quick sort when

Pivot is the median of the array

Pivot is the median of the array

Pivot is the smallest element

Pivot is the smallest element

Pivot is the middle element

Pivot is the middle element

None of the mentioned

None of the mentioned

Question 6

Time: 00:00:00
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?

X will always be a better choice for small inputs

X will always be a better choice for small inputs

X will always be a better choice for large inputs

X will always be a better choice for large inputs

Y will always be a better choice for small inputs

Y will always be a better choice for small inputs

X will always be a better choice for all inputs

X will always be a better choice for all inputs

Question 7

Time: 00:00:00
What is the time, space complexity of following code ?

int a = 0, b = 0; 
for (i = 0; i < N; i++){
a = a + rand();
}
for (j = 0; j < M; j++){
b = b + rand();
}

O(N * M) time, O(1) space

O(N * M) time, O(1) space

O(N + M) time, O(N + M) space

O(N + M) time, O(N + M) space

O(N + M) time, O(1) space

O(N + M) time, O(1) space

O(N * M) time, O(N + M) space

O(N * M) time, O(N + M) space

Question 8

Time: 00:00:00
What is the time complexity of the following code:

int a = 0, i = N; 
while (i > 0)
{
a += i;
i /= 2;
}


O(N)

O(N)

O(Sqrt(N))

O(Sqrt(N))

O(N / 2)

O(N / 2)

O(log N)

O(log N)

Question 9

Time: 00:00:00
What is the time complexity of the following code:

int i, j, k = 0; 
for (i = n / 2; i <= n; i++){
for (j = 2; j <= n; j = j * 2){
k = k + n / 2;
}
}

O(n)

O(n)

O(nLogn)

O(nLogn)

O(n^2)

O(n^2)

O(n^2Logn)

O(n^2Logn)

Question 10

Time: 00:00:00
What is the time complexity of the following code:

int a = 0; 
for (i = 0; i < N; i++){
for (j = N; j > i; j--){
a = a + i + j;
}
}
}

O(N)

O(N)

O(N*log(N))

O(N*log(N))

O(N*log(N/2))

O(N*log(N/2))

O(N*N)

O(N*N)

null
null


Buy TCS NQT Paid Materials

Paid Materials TCS NQT

Join TCS NQT Online Classes