0% found this document useful (0 votes)
88 views15 pages

DAA Question Bank - Unit1&2

DAA

Uploaded by

Kalaivanan K
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)
88 views15 pages

DAA Question Bank - Unit1&2

DAA

Uploaded by

Kalaivanan K
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

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

Tircuchirappalli

FACULTY OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

QUESTION BANK

DEGREE / BRANCH : B.Tech/CSE

YEAR / Semester : II/IV

SUBJECT Code/Title : 21CSC204J – Design and Analysis of Algorithms

Regulation : 2021

Academic Year : 2024-2025


QUESTION BANK

SUBJECT : 21CSC204J – Design and Analysis of Algorithms


SEM/ YEAR : IV/ II
Course Outcomes

CO 1. Apply efficient algorithms to reduce space and time complexity of both recurrent and non-
recurrent relations
CO 2. Solve problems using divide and conquer approaches
CO 3. Apply greedy and dynamic programming types techniques to solve polynomial time
problems.
CO 4. Create exponential problems using backtracking and branch and bound approaches.
CO 5. Interpret various approximation algorithms and interpret solutions to evaluate P type, NP
Type, NPC, NP Hard problems

UNIT I
Introduction-Algorithm Design - Fundamentals of Algorithms- Correctness of algorithm - Time complexity
analysis - Insertion sort-Line count - Operation count - Algorithm Design paradigms - Designing an
algorithm and its analysis – Best- Worst- and Average case - Asymptotic notations Based on growth
functions – O – O – Ө – ω - Ω - Mathematical analysis - Induction, Recurrence relations -Solution of
recurrence relations - Substitution method - Solution of recurrence relations - Recursion tree - Solution of
recurrence relations - examples.
PART-A (Multiple Choice Questions)
Q. Questions Course Competence
Outcome BT Level
No
1 ______is the first step in solving the problem
A. Understanding the Problem
B. Identify the Problem CO 1 BT 1
C. Evaluate the Solution
D. Coding the Problem
Answer: - B
2 While solving the problem with computer the most difficult step is
______.
A. describing the problem CO 1 BT 1
B. finding out the cost of the software
C. writing the computer instructions
D. testing the solution
Answer:- C
3 The correctness and appropriateness of ___________solution can be
checked very easily.
A. algorithmic solution CO 1 BT 1
B. heuristic solution
C. random solution
D. Brute force Solution
Answer:- A
4 When determining the efficiency of algorithm, the space factor is
measured by
A. Counting the maximum memory needed by the algorithm CO 1 BT 1
B. Counting the minimum memory needed by the algorithm
C. Counting the average memory needed by the algorithm
D. Counting the maximum disk space needed by the algorithm
Answer: - A
5 The hierarchy of operations is denoted as _____________.
I. +, - II. Power III. *, / IV. \, MOD
A. I, II, III, IV CO 1 BT 1
B. II, IV, III, I
C. IV, I, III, II
D. II, III, IV, I
Answer:- B
6 Which of the following is not O(n2)?
A. (15) * n2
B. n1.98 CO 1 BT 1
C. n3/(sqrt(n))
D. (20) * n2
Answer: C
7 Which of the following sorting algorithms does not have a worst case
running time O(n2)?
A. Insertion Sort CO 1 BT 1
B. Merge Sort
C. Quick Sort
D. Bubble Sort
Answer: B
8 Number of comparisons required to search an element X=18 in the list
A=[5,44,89,22,18,9,15,8] using linear search.
A. 3 CO 1 BT 1
B. 0
C. 4
D. 5
Answer:D
9 What is the time complexity for the following C module? Assume that
n>0;
int module(int n) CO 1 BT 1
{
if( n== 1)
return 1;
else
return (n+module(n-1));
}
A. O(n)
B. O(log n)
C. O(n2)
D. O(n!)
Answer: A
10 What is the time complexity of following code:
int a = 0, i = N;
while (i > 0) CO 1 BT 1
{
a += i;
i /= 2;
}
A. O(N)
B. O(Sqrt(N))
C. O(N / 2)
D. O(log N)
ANSWER: D
11 Two main measures for the efficiency of an algorithm are
A. Processor and memory
B. Complexity and capacity CO 1 BT 1
C. Time and space
D. Data and space
Answer: - C
12 What does the algorithmic analysis count?
A. The number of arithmetic and the operations that are required to run the
program CO 1 BT 1
B. The number of lines required by the program
C. The number of seconds required by the program to execute
D. None of these
Answer:- A
13 An algorithm that indicates the amount of temporary storage required
for running the algorithm, i.e., the amount of memory needed by the
algorithm to run to completion is termed as_____. CO 1 BT 1
A. Big Theta θ (f)
B. Space complexity
C. Big Oh O (f)
D. Time Complexity
Answer:- B
14 Consider a linked list of n elements. What is the time taken to insert an
element after an element pointed by some pointer?
A. (1) CO 1 BT 1
B. (n)
C. (log2 n)
D. (n log2 n)
Answer:- A
15 If the address of A[1][1] and A[2][1] are 1000 and 1010 respectively
and each element occupies 2 bytes then the array has been stored in
order. CO 1 BT 1
A. row major
B. column major
C. matrix major
D. none of these
Answer A
16 The time factor when determining the efficiency of algorithm is
measured by
A. Counting microseconds CO 1 BT 1
B. Counting the number of key operations
C. Counting the number of statements
D. Counting the kilobytes of algorithm
Answer:- B
17 Time complexities of four algorithms are given. Which should execute
the slowest for large values of N?
A. (n log n) CO 1 BT 1
B. O(n)
C. O(log n)
D. O(n2)
Answer:-B
18 Which one of the following is the tightest upper bound that represents
the number of swaps required to sort n number using selection sort?
A. (log n) CO 1 BT 1
B. O(n)
C. (n log n)
D. O(n2)
Answer:-B
19 How many comparisons are needed for linear Search array when
elements are in order in best case?
A. 1 CO 1 BT 1
B. n
C. n+1
D. n-1
Answer A
20 The complexity of Bubble sort algorithm is__________
A. O(n)
B. O(log n) CO 1 BT 1
C. O(n2)
D. O(n log n)
Answer : C
21 Which of the given options provides the increasing order of asymptotic
complexity of functions f1, f2, f3 and f4?
f1(n) = 2^n CO 1 BT 1
f2(n) = n^(3/2)
f3(n) = nLogn
f4(n) = n^(Logn)
A. f3, f2, f1, f4
B. f2, f3, f1, f4
C. f2, f3, f4, f1
D. f3, f2, f4, f1
Answer : D
22 How much number of comparisons is required in insertion sort
to sort a file if the file is sorted in reverse order?
A. N2 CO 1 BT 1
B. N
C. N-1
D. N/2
Answer:A
23 The worst-case occur in linear search algorithm when …….
A. Item is somewhere in the middle of the array
B. Item is not in the array at all CO 1 BT 1
C. Item is the last element in the array
D. Item is the last element in the array or item is not there at all
Answer D
24 What is the time complexity of fun()?
int fun(int n)
{ CO 1 BT 1
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
A. Theta (n)
B. Theta (n^2)
C. Theta (n*Logn)
D. Theta (nLognLogn)
Answer : B
25 The time complexity of the following C function is (assume n > 0 )
int recursive (int n)
{ CO 1 BT 1
if (n == 1)
return (1);
else
return (recursive (n-1) + recursive (n-1));
}
A. O(n)
B. O(nlogn)
C. O(n2)
D. O(2n)
Answer:D
26 A function in which f(n) is Ω(g(n)), if there exist positive values k and c
such that f(n)>=c*g(n), for all n>=k. This notation defines a lower
bound for a function f(n): CO 1 BT 1
A. Big Omega Ω (f)
B. Big Theta θ (f)
C. Big Oh O (f)
D. Big Alpha α (f)
Answer A
27 The concept of order Big O is important because_______
A. It can be used to decide the best algorithm that solves a given problem
B. It determines the maximum size of a problem that can be solved in a CO 1 BT 1
given
amount of time
C. It is the lower bound of the growth rate of algorithm
D. Both A and B
Answer A
28 The upper bound on the time complexity of the nondeterministic
sorting algorithm is
A. O(n) CO 1 BT 1
B. O(n log n)
C. O(1)
D. O( log n)
Answer: A
29 In the analysis of algorithms, what plays an important role?
A. Text Analysis
B. Growth factor CO 1 BT 1
C. Time
D. Space
Answer: B
30 Which one of the following correctly determines the solution of the
recurrence relation given below with T(1) = 1 and T(n)= 2T(n/4) + n1/2
A. O(n2) CO 1 BT 1
B. O(n)
C. O(n1/2 log n)
D. O(log n)
Answer C
31 What is the time complexity of recursive function given below:
T(n)= 4T(n/2) + n2
A. O(n2) CO 1 BT 1
B. O(n)
C. O(n2 log n)
D. O(n log n)
Answer C
32 Which of the following represents the worst-case time complexity?
a) Best-case complexity
b) Average-case complexity CO1,L2
c) Upper bound complexity
d) Lower bound complexity
33 Which asymptotic notation provides the tightest bound for an
algorithm's running time?
a) O (Big-O)
CO1,L2
b) Ω (Big-Omega)
c) Θ (Theta)
) o (Small-O)
34 Analyse the time and space complexity for the code given below.
#include <stdio.h>
void Test(int n) {
int a = n * 5;
printf("Result: %d\n", a);
}
int main() {
Test(10); CO1,L2
return 0;
}
A) a) O(n) and O(n)
B) b) O(n) and O(1)
C) c) O(1) and O(1)
d) O(1) and O(n)
35 Analyse the time complexity of ‘Print’ function.
#include <stdio.h>
void print(int n) {
for (int i = 1; i <= n; i *= 2) {
printf("%d ", i);
} CO1,L2
}
a) O(1)
b) O(n)
c)O(nlog n)
d)O(log n)
36 Calculate the time complexity of the given algori
void Sample(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j *= 2) {
printf("(%d, %d) ", i, j);
}
CO1,L2
printf("\n");
}
}
a) O(n)
b) O(n log n)
c) O(1)
O( log n)
PART B (4 Marks)

1 Explain Analysis Framework of algorithm with Suitable Example. CO1 BT 2

2 Discuss in detail about all the asymptotic notations with Example. CO1 BT 2

3 Explain the Recursive algorithm for Computing Tower of Hanoi and CO1 BT 3
analyse its Time Complexity using Backward Substitution method.
4 Solve the following recurrence relations. CO1 BT 3
X(n)=x(n-1) + 5 for n>1, x(1) = 0
5 Write the algorithm for finding element uniqueness and analyse its CO1 BT 3
efficiency.
6 Solve by Mathematical Induction. CO1 BT 3

7 Find the Time complexity of the following function. CO1 BT 2


Void Function(int n)
{
int count = 0;
for (int i=n/2; i< =n; i++)
for (int j=1; j<=n; j=2*j)
for(int k=1; k<=n; k=k*2)
count++;
}
8 Solve T(n)=T(n/4)+T(n/2)+n2 using recurrence tree method. CO1 BT 3

9 Give the non-recursive algorithm for finding the value of the largest CO1 BT 2
element in a list of n numbers and analyse its efficiency
10 Solve the following recurrence relations. CO1 BT 3
I. x(n)=x(n-1)+5 for n>1, x(1)=0
II. x(n)=3x(n-1)for n>1, x(1)=4
III. x(n)=x(n/2)+n for n>1, x(1)=1 (solve for n=2k)
11 Given the following time complexities, arrange them in increasing
order of growth rate.
O(nlogn),O(n!),O(1),O(logn),O(n2),O(2n)
12 Find the time complexity of the following algorithm and justify your
answer.
void Test(int n) {
int count = 0;
for (int i = 1; i <= n; i *= 2) {
for (int j = 0; j < n; j++) {
count++;
} }}
13 Solve the recurrence relation using the substitution method:
T(n)=2T(n/2)+O(n)

PART C (12 Marks)


1 What is algorithm? Define the characteristics of the algorithm. CO1 BT 2
Differentiate pseudocode and algorithm.
Illustrate insertion sort algorithm and discuss its time complexity.
2 Write the algorithm for matrix multiplication and analyse its efficiency. CO1 BT 2
3 Solve the recurrence relation T(n)=7T(n/2)+18n2 and find the time CO1 BT 3
complexity.
4 Design a recursive algorithm to compute the factorial function F(n) =n! for CO1 BT 2
an arbitrary non negative integer n and set up a recurrence equation for the
number of multiplication made by the algorithm.
5 Write a recursive algorithm to find the number of binary digits in the CO1 BT 2
binary representation of a positive decimal integer and analyze its
efficiency
6 (a) Solve the following recurrence relation using the Recursion Tree CO1 BT3
Method:
T(n)=2T(n/2) +O(n) (6 Marks)
(b) Solve the recurrence relation T(n)=7T(n/2) +18n2 and find the
time complexity. (6 Marks)
7 [OR] CO1 BT3
UNIT II
Introduction-Divide and Conquer - Maximum Subarray Problem - Binary Search - Complexity of binary search Merge
sort - Time complexity analysis -Quick sort and its Time complexity analysis Best case- Worst case- Average case
analysis - Strassen's Matrix multiplication and its recurrence relation - Time complexity analysis of Merge sort -
Largest sub-array sum - Time complexity analysis of Largest subarray sum - Master Theorem Proof - Master theorem
examples - Finding Maximum and Minimum in an array - Time complexity analysis-Examples - Algorithm for finding
closest pair problem – Convex Hull problem

PART-A (Multiple Choice Questions)


Q. Questions Course Competence
Outcome BT Level
No
1 Partition and exchange sort is____________
A. quick sort
B. tree sort CO 2 BT 1
C. heap sort
D. bubble sort
ANSWER: A
2 Which of the following is not the required condition for binary search
algorithm?
A. The list must be sorted CO 2 BT 1
B. There should be the direct access to the middle element in any sub list
C. There must be mechanism to delete and/or insert elements in list.
D. Number values should only be present
ANSWER: C
3 Which of the following sorting algorithm is of divide and conquer
type?
A. Bubble sort CO 2 BT 1
B. Insertion sort
C. Merge sort
D. Selection sort
ANSWER: C
4 ____________order is the best possible for array sorting algorithm
which sorts n item.
A. O (n logn) CO 2 BT 1
B. O (n2)
C. O (n+logn)
D. O (logn)
ANSWER: C
5 The complexity of merge sort algorithm is __________
A. O (n)
B. O (logn) CO 2 BT 1
C. O (n2)
D. O (n logn)
ANSWER: D
6 Binary search algorithm cannot be applied to ________
A. sorted linked list
B. sorted binary trees CO 2 BT 1
C. sorted linear array
D. pointer array
ANSWER: A
7 Which of the following is not a limitation of binary search algorithm?
A. must use a sorted array
B. requirement of sorted array is expensive when a lot of insertion and CO 2 BT 1
deletions are needed
C. there must be a mechanism to access middle element directly
D. binary search algorithm is not efficient when the data elements more
than 1500.
ANSWER: D
8 Which of the following is an external sorting?
A. Insertion Sort
B. Bubble Sort CO 2 BT 1
C. Merge Sort
D. Tree Sort
ANSWER: B
9 Merging k sorted tables into a single sorted table is called _______
A. k way merging
B. k th merge CO 2 BT 1
C. k+1 merge
D. k-1 merge
ANSWER: A
10 The operation that combines the element is of A and B in a single
sorted list C with n=r+s element is called ________
A. Inserting CO 2 BT 1
B. Mixing
C. Merging
D. Sharing
ANSWER: C
11 What is the worst case time complexity of a quick sort
algorithm?
a) O(N) CO 2 BT 1
b) O(N log N)
c) O(N2)
d) O(log N)
ANSWER: C
12 What is the average running time of a quick sort algorithm?
a) O(N2)
b) O(N) CO 2 BT 1
c) O(N log N)
d) O(log N)
ANSWER: C
13 How many sub arrays does the quick sort algorithm divide the
entire array into?
a) one CO 2 BT 1
b) two
c) three
d) four
ANSWER: B
14 Quick sort is a __________
a) greedy algorithm
b) divide and conquer algorithm CO 2 BT 1
c) dynamic programming algorithm
d) backtracking algorithm
ANSWER: B
15 Which one of the following sorting algorithm is best suited to
sort an array of 1 million elements?
a) Bubble sort CO 2 BT 1
b) Insertion sort
c) Merge sort
d) Quick sort
ANSWER: D
16 Strassen’s algorithm is a/an_____________ algorithm.
a) Non- recursive
b) Recursive CO 2 BT 1
c) Approximation
d) Accurate
ANSWER: B
17 What is the running time of naïve matrix multiplication
algorithm?
a) O(n2.81) CO 2 BT 1
b) O(n4)
c) O(n)
d) O(n3)
ANSWER: D
18 ___________ is a method of constructing a smallest polygon out
of n given points.
a) closest pair problem CO 2 BT 1
b) quick hull problem
c) path compression
d) union-by-rank
ANSWER: B
19 What is the other name for quick hull problem?
a) convex hull
b) concave hull CO 2 BT 1
c) closest pair
d) path compression
ANSWER: A
20 Master’s theorem is used for?
a) solving recurrences
b) solving iterative relations CO 2 BT 1
c) analysing loops
d) calculating the time complexity of any code
ANSWER: A
21 What is the result of the recurrences which fall under first case
of Master’s theorem (let the recurrence be given by
T(n)=aT(n/b)+f(n) and f(n)=nc? CO 2 BT 1
a) T(n) = O(n^logba)
b) T(n) = O(nc log n)
c) T(n) = O(f(n))
d) T(n) = O(n2)
ANSWER: A
22 Under what case of Master’s theorem will the recurrence
relation of merge sort fall?
a) 1 CO 2 BT 1
b) 2
c) 3
d) It cannot be solved using master’s theorem
ANSWER: B
23 Find the maximum sub-array sum for the given elements.
{2, -1, 3, -4, 1, -2, -1, 5, -4}
a) 3 CO 2 BT 1
b) 5
c) 8
d) 6
ANSWER: B
24 What is the time complexity of the divide and conquer
algorithm used to find the maximum sub-array sum?
a) O(n) CO 2 BT 1
b) O(logn)
c) O(nlogn)
d) O(n2)
ANSWER: C
25 What is the advantage of recursive approach than an iterative
approach?
a) Consumes less memory CO 2 BT 1
b) Less code and easy to implement
c) Consumes more memory
d) More code has to be written
ANSWER: B
26 In the recurrence relation T(n) = 2T(n/2) + O(n), what is the time
complexity?
a) O(n²) CO 2 BT 1
b) O(n log n)
c) O(n)
d) O(log n)
27 How many recursive calls does Merge Sort make per level of
recursion?
a) 1 CO 2 BT 1
b) 2
c) 3
d) 4
28 Which of the following algorithms uses a partitioning technique?
a) Merge Sort
b) Quick Sort CO 2 BT 1
c) Heap Sort
d) Bucket Sort
29 Which of the following recurrence relations represents Strassen’s
Matrix Multiplication?
a) T(n) = 8T(n/2) + O(n²) CO 2 BT 1
b) T(n) = 7T(n/2) + O(n²)
c) T(n) = 4T(n/2) + O(n²)
d) T(n) = 6T(n/2) + O(n²)
30 Given a sorted array {2, 3, 5, 7, 11, 13, 17, 19}, how
many comparisons are needed to find 17 using Binary Search?
A) 2 CO 2 BT 1
B) 3
C) 4
D) 5
PART B (4 Marks)
1 Formulate the Binary Search Algorithm and analyze its worst, best and CO2 BT 3
average case time complexity.
2 Consider that there were two list of sorted array. Propose the algorithm for CO2 BT 3
combining the elements of two arrays into single array in sorted order.
3 Solve the maximum sub array sum in a pictorial way by drawing tree. CO2 BT 3

4 Write an algorithm for finding maximum sub array sum and analyse its CO2 BT 3
efficiency.
5 Describe the control abstraction for Divide and Conquer strategy. CO2 BT 2

6 Devise an algorithm for generating n’ terms of Fibonacci series and CO2 BT 2


analyse its efficiency.
7 Write short notes on Master theorem usage in the time complexity analysis. CO2 BT 2

8 Develop the algorithmic steps to find the maximum and minimum element CO2 BT 3
in the given list and analyse its efficiency.
9 Given an unsorted array [15, 3, 8, 5, 2, 1], show the step-by-step execution CO2 BT 3
of Merge Sort, including recursive calls and merging steps.
10 You are given an integer array A of size N. Your task is to find the CO2 BT 3
contiguous subarray (containing at least one element) that has the
maximum sum and return this maximum sum. For example, given
the input array:

A=[−2,1,−3,4,−1,2,1,−5,4]
11 Use the Master Theorem to find the time complexity of the recurrence: CO2 BT 3
T(n)=4T(n/2)+O(n2)
PART C (12 Marks)

1 Consider example of your choice and find the Closest pair among the CO2 BT 2
considered number. Devise an algorithm and analyze its efficiency.
2 Explain the Convex Hull problem and analyze the time complexity of the CO2 BT 2
algorithm.
3 Write an algorithm for binary search and analyse its time complexity with CO2 BT 2
suitable examples.
4 Write an algorithm for quick sort and analyse its time complexity with CO2 BT 2
suitable examples.
5 Write an algorithm for merge sort and analyse its time complexity with CO2 BT 3
suitable examples 6 5 12 10 9 1 8 6
6 Solve the given matric multiplication with Strassen’s matrix multiplication CO2 BT 3
and analyse its time complexities.

A= .
B=

8 You are working as a software developer at a startup that specializes CO2 BT 3


in optimizing sorting algorithms for large datasets. Your manager
has given you a set of unsorted numbers and asked you to sort them
using the QuickSort algorithm.
i). Manually apply QuickSort step-by-step, choosing the first
element as the pivot. (4 Marks)
ii). Write the final sorted order of the numbers with suitable
algorithm (4 Marks).
iii)Time Complexity: Analyze the time complexity for this particular
input. Is it the best-case, average-case, or worst-case scenario?
Justify your answer. (4 Marks)
Given Unsorted Array:
35, 12,42,8,51,26,17,21
9 (i) Solve the following recurrence relation by applying the Master CO2 BT 3
Theorem:
T(n)=3T(n/4)+O(n2) (4 Marks)
(ii) Given two matrices of size 2x2 implement Strassen’s Matrix
Multiplication algorithm step by step. Analyze the computational
advantages and limitations of using Strassen’s method compared to the
standard matrix multiplication approach (8
Marks)

Note:

1. BT Level – Blooms Taxonomy Level

2. CO – Course Outcomes

BT1 – Remember BT2 – Understand BT3 – Apply BT4 – Analyze BT5 – Evaluate BT6 – Create

You might also like