You are on page 1of 12

School of Computer Science and Engineering

Winter Semester 2022-2023 Continuous Assessment Test – II


SLOT :G1+TG1
Programme Name & Branch : B.Tech - CSE
Course Name & code : BCSE204L – Design and Analysis of Algorithms
Class Number (s) :
Exam Duration : 90 Min. Maximum Marks: 50

ANSWER ALL THE QUESTIONS(5X10=50 Marks)

Q.N Modul Max


Question
o e Mark
1 What is the difference between FIFOBB and LIFOBB? Solve
the Knapsack Problem using LIFOBB, Assume knapsack
capacity is W =8. Show how stack is used for node creation
in the state space tree using variable tuple representation.

2 10
Item Profit Weight
1 3 3
2 4 2
3 5 3
4 6 5
2 Solve the Job Sequencing Problem using FIFOBB. Select
optimal subset J with an optimal penalty for the following
data. What will be the penalty corresponding to the optimal
solution? Discuss how queue is used in the state space tree
using fixed tuple representation.

Job Penalty Deadline Execution 2 10


Time Time
1 40 2 1
2 10 4 2
3 60 2 2
4 30 3 1

3 Using a string matching algorithm which uses hashing


functions, how many spurious hits does the algorithm (with
3 10
q to be 11) encounter in the Text =ABCBBCABCBA when
looking for the pattern Pattern = CBA?
4 John is driving his electric car from Vellore and has planned
to visit tourist places around Vellore. Due to limitations of
charging on the road, he needs to find the shortest path from
Vellore to all other chosen tourist places, through. The road
map with tourist places between Vellore and tourist places
is given as a weighted directed graph G = (V,E) along with
weights w (representing the distance). Find the shortest
path from source vertex A (i.e., Vellore) to all other vertices
(i.e., to all other visiting place around Vellore) using suitable
algorithm for the given graph. Write the pseudocode of your
algorithm.
4 10

5 In a wireless network, node S wishes to send some packets to


node T, but S and T are not directly connected. We need to find
the path that can transfer the most packets from node S to node T,
while satisfying the capacity constraints of the edges. The
network is represented as a graph, G = (V,E). Design an algorithm
with complexity O(VE2), and find the maximum number of packets
transfered from node S to node T using the given graph.

4 10
School of Computer Science and Engineering
Fall Semester 2022-2022 Continuous Assessment Test – II
SLOT :G1+TG1
Programme Name & Branch : B.Tech - CSE
Course Name & code : BCSE204L – Design and Analysis of Algorithms
Class Number (s) :
Exam Duration : 90 Min. Maximum Marks: 50

ANSWER ALL THE QUESTIONS (5X10=50 Marks)

Q.N Modul Max


Question CO BL
o e Mark
1 What is the difference between FIFOBB and LIFOBB? Solve
the Knapsack Problem using LIFOBB, Assume knapsack
capacity is W =8. Show how stack is used for node creation
in the state space tree using variable tuple representation.

2 10 CO2 BL6
Item Profit Weight
1 3 3
2 4 2
3 5 3
4 6 5
2 Solve the Job Sequencing Problem using FIFOBB. Select
optimal subset J with an optimal penalty for the following
data. What will be the penalty corresponding to the optimal
solution? Discuss how queue is used in the state space tree
using fixed tuple representation.

Job Penalty Deadline Execution 2 10 CO2 BL6


Time Time
1 40 2 1
2 10 4 2
3 60 2 2
4 30 3 1

3 Using a string-matching algorithm which uses hashing


functions, how many spurious hits does the algorithm (with
3 10 CO3 BL6
q to be 11) encounter in the Text =ABCBBCABCBA when
looking for the pattern Pattern = CBA?
4 John is driving his electric car from Vellore and has planned 4 10 C03 BL6
to visit tourist places around Vellore. Due to limitations of
charging on the road, he needs to find the shortest path from
Vellore to all other chosen tourist places, though. The road
map with tourist places between Vellore and tourist places
is given as a weighted directed graph G = (V,E) along with
weights w (representing the distance). Find the shortest
path from source vertex A (i.e., Vellore) to all other vertices
(i.e., to all other visiting place around Vellore) using suitable
algorithm for the given graph. Write the pseudocode of your
algorithm.

5 In a wireless network, node S wishes to send some packets to


node T, but S and T are not directly connected. We need to find
the path that can transfer the most packets from node S to node T,
while satisfying the capacity constraints of the edges. The
network is represented as a graph, G = (V,E). Design an algorithm
with complexity O(VE2), and find the maximum number of packets
transfered from node S to node T using the given graph.

4 10 C03 BL6
School of Computer Science and Engineering
Fall Semester 2022-2022 Continuous Assessment Test – II
SLOT :G1+TG1
Programme Name & Branch : B.Tech - CSE
Course Name & code : BCSE204L – Design and Analysis of Algorithms
Class Number (s) :
Exam Duration : 90 Min. Maximum Marks: 50

ANSWER ALL THE QUESTIONS (5X10=50 Marks)

Modul Max
Q.No Question CO BL
e Mark
1 What is the difference between FIFOBB and LIFOBB? Solve the 2 10 CO2 BL6
Knapsack Problem using LIFOBB, assume knapsack capacity is
W =8. Show how stack is used for node creation in the state
space tree using variable tuple representation.

Item Profit Weight


1 3 3
2 4 2
3 5 3
4 6 5
Ans:
Job 1, Job 2, Job 3 are selected with profit 12

Node 1: U =3+4 +5=−12, C ^ = -12+(8-(3+2+3))6/5 = -12,


Node 2, 3, 4, 5 created
Node 5: U =−6, U > Upper, Node is killed
Node 4: U¿−( 5+6 ) =−11, U> Upper, Node is killed
Node 3: U =−( 4 +5 )=−9, U > Upper, Node is killed
Node 2: U =−( 3+4 +5 )=−12, C ^ = -12+(8-(3+2+3))6/5 = -12,
Node 6, 7, 8 created
Node 8: U =−( 4 +5 )=−9, U> Upper, Node is killed
Node 7: U =−( 4 +6 )=−10, U > Upper, Node is killed
Node 6: U =−( 3+4 +5 )=−12, C ^ = -12+(8-(3+2+3))6/5 = -12,
Node 9, 10 created
Node 10: Total weight with J1, J2, J4 > W, Node is killed
Node 9: U =−( 3+4 +5 )=−12, C ^ = -12+(8-(3+2+3))6/5 = -12,
Node 11 created
Node 11: Total weight with J1, J2, J3, J4 > W, Node is killed
J1,J2,J3 are selected with maximum profit of -12
2 Solve the Job Sequencing Problem using FIFOBB. Select 2 10 CO2 BL6
optimal subset J with an optimal penalty for the following
data. What will be the penalty corresponding to the optimal
solution? Discuss how queue is used in the state space tree
using fixed tuple representation.

Job Penalty Deadline Execution


Time Time
1 40 2 1
2 10 4 2
3 60 2 2
4 30 3 1
Ans:
Job selected are {0,0,1,1} with maximum profit: 90

^ , U = 40+10+60+30 = 140, Node 2, 3 created


Node 1: C=0
^
Node 2: C=4 0, U = 40+10+60+30 = 140, Node 4, 5 created
^ , U = 10+60+30 = 100, Node 6, 7 created,
Node 3: C=0
Upper updated with U
^
Node 4: C=40+ 10=50 , U = 60+30 = 90, Node 8, 9 created,
Upper updated with U
^
Node 5: C=4 0, U = 40+60+30 = 130, Node killed since
U>Upper
^
Node 6: C=1 0, U = 40+60+30 = 100, Node killed since
U>Upper
^ , U = 60+30 = 90, Node 10, 11 created.
Node 7: C=0
^
Node 8: C=10+10+60=11 ^ Upper
0, Node killed since C>
^
Node 9: C=40+ 10=5 0 , U = 40+10+30 = 80, Node 12, 13
created, Upper updated with U
Node 10: C=6^ 0 , U = 60+30 = 90, Node killed since
U>Upper
Node 11: Deadline = 4 < Total execution time {1+2+2},
Node killed
^
Node 12: C=40+ 10+30=8 0, U = 40+10+30 = 80, No more
job, node is killed
^
Node 13: C=40+ 10=5 0 , U = 40+10 = 50

^
Minimum Penality is C=50 , so maximum profit of 90 with jobs
{0,0,1,1,}
3 Using a string-matching algorithm which uses hashing
functions, how many spurious hits does the algorithm (with q
to be 11) encounter in the Text =ABCBBCABCBA when
looking for the pattern Pattern = CBA?

Ans
H(X) = {P[2]*102+P[1]*101+P[0]}mod 11.
Assign value A=1, B=2, C=3
H(P) = (300+200+1)mod 11 =321=2.

Text: ABCBBCABCBA
3 10 CO3 BL6
ABC = 100+20+3 = 123
BCB = ((123)mod100)*10+2=232 mod 11 = 1
CBB = ((232)mod100)*10+2=322 mod 11 = 3
BBC = ((322)mod100)*10+3=223 mod 11 = 3
BCA = ((223)mod100)*10+1=231 mod 11 = 0
CAB = ((231)mod100)*10+2=312 mod 11 = 4
ABC = ((312)mod100)*10+3=123 mod 11 = 2 – spurious hit
BCB = ((123)mod100)*10+2=232 mod 11 = 1
CBA = ((232)mod100)*10+1=321 mod 11 = 2
Total number of spurious hits is 2 for the patten CBA.

4 John is driving his electric car from Vellore and has planned to 4 10 C03 BL6
visit tourist places around Vellore. Due to limitations of
charging on the road, he needs to find the shortest path from
Vellore to all other chosen tourist places, though. The road
map with tourist places between Vellore and tourist places is
given as a weighted directed graph G = (V,E) along with
weights w (representing the distance). Find the shortest path
from source vertex A (i.e., Vellore) to all other vertices (i.e., to
all other visiting place around Vellore) using suitable
algorithm for the given graph. Write the pseudocode of your
algorithm.

Ans:
Shortest path From A to B : ACB: Cost is 3
Shortest path From A to C: AC: Cost is 6
Shortest path From A to D: AD: Cost is 2
Shortest path From A to E: ACE: Cost is 4
Shortest path From A to F: ACBF: Cost is -1
Shortest path From A to G: ADG: Cost is 8

5 In a wireless network, node S wishes to send some packets to node 4 10 C03 BL6
T, but S and T are not directly connected. We need to find the path
that can transfer the most packets from node S to node T, while
satisfying the capacity constraints of the edges. The network is
represented as a graph, G = (V,E). Design an algorithm with
complexity O(VE2), and find the maximum number of packets
transfered from node S to node T using the given graph.
Ans:
• SADT Max flow is =6

• SACFT Max flow is = 2

• SADFT Max flow is =4


• SABCFT Max flow is =10

• SABECFT Max flow is = 4


• SBET= Max flow is 20

Maximum Flow = 46

You might also like