NPTEL Data Structures and Algorithms Design Week 2 Assignment Answers 2025
1. What is the worst-case time complexity of Bubble Sort?
- O(n2)
- O(nlogn)
- O(n)
- O(logn)
Answer : See Answers
2. What is the best time complexity of the following subroutine as a
function of n? Assume each instruction takes O(1) time only.
sum = 0;
for (i = 1; i < n; i = i*2)
for(j = 0; j < i; j = j+1)
sum = sum + 1;
- O(n)
- O(nlogn)
- O(n2)
- O(n2logn)
Answer :
3. Arrange the following in increasing order of growth: O(nlogn) O(n2) O(2n) O(n!)
- O(nlogn)<O(n2)<O(2n)<O(n!)
- O(nlogn)<O(2n)<O(n2)<O(n!)
- O(n2)<O(nlogn)<O(n!)<O(2n)
- O(2n)<O(n!)<O(n2)<O(nlogn)
Answer :
4. If f(n)=nlogn and g(n)=n(logn)2, which is true?
- f(n)=o(g(n))
- f(n)=ω(g(n))
- f(n)=Θ(g(n))
- g(n)=o(f(n))
Answer :
5. Let f(n)=2logn√, g(n)=(logn)5. Which of the following is true?
- g(n)=o(f(n))
- f(n)=o(g(n))
- f(n)=Θ(g(n))
- f(n)=ω(n)
Answer :
6. Arrange the following functions in increasing order of asymptotic growth:
1.n1.5
2.nlog2n
3.n−−√logn
4.n0.75
- 3<4<2<1
- 2<3<4<1
- 3<2<4<1
- 4<3<2<1
Answer : See Answers
7. Consider the following pseudocode:
for i = 1 to n:
j = i
while j > 1:
j = j / 2
What is the time complexity?
- O(nlogn)
- O(n)
- O(logn)
- O(n2)
Answer :
8. Consider the following pseudocode:
i = 2
while i <= n:
j = 2
while j <= \log i:
j = j * j
i = i * 2
What is the time complexity?
- O(lognâ‹…logloglogn)
- O(lognâ‹…loglogn)
- O(logn)
- O(n)
Answer :
9. At each index i, the O(n) maximum subarray sum algorithm updates the running sum by:
- Taking the maximum of the current element and the sum so far plus the current element
- Taking the minimum of the current element and the sum so far plus the current element
- Always adding the current element to the sum
- Comparing the current element to the maximum sum found so far
Answer :
10. What is the time complexity of a brute-force solution that checks all possible subarrays and computes their sums individually?
- O(n3)
- O(n2)
- O(nlogn)
- O(n!)
Answer : See Answers


