DAA. .
DAA. .
Reg. No.
Amrita Vishwa Vidyapeetham
Amrita School of Engineering, Bengaluru
Depart1ment of CSE
Periodical Test - 2, March 2018
15CSE211 Design and Analysis of Algorithms Max.: 50 Marks
Sem /Branch: IV CSE A and B Sections Duration: 2 Hrs.
Answer all the questions.
Part A 5 x3 =15 Marks
1
In the single-processor scheduling problem, we are given aset of njobs. Each job i has adeadline
di.Afeasibie schedule is apermutation of the jobs such that when the jobs are performed in that
order, every job is finished before its deadline. The greedy algorithm for single-processor
scheduling selects the job with the earliest deadline first. Show that if a feasible schedule exists,
then the schedule produced by this greedy algorithm is feasible. What is the optimal solution?
Job Deadline in Profit per
Profit
Minutes Minute
A 19 2 19
B 27 1 27
25 25
D 30 30
2. Write the binary encoding of the messages using the table: i) BCDA i) BADBB
A BC D
Check whether the given encoding scheme leads to unambiguous decoding or not for any arbitrary
message. Justify.
3. Compare and Contrast Divide &Conquer method, Dynamic Programming and Greedy method.
Mention the suitable examples for each method.
4. Suggest a technique which could be the best to solve for each of the following problems and
justify your answer.
i) Given a set of non-negative integers, and a value sum, determine if there is a subset of the
given set with sum equal to given sum. Examples: set [ ]= {3, 34, 4, 12, 5. 2}, sum = 9
Output: True, There is a subset (4,5) with sum 9.
i) Given the capacity of Compact Disc as 650 MB and a bunch of songs of varying sizes
(anown sizes), store maximum songs on the Compact Disc until it is full.
ii) Hunt the way out for thegiven maze. If noway out possible then report that as an error.
S. Complete the Sudoku 4x4 and show the application of backtracking in the solution.
3
1
2
Page 1 of 2
035
(35 M a r k s )
Part B
(10M)
6
Consider the codes shown below:
D E
Character B
1 0 ||10
001011
000
Encoding 16 18
10 23
Frequency in Thousands 25 the cost.
form. Find
binary tree
101100010002
2 2
4
4 7
3
5 4
6
a set ots
should take from
deciding which subset
of items you
problem inyolves the size of the items. or th:
8. Knapsack perhaps the worth of the items, an item or
optimize some value: we can either take lea
if you want to In this problem, we will assume that a fixed size. and o:
worth to size. knapsack has
ratio of
fractional part of an
item). Our
hold at most 25 units of spa:
it (we cannot take a the selected items. Our knapsack can items and o
optimize the worth of worth. Show the steps for the selection of
and their
Here is the list of items (8 M
on the given problem.
Size Worth
Item
22 12
Laptop
10 9
Play Station
Textbook 9
Basketball 6
distinct
a) A chain of 6 matrices A through F is to be multiplied. Find the number of
9.
parenthesized.
ways by which the matrices can be fully
required to multiply the following char
b) Find the number of scalar multiplications
Show the best order of muti
matrices along with the solution for the sub-problems.
them.
Matrix Name A1 A2 A3 A4
Order 2X5 5 X33X6 6X4
036
31 MAY 2024
Reg. No:
Amrita V:slhwa Vidyapeetham
Anrita School of Computing,
B.Tech. Semester Examinaticn -Bengaluru
May 2024
Fourtii & Fifth Semester
Common to CSE & AIE
21AIE212/19CSE302 Design and Analysis of Algorithms
ation Three hours Maximum: 100 Marks
CO Course Outcomes
Evaluate the correctness and analyze
Col complexity offalgorithms solve classical
Understand and implement varicus techniques and
CO2 problems
algorithmic design
for real world problems by identifying, applying and implementing
Design solutions
CO3 appropriate designtechniques.
solutions for real world
CO4 Design problem by napping to classical problemscomplexity
the
COS Ånalyze impact of various implementation choices on the algorithm
4 Given a single sequence of numbers, design an algorithm to find the longest [C04]
monotonically increasing subsequence. For example, in the sequence 23143758 BTL3]
the longest monotonically increasing subsequence is 23458. What is the running
time of your algorithm? Show the working of the algorithm for this example.
5 Given a one-dimensional array that contain both positive and negative integers,
find the sum of contiguous subarray of numbers which has the largest sum based
on the following approaches.
The problem described above when solved using divide andconquer approach [C02
has a complexity of O(nlogn). Find the maximum sum using this mentioned BTL3]
approach for the aray (-2, -3, 4, -1, -2, 1, 5, -3}.
b. Avariation of the algorithm proposed by Kadane (given below) claims that the [COs]
above problem can be solved using dynamic programming approach with a BTL4]
worst-case complexity of 0(2). Verify the algorithm to get the result obtained
in the subdivision (a). Kadane's algorithm is as follows:
Initialize:
max so far =0
max _ending here =0
Loop for each element of the array
Step 1 max ending here = max ending here +t ali)
Step 2if(max_ending here <0)
max_ending here =0
Step 3 if(max so far < max_ending
here)
max so far = max ending here
return max so far
S
Çolve thesudok1, given in Figure l using backtracking approach. Show the [CO1
Figure l
(3)
Rabin- -Karp algor1thm find the number of valid and spurious hits while
[CO2]
(BTL3]
Using the pattern P
matching
"MIPS" in the text
OREMPSUMDOLORSITAMET»
[COs] (3]
whether
the following are true or false. Justify your answer. (BTL4J
with edge costs that are all positive and distinct. Let Tbe ai
G,
graph
tree for this instance. Now Suppose we replace each edge
cost C by its
newinstance of the problem with the same graph
spanning
different
but depth-first
the order of the vertices encountered ona breadth-first and (BTL3]
Report
picking the vertices
starting from vertex A in Figure 2. Break all ties by
thus
searches
typeof edges
order, Draw the resultant trees highlighting the
alphabetical
in
o b t a i n e d .
34
24
22
35
25 19
16 39
65
23
4
12
30
Figure 2 [CO2]
components. Identify the
connected
example graph
which has two reason for your chninn
C Give an from your graph. State the
separation edges and vertices [5
[CO2]
gure 3.
the graph Ggiven in
[BTL3]
topological sorting for
Perform
Figure 3
Page 3 cf 4
16
163
The initial Dmatris and the computed D'matrix for a4-noded digraph is pivcn (Cy.
in Figure 4. Using these matrices, compute the final ' using Floyd-Warshail's (i
algorithm. How many entrics change when compared with D?
3 0 0 3 15
12 5 D ' |l6 0 12
DO
4 7 0
l2 -4 4
Figre 4
12
Figure 5
11. Define the follo wing class of problems and give one example for each category. [CO1]
P, NP, NP Complete [BTLI|
S
Page 4 of4
170