0% found this document useful (0 votes)
1 views

Assignment

Uploaded by

ro6162
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Assignment

Uploaded by

ro6162
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q1.

CHOOSE1Solved

Stuck somewhere?
Ask for help from a TA and get it resolved.
Get help from TA.

Which of the following is not bounded by O(n^2)?

Choose the correct answer from below:


(15^10) * n + 12099
n^1.98
n^3 / (sqrt(n))
(2^20) * n

Q2. CHOOSE4Solved

Stuck somewhere?
Ask for help from a TA and get it resolved.
Get help from TA.

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

Choose the correct answer from below:


X will always be a better choice for all inputs
X will always be a better choice for large inputs
X will always be a better choice for small inputs
Y will always be a better choice for small inputs

Q3. DSA - 01Solved

Stuck somewhere?
Ask for help from a TA and get it resolved.
Get help from TA.
An algorithm consists of two independent piece of code, having complexities f(n) and g(n)
respectively. What would be the complexity of the complete algorithm

Choose the correct answer from below:


f(n) x g(n)
MAX( f(n), g(n) )
MIN ( f(n), g(n) )
f(n) + g(n)

Q4. LOOP_CMPL2Solved

Stuck somewhere?
Ask for help from a TA and get it resolved.
Get help from TA.

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;
}
}
Choose the correct answer from below:
&Theta;(n)
&Theta;(nLogn)
&Theta;(n^2)
&Theta;(n^2 / Logn)
&Theta;(n^2Logn)

Q5. NESTED_CMPLSolved

Stuck somewhere?
Ask for help from a TA and get it resolved.
Get help from TA.
What is the time, space complexity of following code :

 C++
 Java
 Python

int a = 0, b = 0;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
a = a + j;
}
}
for (k = 0; k < N; k++) {
b = b + k;
}
int a = 0, b = 0;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
a = a + j;
}
}
for (k = 0; k < N; k++) {
b = b + k;
}
a = 0
b = 0
for i in range(N):
for j in range(N):
a = a + j
for k in range(N):
b = b + k
Choose the correct answer from below:
O(N * N) time, O(1) space
O(N) time, O(N) space
O(N) time, O(N) space
O(N * N) time, O(N) space
O(N * N * N) time, O(1) space

Q6. LOOP_CMPLSolved

Stuck somewhere?
Ask for help from a TA and get it resolved.
Get help from TA.
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();
}

Assume that rand() is O(1) time, O(1) space function.

Choose the correct answer from below:


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

You might also like