DAA Mids SP2023 Sem 4 03052023 030929pm
DAA Mids SP2023 Sem 4 03052023 030929pm
Objective
Class: BSE 4-A&B Morning
Course Instructor: Engr. Bushra Fazal Khan Time Allowed: 20 min
Date: 10-04-2023 Session: II Max Marks: 5
Student’s Name: ____________________ Reg. No: _________
3. A ________ notation defines as “If a function f(x) is growing slower than function g(x)”.
(a) Little-o (b) Big- Omega (c) Big-O (d) Big-Theta
6. When an algorithm performs at most N passes and each pass takes N steps, the total
runtime will be _________
(a) O(2N) (b) O(N2) (c) O(Nlog2N) (d) O(N)
10. Which among the following is the best when the list is already sorted?
(a) Insertion sort (b) Bubble sort (c) Merge sort (d) Selection sort
11. What is the result of the recurrences which fall under second case of Master’s theorem
(let the recurrence be given by T(n)=aT(n/b)+f(n) and f(n)=nc?
(a) T(n) = O(nlogba) (b) T(n) = O(nc log n) (c) T(n) = O(f(n))
2
(d) T(n) = O(n )
12. Under what case of Master’s theorem will the recurrence relation of binary search fall?
(a) 1 (b) 2 (c) 3 (d) It cannot be solved using master’s theorem
Subjective
Class: BSE 4-A&B Morning
Course Instructor: Engr. Bushra Fazal Khan Time Allowed: 70 min
Date: 10-04-2023 Session: II Max Marks: 15
Student’s Name: ____________________ Reg. No: _________
}
int mystery2(int m)
{
int x=0
for(int i=1;i<=m;i++)
{
for(int j=m;j>=1;j--)
{
x++;
}
for(int k=i;k<=m;k++)
{
x--;
}
}
return x;
}
b) Analyze the following functions using Master Theorem to calculate Big-O time
complexity. (3)
int fun(int n)
{
int answer1, answer2;
if (n > 0)
{
answer1 =3*fun(n/2);
Print(answer1);
answer2 =3*fun(n/2);
Print(answer2);
}
int fun2(int m)
{
int x=0
for(int k=m;k>=1;k--)
{
x++
}
return x;
}
Write down the pseudo-code of a hash function that converts string to integer and apply
squaring method to result.