0% found this document useful (0 votes)
27 views3 pages

CT1 - B - Solution

The document outlines a class test for CSE2217: Data Structure and Algorithms II, consisting of three questions focusing on time complexity analysis. It includes exercises on determining exact time complexities, best and worst case scenarios for a given code, and formulating a recurrence relation for a problem. The test is structured to assess understanding of asymptotic notation and complexity analysis techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

CT1 - B - Solution

The document outlines a class test for CSE2217: Data Structure and Algorithms II, consisting of three questions focusing on time complexity analysis. It includes exercises on determining exact time complexities, best and worst case scenarios for a given code, and formulating a recurrence relation for a problem. The test is structured to assess understanding of asymptotic notation and complexity analysis techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE2217: Data Structure and Algorithms II (Fall ’24)

Class Test -1 Sec: B Total: 20 marks Time: 30 min


Name: Id:

1. Find the exact time complexity of each line and represent the total time [5]
complexity using asymptotic notation: [You must represent total time
complexity using n]

1. int p=0; 1

2. for(int k=1;k<=n;k*=2) logn + 2

3. p++; logn + 1

4. for(int j=1;j*j<=p;j++) √𝑙𝑜𝑔𝑛 + 1 + 1

5. printf("%d ",j); √𝑙𝑜𝑔𝑛 + 1

T(n) = O (logn)
2. Find the best case and worst case time complexity of the following code [6]
and represent them using big-oh notation:

Best case worst

1. int count=0; O(1) O(1)

2. for(int i=1;i<n;i++){ O(n) O(n)

3. if(a[i]>10){ O(n) O(n)

4. int j=1; 0 O(n)

5. while(j<=n){ 0 O(n logn)

6. count++; 0 O(n logn)

7. j=j*2; 0 O(n logn)

8. }
9. }
10. count--; O(n) O(n)
11. }
Total time complexity using big-oh O(n) O(n logn)
3. Suppose, A problem X of size n can be divided into 2 subproblems each of [2+
size n/3, each of the problem can be solved recursively in time T(n/3) 3+4
respectively. The cost of dividing the problem and combining the results ]
of the subproblems is O(n). Formulate the recurrence relation assuming,
T(1) = O(1). Then solve the recurrence relation using
i. Master theorem
ii. Recursion tree

You might also like