TCS Ninja Programming Logic Time Complexity Quiz-1

Question 1

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

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)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

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)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

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))

O(N*log(N))

O(N*N)

O(N*N)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
Which of the following case does not exist in complexity theory?

Best case

Best case

Worst case

Worst case

Average case

Average case

Null case

Null case

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

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

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

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

O(n)

O(n)

O(log n)

O(log n)

O(n2)

O(n2)

O(n log n)

O(n log n)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

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

O(n)

O(n)

O(log n)

O(log n)

O(n2)

O(n2)

O(n log n)

O(n log n)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

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

O(n)

O(n)

O(log n)

O(log n)

O(n2)

O(n2)

O(n log n)

O(n log n)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assurance

Get Access to PrepInsta Placement Cell

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.