0% found this document useful (0 votes)
9 views

Set b Daa Answer Key1

The document outlines the structure and content of a test for the course 'Design and Analysis of Algorithms' at SRM Institute of Science and Technology for the academic year 2023-24. It includes a course articulation matrix, various questions categorized into parts A, B, and C, covering topics such as greedy algorithms, dynamic programming, and backtracking. The test is designed to assess students' understanding and application of algorithmic concepts with a total duration of 1 hour and 40 minutes, and a maximum score of 50 marks.

Uploaded by

Sreeramkumar VR
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)
9 views

Set b Daa Answer Key1

The document outlines the structure and content of a test for the course 'Design and Analysis of Algorithms' at SRM Institute of Science and Technology for the academic year 2023-24. It includes a course articulation matrix, various questions categorized into parts A, B, and C, covering topics such as greedy algorithms, dynamic programming, and backtracking. The test is designed to assess students' understanding and application of algorithmic concepts with a total duration of 1 hour and 40 minutes, and a maximum score of 50 marks.

Uploaded by

Sreeramkumar VR
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/ 13

SRM Institute of Science and Technology

College of Engineering and Technology


School of Computing SET B
SRM Nagar, Kattankulathur – 603203, Chengalpattu District, Tamilnadu
Academic Year: 2023-24 (EVEN)

Test: CLA-2 T3 Date: 30/04/2024


Course Code & Title: 21CSC204J Design and Analysis of Algorithms Duration: 1 hour 40 min
Year & Sem: II Year / IV Sem Max. Marks: 50

Course Articulation Matrix:


Course Outcome PO PO PO PO PO PO PO PO PO PO PO PO Program Specific
1 2 3 4 5 6 7 8 9 10 11 12 Outcomes
PSO- PSO- PSO-
1 2 3
CO1 2 1 2 1 - - - - 3 - 3 3 1 -
CO2 2 1 2 1 - - - - 3 - 3 3 1 -
CO3 2 1 2 1 - - - - 3 - 3 3 1 -
2 1 2 1 - - - - 3 - 3 3 1 -
CO4

CO5 2 1 2 1 - - - - 3 - 3 3 1 -

Part – A (8 x 1 = 8 Marks) Instructions: Answer all


Q. Question Marks BL C PO PI
No O Code
1 Which strategy is used in the greedy approach for solving the 1 L1 3 2 2.5.2
Knapsack problem?
a) Selecting items randomly
b) Choosing items with the highest value-to-weight ratio
c) Prioritizing items based on their weight only
d) Selecting items with the lowest value-to-weight ratio
2 What is the primary advantage of solving the optimal binary 1 L1 3 2 2.5.2
search tree problem using dynamic programming?
a) It guarantees the shortest tree height
b) It ensures the optimal placement of nodes
c) It reduces the overall memory usage
d) It optimizes search operations by reducing the
number of comparisons
3 The minimum number of scalar multiplications required for 1 L2 3 2 2.6.3
multiplying three matrices A, B, and C, where the
dimensions are A(10x20), B(20x30), and C(30x40) is
________.
a) 2400
b) 3000
c) 3600
d) 4800

Note: As there is a typo error in this question, provide a


grace mark to the students.

4 What is the time complexity of the backtracking approach to 1 L2 4 2 2.6.3


solve the N Queens problem for an N x N chessboard?
a) O(N!)
b) O(2^N)
c) O(N^2)
d) O(N)
5 What does the Floyd Warshall algorithm compute in a graph? 1 L1 4 2 2.5.2
a) shortest path for each pair of vertices
b) Minimum spanning tree
c) Longest path
d) Topological sort
6 In a complete graph with n vertices, how many Hamiltonian 1 L2 4 2 2.1.2
circuits exist?
a) n
b) (n-1)!
c) n!
d) 2^n

7 In the Rabin-Karp algorithm, which factor can affect the 1 L2 5 2 2.5.2


accuracy of pattern matching?
a) Size of the text
b) Length of the pattern
c) Choice of hash function
d) Number of characters in the alphabet
8 Consider the problem of finding the shortest path in a 1 L1 5 2 2.5.2
weighted graph. Is this problem NP-hard or NP-
complete?
a) NP-hard
b) NP-complete
c) Neither NP-hard nor NP-complete
d) Both NP-hard and NP-complete
SRM Institute of Science and Technology SET B
College of Engineering and Technology
School of Computing
SRM Nagar, Kattankulathur – 603203, Chengalpattu District, Tamilnadu
Academic Year: 2023-24 (EVEN)

Test: CLA-2 T3 Date: 30/04/2024


Course Code & Title: 21CSC204J Design and Analysis of Algorithms Duration: 1 hour 40 min
Year & Sem: II Year / IV Sem Max. Marks: 50

Course Articulation Matrix:


Course Outcome PO PO PO PO PO PO PO PO PO PO PO PO Program Specific
1 2 3 4 5 6 7 8 9 10 11 12 Outcomes
PSO- PSO- PSO-
1 2 3
CO1 2 1 2 1 - - - - 3 - 3 3 1 -
CO2 2 1 2 1 - - - - 3 - 3 3 1 -
CO3 2 1 2 1 - - - - 3 - 3 3 1 -
2 1 2 1 - - - - 3 - 3 3 1 -
CO4

CO5 2 1 2 1 - - - - 3 - 3 3 1 -

Part – B (3 x 5 = 15 Marks) Instructions: Answer all


Q. Question Marks BL CO PO PI
No Code
9 Given three matrices A, B, and C with dimensions as follows: 5 L2 3 2 2.4.1
Matrix A: 2 x 3
Matrix B: 3 x 4
Matrix C: 4 x 2
Using dynamic programming, determine the minimum number
of scalar multiplications required to multiply these matrices
together efficiently. Describe the steps and discuss the time
complexity of your algorithm.

Solution: 4 Marks
Time Complexity: O(n3) (1 Mark)
10 Consider the following tree structure. Implement Breadth-First 5 L3 4 2 2.1.2
Search (BFS) and Depth-First Search (DFS) algorithms to
explore this tree. Using appropriate data structures, provide the
order in which the nodes are visited for both BFS and DFS.
Demonstrate the traversal step-by-step. (5 Marks)
11 In the bustling kingdom of Eldoria, there exists a prestigious 5 L3 5 2 2.4.1
guild of skilled adventurers who seek employment
opportunities in various quests and missions. Each adventurer
possesses unique abilities and strengths, making them suitable
candidates for different quests. However, the guild master
faces the challenge of efficiently selecting the most qualified
adventurers for each quest. Write a pseudocode that employs a
randomized approach to select the most qualified adventurers
for a given quest, ensuring fairness and impartiality in the
selection process. Also, provide the time complexity for your
algorithm.
Pseudocode: 4 Marks
function selectAdventurers(adventurers, questRequirements):
selectedAdventurers = []
while (questRequirements not met):
randomly select an adventurer from the pool
if (adventurer meets questRequirements):
add adventurer to selectedAdventurers
return selectedAdventurers

Time Complexity: O(Cn ln n) (1 Mark)

Part – C
(3 x 9 = 27 Marks)
12. Suppose you are tasked with designing an efficient 9 L3 3 2 3.6.2
A transportation network at minimum cost for a city with
multiple neighbourhoods. Each neighborhood needs to be
connected to every other neighbourhood in the city to ensure
seamless travel for residents and visitors. However, building
roads between all pairs of neighbourhoods would be costly and
unnecessary. Your goal is to devise a strategy to connect the
neighbourhoods using the minimum number of roads while
ensuring that every neighbourhood remains accessible from
any other. Using a greedy approach, describe how you would
go about selecting the roads to build to connect the
neighbourhoods efficiently. Provide a detailed explanation of
your strategy and justify your decisions at each step to achieve
the most cost-effective transportation network for the city.
Additionally, provide a pseudocode and time complexity
outlining the steps of your greedy approach to constructing the
transportation network.

Expected Answer: Marks can be awarded for both Prim's and


Kruskal's algorithms. Students must have solved correctly
using any one algorithm, providing proper pseudocode and
mentioning the time complexity.

Example: 4 Marks
Pseudocode: marks
Time complexity: 1 Mark

Prims algorithm:

Total Cost = 5 + 3 + 3 + 4 + 4 = 19

Pseudocode:
Prim (G, start):
Initialize an empty set MST to store the minimum
spanning tree
Initialize a priority queue PQ to store vertices and
their weights
Add start vertex to MST and PQ with weight 0
while PQ is not empty:
u = extract_min(PQ)
Add u to MST
for each neighbor v of u:
if v is not in MST:
Add v to PQ with weight of edge (u, v)
return MST

Kruskal Algorithm

Total Cost = 3 + 3 + 4 + 4 + 5 = 19

Pseudocode:
Kruskal(G):
Sort the edges of G in non-decreasing order of their
weights
Initialize an empty set MST to store the minimum
spanning tree
for each vertex v in G:
Make a set containing only v
for each edge (u, v) in sorted edges:
if find(u) is not equal to find(v): // check if adding
the edge creates a cycle
Add (u, v) to MST
Union the sets containing u and v
return MST

Time Complexity: O(n 3)

(or)
12. Imagine you are a puzzle enthusiast who loves solving word 9 L3 3 2 3.6.2
B puzzles. You have two sets of word tiles, each containing a
sequence of letters arranged in a particular order. Your goal is
to find the longest sequence of letters that appears in the same
order in both sets of word tiles. However, you can only remove
letters from the tiles, not rearrange them, to form the common
sequence.
Example Problem: 5 Marks
Consider two sets of word tiles:
Set A: {M, Z, J, A, W, X, U}
Set B: {X, M, J, Y, A, U, Z}
Determine the length of the longest sequence of letters that
appears in the same order in both sets of word tiles using a
dynamic Programming Approach. Provide the pseudocode for
the same.
Solution:

Pseudocode: 4 Marks
If(a[i]=b[j])
LCS [I,j] = 1+LCS[i-1, j-1]
Else
LCS[I,j] = max ( LCS [i-1,j], LCS [i, j-1])

13. Imagine you are embarking on an adventure through a magical 9 L3 4 2 2.1.2


A forest filled with treasure chest of variable sizes. The treasure
chest contains a collection of coins, with each coin having a
different value. Your goal is to find the combination of coins
from the treasure chest that adds up to a specific target value,
allowing you to unlock a hidden path deeper into the forest.
However, you can only select coins from the treasure chest
without exceeding the target value. Determine the combination
of coins from the treasure chests that add up to the target value
with state space tree and pseudocode using the Backtracking
Approach.
Using the example treasure chest and target value:
Treasure Chest: {3, 5, 6, 7}
Your target value is 15.

Solution: 5 Marks
Pseudocode: 4 Marks

(or)
13. Alice is preparing for a wilderness expedition where she needs 9 L3 4 2 3.6.2
B to carry a limited weight of supplies in her backpack. She has
a list of items with their weights and values. However, her
backpack has a strict weight limit. Alice wants to maximize the
total value of the items she carries while ensuring she doesn't
exceed the weight limit of her backpack. Derive the following
example and provide the pseudocode for the same.

Items Tent Sleeping Portable First Aid Kit


Bag Stove
Profit $10 $12 $20 $25
Weight 2 kg 3 kg 4 kg 5 kg
Backpack weight limit: 12 kg
Example: 5 marks

Pseudocode: 4 Marks

Algorithm BB_KNAPSACK(cp, cw, k)


// Description : Solve knapsack problem using branch
and bound
// Input:
cp: Current profit, initially 0
cw: Current weight, initially 0
k: Index of item being processed, initially 1

// Output:
fp: Final profit
Fw: Final weight
X: Solution tuple

cp ← 0
cw ← 0
k←1

if (cw + w[k] ≤ M) then


Y[k] ← 1
if (k < n) then
BB_KNAPSACK(cp + p[k], cw + w[k], k + 1)
end
if (cp + p[k] > fp) && (k == n) then
fp ← cp + c[k]
fw ← cw + w[k]
X←Y
end
end

if BOUND(cp, cw, k) ≥ fp then


Y[k] ← 0
if (k < n) then
BB_KNAPSACK(cp, cw, k + 1)
end
if( cp>fp ) && ( k == n ) then
fp ← cp
fw ← cw
X←Y
end
end
Upper bound is computed as follow :
Function BOUND(cp, cw, k)

b ← cp
c ← cw
for i ← k + 1 to n do
if (c + w[i] ≤ M) then
c ← c + w[i]
b ← b – p[i]
end
end
return b

14. Considering the complexities inherent in sorting diverse 9 L3 5 2 2.4.1


A datasets efficiently, explain what strategic approach can be
employed to ensure that quicksort maintains an average-case
time complexity of O(nlogn) when dealing with large datasets.
Provide a pseudocode for the approach and solve the sample
dataset given below.
The dataset consists of the following elements:
[10, 25, 30, 45, 50, 65, 70, 85].

Example: 4 Marks
Use Randomized quick sort to sort the array.
Sorted Array: 10, 25, 30, 45, 50, 65, 70, 85

Pseudocode: 5 Marks
function randomizedQuicksort(array):
if length(array) <= 1:
return array

pivotIndex = randomIndex(length(array)) // Choose a


random index as the pivot
pivot = array[pivotIndex]

// Partition the array around the pivot


lessThanPivot = []
equalToPivot = []
greaterThanPivot = []
for element in array:
if element < pivot:
append element to lessThanPivot
else if element == pivot:
append element to equalToPivot
else:
append element to greaterThanPivot

// Recursively sort the subarrays


sortedLess = randomizedQuicksort(lessThanPivot)
sortedGreater =
randomizedQuicksort(greaterThanPivot)

// Concatenate the sorted subarrays with the pivot


return concatenate (sortedLess, equalToPivot,
sortedGreater)

(or)
14. Write an algorithmic approach to solve the Traveling Salesman 9 L3 5 2 2.1.1
B Problem (TSP), a well-known NP-complete problem, using
dynamic programming. Analyze the time complexity of your
proposed solution and compare it with the Brute Force
algorithm.

Algorithm: Traveling-Salesman-Problem (5 Marks)


C ({1}, 1) = 0
for s = 2 to n do
for all subsets S є {1, 2, 3, … , n} of size s and containing 1
C (S, 1) = ∞
for all j є S and j ≠ 1
C (S, j) = min {C (S – {j}, i) + d(i, j) for i є S and i ≠ j}
Return minj C ({1, 2, 3, …, n}, j) + d(j, i)

Time Complexity Analysis: (1 Mark)


There are 2^n subsets of cities, and for each subset, we iterate
over all cities, resulting in a time complexity of O(n^2 * 2^n).
Each DP state takes O(n) time to compute.
Overall, the time complexity of the dynamic programming
solution is O(n^2 * 2^n).

Comparison with Brute Force: (3 Marks)


Brute Force: The brute force approach generates all
permutations of cities and calculates the total distance for each
permutation. The time complexity of brute force is O(n!),
significantly worse than dynamic programming for larger n.
Dynamic Programming: The dynamic programming approach
optimally solves the problem in O(n^2 * 2^n) time, making it
much more efficient than brute force for larger instances of the
problem.
In summary, while the dynamic programming solution for the
Traveling Salesman Problem has a high time complexity, it is
much more efficient than the brute force approach for larger
instances of the problem due to its polynomial time
complexity.

*Program Indicators are available separately for Computer Science and Engineering in AICTE
examination reforms policy.

Course Outcome (CO) and Bloom’s Level (BL) Coverage in Questions


CO COVERAGE IN % BL Coverage in %
34 34
32
36 36

29

BL1 BL2 BL3


CO1 CO2 CO3 CO4 CO5

Approved by the Audit Professor/Course Coordinator

You might also like