0% found this document useful (0 votes)
12 views4 pages

DAA Mids SP2023 Sem 4 03052023 030929pm

Uploaded by

Rehab Khaleel
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)
12 views4 pages

DAA Mids SP2023 Sem 4 03052023 030929pm

Uploaded by

Rehab Khaleel
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/ 4

P

BAHRIA UNIVERSITY (KARACHI CAMPUS)


MIDTERM EXAMINATION – Spring 2023
DESIGN & ANALYSIS OF ALGORITHMS CSC-321

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: _________

Question#1 (Marks 5: CLO1) 20 Mins


Answer the following MCQs in grid given below

1. The runtime performance of a merge sort algorithm is ____________.


(a) O(N2) (b) O(N) (c) O(NLogN) (d) O(N+M)

2. A (an) _____________is a process of executing a correctly working program with the


appropriate data sets, and measuring the time and memory space it takes to execute various
parts of the program.
(a) Efficiency (b) Correctness (c) Debugging (d) Profiling

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

4. When two keys hash to the same value, is known as ________________.


(a) Hashing (b) Collision (c) Chaining (d) Dictionaries
5. A __________is a text that is a lot like a programming language but that is not really a
programming language.
(a) Program-Code (b) Pseudo-Code (c) Data Structure (d) Profiling

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)

7. The running time complexity of Quick Sort depends heavily on selection of


(a) No of input (b)Arrangements of elements in array (c) size of elements
(d) pivot elements

8. Master’s theorem is used for?


(a) solving recurrences (b) solving iterative relations (c) analyzing loops
(d) calculating the time complexity of any code

9. How many cases are there under Master’s theorem?


(a) 2 (b) 3 (c) 4 (d) 5

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

13. Recursion is a method in which the solution of a problem depends on ____________


(a) Larger instances of different problems (b) Larger instances of the same problem
(c) Smaller instances of the same problem (d) Smaller instances of different problems

14. Which of the following problems can’t be solved using recursion?


(a) Factorial of a number (b) Nth fibonacci number (c) Length of a string
(d) Problems without base case

15. Bucket sort is most efficient in the case when __________


(a) the input is non uniformly distributed (b) the input is uniformly distributed
(c) the input is randomly distributed (d) the input range is large
P
BAHRIA UNIVERSITY (KARACHI CAMPUS)
MIDTERM EXAMINATION – Spring 2023
DESIGN & ANALYSIS OF ALGORITHMS CSC-321

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: _________

Question#2 (Marks 5: CLO2)


a) Explain Hashing, with given data 15, 17, 8, 23, 3, 5 and tablesize is 7. Also explain
collision resolution use quadratic probing and separate chain for given
data. (3)
b) Explain bucket sort and explain by sorting given list of data
List: 7, 9, 16, 18, 2, 15, 3, 19, 25, 21, 13, 5 (2)
Question#3 (Marks 7: CLO4)
a) Analyze the following functions to give Big O time complexity using substitution
method: (4)
int mystery(int n)
{
int answer;
if (n > 0)
{
answer =5*(mystery(n-1)+ 3);
return answer;
}
else
return mystery2(n/2);

}
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);

return answer1+ answer2;


}
else
return fun2(n);

}
int fun2(int m)
{
int x=0
for(int k=m;k>=1;k--)
{
x++
}
return x;
}

Question#4 (Marks 3: CLO3)

Write down the pseudo-code of a hash function that converts string to integer and apply
squaring method to result.

You might also like