Font size
WorksheetsTime and Space Complexity
Total questions: 91
Worksheet time: 1hrs 8mins
O(n)
O(m)
O(n+m)
O(n*m)
If for an algorithm time complexity is given by O(1) then complexityof it is:
constant
polynomial
exponential
none of the mentioned
If for an algorithm time complexity is given by O(n) then complexityof it is:
A. constant
B. linear
C. exponential
D. none of the mentioned
What is the time complexity of this algorithm?
O(n)
O(2n)
O(log n)
O(n2)
O(1)
What is the time complexity of this algorithm?
O(n)
O(2n)
O(log n)
O(n2)
O(1)
Why is this not a sequence?
Start car
Put in key
Turn key
Drive away
There are spelling mistakes
The instructions are in the correct order
The instructions are in the wrong order
It is a sequence
Which algorithm, will NOT take you from A to B
UP 1
RIGHT 5
UP 2
RIGHT 1
UP 3
RIGHT 4
UP 2
RIGHT 5
UP 1
LEFT 1
UP 3
RIGHT 5
What is an Algorithm?
A set of instructions that, when executed, completes a defined task that solves a problem.
The process of breaking apart a problem.
The process of removing unnecessary detail.
A sequence of instructions.
How do we represent the complexity of an algorithm?
Big-R
Big-O
Big-N
Big-A
What order of complexity does this graph represent?
Exponential
Polynomial
Linear
Logarithmic
What order of complexity does this graph represent?
Exponential
Polynomial
Linear
Constant
What order of complexity does this graph represent?
Exponential
Polynomial
Linear
Logarithmic
How do you reduce the time complexity of an algorithm?
You reduce the amount of embedded for loops, and then reduce the amount of items you complete the operations.
Try to complete all of the operations on the same data set
Which of the following is not O(n^2)?
(15^10) * n + 12099
n^1.98
n^3 / (sqrt(n))
(2^20) * n
Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3 and f4?
f1(n) = 2^n
f2(n) = n^(3/2)
f3(n) = nLogn
f4(n) = n^(Logn)
f3, f2, f4, f1
f3, f2, f1, f4
f2, f3, f1, f4
f2, f3, f4, f1
What is the correct Big O notation for an algorithm where the number of operations (steps) can be expressed as:
4n3 +3n log2n + 273 n is the size of the input.
O(n2)
O(3n)
O(log2n)
O(273)
O(n3)
What is the big-Oh runtime of A()?
O(nlogn)
O(n2)
O(n)
O(10⋅n)
What is true for f(n)=logn and g(n)=n ?
f(n)=O(g(n))
f(n)=θ(g(n))
f(n)=Ω(g(n))
What is the maximum number of comparisons that a binary search will apply for an array of length 30.
30
15
5
3
2
What is the big-Oh runtime of B()?
O(n2)
O(n3)
O(30⋅n)
O(n)
Which of these is true for f(n)=5n3+7n+13 and g(n) = n5 ?
f(n)=θ(g(n))
f(n)=Ω(g(n))
f(n)=O(g(n))
What is the big-Oh runtime of C(n)?
O(10)
O(n)
O(2n)
O(logn)
Which of the following is the time complexity of insertion sort?
O(n2)
O(logn)
O(n)
O(nlogn)
Which is true for f(n)=2n and g(n)=n! ?
f(n)=O(g(n))
f(n)=θ(g(n))
f(n)=Ω(g(n))
What is the big-Oh runtime of D(n)?
O(n⋅logn)
O(n2)
O(logn)
O(2n)
What is the time complexity of this code
int a = 0, i = N;
while (i > 0)
{
a += i;
i /= 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The complexity of Binary search algorithm is
O(n)
O(log n)
O(n2)
O(n log n)
What is the time complexity of 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*log(N))
O(N * Sqrt(N))
O(N*N)
What is the time complexity of 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(nLogn)
O(n^2)
O(n^2Logn)
A linear function takes the form
f(n) = an + b
f(n) = an2 +bn + c
f(n) = alog2n
f(n) = a + b
Find the slowest algorithm:
O (n)
O (n^2)
O (n!)
O (2^n)
The number of executions grows extremely quickly as the size of the input increases
Exponential Time
Linear Time
Polynomial Time
Constant Time
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
X will be a better choice for all inputs
X will be a better choice for all inputs except possibly small inputs
X will be a better choice for all inputs except possibly large inputs
Y will be a better choice for small inputs
What is the worst case running time of the above pseudo code?
O(n)
O(n log n)
O(n2)
O(n3)
asymptotic notations represents
space complexity of algo
time complexity of algo
both a and b
none of the above
Big
Ω defineslower bound
upper bound
middle bound
none of the above
What is an Algorithm?
A set of instructions that, when executed, completes a defined task that solves a problem.
The process of breaking apart a problem.
The process of removing unnecessary detail.
A sequence of instructions.
How do we represent the complexity of an algorithm?
Big-R
Big-O
Big-N
Big-A
What order of complexity does this graph represent?
Exponential
Polynomial
Linear
Logarithmic
What order of complexity does this graph represent?
Exponential
Polynomial
Linear
Constant
What order of complexity does this graph represent?
Exponential
Polynomial
Linear
Logarithmic
How do you reduce the time complexity of an algorithm?
You reduce the amount of embedded for loops, and then reduce the amount of items you complete the operations.
Try to complete all of the operations on the same data set
Which of the following is not O(n^2)?
(15^10) * n + 12099
n^1.98
n^3 / (sqrt(n))
(2^20) * n
Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3 and f4?
f1(n) = 2^n
f2(n) = n^(3/2)
f3(n) = nLogn
f4(n) = n^(Logn)
f3, f2, f4, f1
f3, f2, f1, f4
f2, f3, f1, f4
f2, f3, f4, f1
You are given a sorted Array A. What is the time complexity to determine if it has two elements whose sum is less than 100?
(a)
What are the time complexities of fun1() and fun2() respectively?
O(n) and O(n)
O(n) and O(2^n)
O(n^2) and O(2^n)
O(n^2) and O(n^2)
O(n^2) and O(n)
Find Time complexity of the following
(a)
Algorithm A and B have a worst-case running time of O(n) and O(log n) respectively. Therefore, algorithm B always runs faster than the algorithm A.
True
False
The asymptotic upper-bound of f(n)=20n2+100n+2 is O(n2)
True
False
The asymptotic upper-bound of f(n)=2n+2n is O(n2)
True
False
If for an algorithm time complexity is given by O(1) then complexity of it is
constant
polynomial
exponential
none of the mentioned
If for an algorithm time complexity is given by O(n) then complexity of it is
constant
linear
exponential
none of the mentioned
What is the time complexity of following code
int a = 0, i = N;
while (i > 0) {
a + = i;
i / = 2;
}
O(N)
O(Sqrt(N))
O(N / 2)
O(log N)
The linear/sequential search method to search an element in an array has the complexity of BigO(?)
n
n-1
n^2
n logn
Indicate exponential time complexity in terms of big-O notation
O (n)
O (n^2)
O (2^n)
O (log n)
Find the slowest time complexity
O (n)
O (n^2)
O (n!)
O (2^n)
Which notation is consistent for every execution?
O (n)
O (n^2)
O (1)
O (2^n)
Which notation grows in proportion to the size of the input
O (n)
O (n^2)
O (1)
O (2^n)
Which notation would you usually use for a nested loop?
O (n)
O (n^2)
O (1)
O (2^n)
The number of executions grows extremely quickly as the size of the input increases
Exponential Time
Linear Time
Polynomial Time
Constant Time
The number of executions remains the same regardless of the input size
Exponential Time
Linear Time
Polynomial Time
Constant Time
The number of executions grows quickly by the input being multiplied by the input
Exponential Time
Linear Time
Polynomial Time
Constant Time
For every element, you are doing a constant number of operations, such as comparing each element to a known value.
Quadratic
Linear
Logarithmic
Constant
Exponential
