Software Development Exam  >  Software Development Test  >  DSA in C++  >  Test: Time and Space Complexity - 1 - Software Development MCQ

Time and Space Complexity - 1 - Free MCQ Practice Test with solutions,


MCQ Practice Test & Solutions: Test: Time and Space Complexity - 1 (15 Questions)

You can prepare effectively for Software Development DSA in C++ with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Time and Space Complexity - 1". These 15 questions have been designed by the experts with the latest curriculum of Software Development 2026, to help you master the concept.

Test Highlights:

  • - Format: Multiple Choice Questions (MCQ)
  • - Duration: 30 minutes
  • - Number of Questions: 15

Sign up on EduRev for free to attempt this test and track your preparation progress.

Test: Time and Space Complexity - 1 - Question 1

Which of the following best describes time complexity in algorithms?

Detailed Solution: Question 1

Time complexity in algorithms refers to the amount of time taken by an algorithm to execute or run, usually measured in terms of the number of operations or steps executed.

Test: Time and Space Complexity - 1 - Question 2

What does O(1) time complexity mean?

Detailed Solution: Question 2

O(1) time complexity means that the algorithm takes a constant amount of time to run, irrespective of the input size. It indicates that the algorithm has a fixed number of operations.

Test: Time and Space Complexity - 1 - Question 3

Which of the following represents the best-case time complexity of an algorithm? a) O

Detailed Solution: Question 3

The best-case time complexity of an algorithm represents the minimum amount of time it takes to run, given a particular input. O(1) represents constant time complexity, indicating that the algorithm takes a constant amount of time, regardless of the input size.

Test: Time and Space Complexity - 1 - Question 4

Which of the following represents the worst-case time complexity of an algorithm?

Detailed Solution: Question 4

The worst-case time complexity of an algorithm represents the maximum amount of time it takes to run, given a particular input. O(n2) represents quadratic time complexity, indicating that the algorithm's running time grows exponentially with the input size.

Test: Time and Space Complexity - 1 - Question 5

What does space complexity in algorithms measure?

Detailed Solution: Question 5

Space complexity in algorithms refers to the amount of memory used by an algorithm to store data and variables during its execution. It measures how the space requirements of the algorithm grow with the input size.

Test: Time and Space Complexity - 1 - Question 6

What is the time complexity of the following code snippet?
int sum = 0;
for (int i = 0; i < n; i++) {
    sum += i;
}

Detailed Solution: Question 6

The given code snippet has a loop that runs n times, where n is the input size. Since the loop executes n times, the time complexity is O(n).

Test: Time and Space Complexity - 1 - Question 7

What is the output of the following code snippet?
int count = 0;
for (int i = 1; i <= n; i *= 2) {
    count++;
}
cout << count;

Detailed Solution: Question 7

The loop iterates until i exceeds n, where i is doubled in each iteration. The number of iterations can be calculated as log2(n), which represents the logarithmic time complexity.

Test: Time and Space Complexity - 1 - Question 8

What is the time complexity of the following code snippet?
for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
        cout << i << " " << j << endl;
    }
}

Detailed Solution: Question 8

The code snippet contains nested loops, with both loops iterating n times. Hence, the overall time complexity is O(n^2), indicating a quadratic time complexity.

Test: Time and Space Complexity - 1 - Question 9

What is the output of the following code snippet?
int n = 5;
int count = 0;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
            count++;
        }
    }
}
cout << count;

Detailed Solution: Question 9

The code snippet contains three nested loops, each running n times. Hence, the total number of iterations is n * n * n = n^3 = 5^3 = 125.

Test: Time and Space Complexity - 1 - Question 10

What is the space complexity of the following code snippet?
int n = 10;
int* arr = new int[n];
for (int i = 0; i < n; i++) {
    arr[i] = i;
}
delete[] arr;

Detailed Solution: Question 10

The code snippet allocates memory for an array of size n and then deallocates it using the delete[] operator. The space complexity is constant O(1) because the memory usage does not depend on the input size

Test: Time and Space Complexity - 1 - Question 11

What is the time complexity of the following code snippet?
int count = 0;
for (int i = 1; i <= n; i *= 2) {
    for (int j = 0; j < n; j++) {
        count++;
    }
}
cout << count;

Detailed Solution: Question 11

The outer loop runs log2(n) times, and the inner loop runs n times. Hence, the time complexity is O(n log n).

Test: Time and Space Complexity - 1 - Question 12

What is the time complexity of the following code snippet?
int count = 0;
for (int i = 1; i <= n; i *= 2) {
    for (int j = 0; j < i; j++) {
        count++;
    }
}
cout << count;

Detailed Solution: Question 12

The outer loop runs log2(n) times, and the inner loop runs i times, where i doubles in each iteration. Hence, the time complexity is O(n log n).

Test: Time and Space Complexity - 1 - Question 13

What is the time complexity of the following code snippet?
int count = 0;
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j *= 2) {
        count++;
    }
}
cout << count;

Detailed Solution: Question 13

The outer loop runs n times, and the inner loop runs log2(i) times, where i doubles in each iteration. Hence, the time complexity is O(log n).

Test: Time and Space Complexity - 1 - Question 14

What is the time complexity of the following code snippet?
int count = 0;
for (int i = 1; i <= n; i *= 2) {
    for (int j = 1; j <= i; j++) {
        for (int k = 1; k <= n; k *= 2) {
            count++;
        }
    }
}
cout << count;

Detailed Solution: Question 14

The outer loop runs log2(n) times, the middle loop runs i times, and the inner loop runs log2(n) times. Hence, the time complexity is O(n^2).

Test: Time and Space Complexity - 1 - Question 15

What is the time complexity of the following code snippet?
int count = 0;
for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
        count++;
    }
}
cout << count;

Detailed Solution: Question 15

The outer loop runs n times, and the inner loop runs n - i times. The total number of iterations is 1 + 2 + 3 + ... + n, which is equivalent to (n * (n + 1)) / 2. Hence, the time complexity is O(n^2).

152 videos|118 docs|24 tests
Information about Test: Time and Space Complexity - 1 Page
In this test you can find the Exam questions for Test: Time and Space Complexity - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Time and Space Complexity - 1, EduRev gives you an ample number of Online tests for practice
152 videos|118 docs|24 tests
Download as PDF