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 - 2". 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:
Sign up on EduRev for free to attempt this test and track your preparation progress.
Which of the following asymptotic notations represents the worst-case time complexity of an algorithm?
Detailed Solution: Question 1
The time complexity of an algorithm is expressed as O(log n). This indicates that the algorithm has a ________ time complexity.
Detailed Solution: Question 2
Which of the following asymptotic notations represents the upper bound of the time complexity of an algorithm?
Detailed Solution: Question 3
In terms of time complexity, which of the following statements is correct?
Detailed Solution: Question 4
The time complexity of an algorithm is given by T(n) = 5n^2 + 3n + 2. What is the dominant term in this equation?
Detailed Solution: Question 5
What will be the output of the following code?
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j = j * 2) {
sum++;
}
}
cout << sum;
Detailed Solution: Question 6
What will be the output of the following code?
int func(int n) {
if (n <= 0) {
return 1;
}
return func(n / 2) + func(n / 2);
}
int result = func(8);
cout << result;
Detailed Solution: Question 7
What will be the output of the following code?
int n = 100;
int count = 0;
while (n > 0) {
n = n / 2;
count++;
}
cout << count;
Detailed Solution: Question 8
What will be the output of the following code?
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j = j * 2) {
cout << j << " ";
}
cout << endl;
}
Detailed Solution: Question 9
What will be the output of the following code?
int n = 4;
int count = 0;
for (int i = n; i >= 1; i = i / 2) {
for (int j = 1; j <= i; j++) {
count++;
}
}
cout << count;
Detailed Solution: Question 10
What is the time complexity of the following code snippet?
int func(int n) {
if (n <= 0) {
return 0;
}
return 1 + func(n / 2);
}
int result = func(16);
Detailed Solution: Question 11
What is the space complexity of the following code snippet?
void func(int n) {
if (n <= 0) {
return;
}
cout << n << " ";
func(n - 1);
func(n - 1);
}
func(4);
Detailed Solution: Question 12
Which of the following statements about time complexity is false?
Detailed Solution: Question 13
What is the time complexity of the following code snippet?
int sum = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j = j * 2) {
sum++;
}
}
Detailed Solution: Question 14
What is the space complexity of the following code snippet?
int fib(int n) {
if (n <= 1) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
int result = fib(5);
Detailed Solution: Question 15
152 videos|118 docs|24 tests |