CSE221 - Fall22 Final Solution
CSE221 - Fall22 Final Solution
Graph Theory
Set A
#, Co Question Marks
3 As we all know, the Spanish National Football Team is notorious for their passing 6
football, especially their back passes. After their disastrous 2022 World Cup campaign,
The King of Spain made you the coach and declared that no back passes are allowed
on the field from now on till Spain scores 2 goals, that is, Simon the goalkeeper can only
pass to the defenders Rodri and Cesar, but Rodri and Cesar cannot pass the ball back
to Simon. Also, every pass now comes with a cost– and the more cost players
accumulate, the angrier the King gets. These are the costs of the passes:
Passes Cost
Simon → Rodri 2
Simon → Cesar 4
Rodri → Cesar 1
Rodri → Pedri 7
Cesar → Gavi 3
Gavi → Pedri 2
Pedri → Morata 1
Gavi → Morata 5
a. Find the lowest cost for the ball to reach every player starting from Simon, using
any algorithm you find useful. The King will need to see every single step of the
algorithm, or he will not believe you and fire you on the spot.
Solution:
Rubrics:
a. Wrote something: 0-1.5 (depending on how wrong they are)
2. Wrote Dijkstra but did not show steps or wrote the algorithm in any way: 2.5
3. Wrote Dijkstra, showed steps, but made a mistake somewhere: 5
4. Full correct: 6
Use your best judgment to deliberate 0.5 marks. For example, if someone wrote the
steps for MST, you may give half a mark extra for his or her effort.
3 After scoring 2 goals, Spain changed their strategy and started to back pass again 4
incorporating 2 more players, the master of dark arts Busquets and the young sensation
Ansu Fati. Now they are no longer concerned with the cost of the pass as well. These
are the passes for the new strategy:
Passes
Simon → Rodri
Simon → Cesar
Rodri → Busquets
Rodri → Pedri
Cesar → Rodri
Busquets → Gavi
Busquets → Pedri
Gavi → Cesar
Gavi → Pedri
Gavi → Fati
Fati → Morata
Pedri → Fati
Morata → Pedri
b. Now using a suitable algorithm find out the largest group of players who can
pass the ball among themselves. For example, one such group can be (Fati,
Morata, Pedri) where Morata can pass to Pedri, Pedri can pass to Fati and Fati
can pass to Morata. It is important to keep in mind that the king will be observing
every step of the algorithm. Any discrepancies can lead you to lose your job.
Solution:
Set B
#, Co Question Marks
3 As we all know, the Spanish National Football Team is notorious for their passing 6
football, especially their back passes. After their disastrous 2022 World Cup campaign,
The King of Spain made you the coach and declared that no back passes are allowed
on the field from now on till Spain scores 2 goals, that is, Simon the goalkeeper can only
pass to the defenders Rodri and Cesar, but Rodri and Cesar cannot pass the ball back
to Simon. Also, every pass now comes with a cost– and the more cost players
accumulate, the angrier the King gets. These are the costs of the passes:
Passes Cost
Simon → Cesar 2
Simon → Rodri 4
Cesar → Rodri 1
Rodri → Pedri 3
Cesar → Gavi 7
Pedri → Gavi 2
Pedri → Morata 5
Gavi → Morata 1
a. Find the lowest cost for the ball to reach every player starting from Simon, using
any algorithm you find useful. The King will need to see every single step of the
algorithm, or he will not believe you and fire you on the spot.
Solution:
Shortest path algorithm with source: Simon, using the path
Simon(0) → Cesar(2) → Rodri(3) → Pedri(6) → Gavi(8) → Morata(9)
Rubrics:
5. Wrote something: 0-1.5 (depending on how wrong they are)
6. Wrote Dijkstra but did not show steps or wrote the algorithm in any way: 2.5
7. Wrote Dijkstra, showed steps, but made a mistake somewhere: 4
8. Full correct: 6
Use your best judgment to deliberate 0.5 marks. For example, if someone wrote the
steps for MST, you may give half a mark extra for his or her effort.
3 After scoring 2 goals, Spain changed their strategy and started to back pass again 4
incorporating 2 more players, the master of dark arts Busquets and the young sensation
Ansu Fati. Now they are no longer concerned with the cost of the pass as well. These
are the passes for the new strategy:
Passes
Simon → Cesar
Simon → Rodri
Cesar → Gavi
Gavi → Busquets
Gavi → Pedri
Gavi → Fati
Busquets → Pedri
Busquets → Rodri
Pedri → Morata
Fati → Pedri
Morata → Fati
Rodri → Pedri
Rodri → Cesar
b. Now using a suitable algorithm find out the largest group of players who will pass
the ball among themselves. For example, one such group can be (Fati, Morata,
Pedri) where Morata can pass to Fati, Fati can pass to Pedri and Pedri can pass
the ball back to Morata. It is important to keep in mind that the king will be
observing every step of the algorithm. Any discrepancies can lead you to lose
your job.
Solution:
Rubr for gt q1: wrote something: 0.5-1 depending on how wrong they are, wrote
ics Dijkstra but did not show steps: 2, wrote dijskta, showed steps but made a
mistake somewhere: 3, full correct: 4. 0.5 marks can be deliberated based
on your best judgment.
Same goes for SCC.
Greedy
Set A
#, Co Question Marks
1 (a) You are given the following table containing symbols and their frequencies: [4+
1]+[
Symbol A B C D + 3+2
]
Frequency 40 10 20 15 15
i) Build the Huffman code tree and find the codeword for each character.
ii) Decode 100010111001010 using the Huffman code that you generated.
(b) You are given the arrival and departure times of eight trains for a railway
platform, each in the following format: [𝑎𝑟𝑟𝑖𝑣𝑎𝑙 𝑡𝑖𝑚𝑒, 𝑑𝑒𝑝𝑎𝑟𝑡𝑢𝑟𝑒 𝑡𝑖𝑚𝑒). Only one
train can use the platform at a time.
Suppose that you have got the following train-use requests for the next day.
{ [8, 13), [6, 9), [11, 14), [2, 7), [1, 7), [12, 20), [7, 13) , [13, 20) }
i) Find the maximum number of trains that can use the platform without any
collision.
ii) Determine the minimum number of platforms necessary to ensure the arrival
and departure of all these trains without collision.
Ans
wers a) Huffman Tree
i)
ii) Decode: BAD+ADA
b) Activity Selection
i) Total 3 activities selected: (2, 7), (8, 13), (13, 20)
ii) the minimum number of platforms needed to ensure the arrival
and departure of all these trains without collision would be 4. A
possible solution can be
3 Full marks
1 (a) You are given the following table containing symbols and their frequencies: [4+
1]+[
Symbol A B C D # 3+2
]
Frequency 35 15 25 10 20
i) Build the Huffman code tree and find the codeword for each character.
ii) Decode 100010111001010 using the Huffman code that you generated.
(b) You are given the arrival and departure times of eight trains for a railway
platform, each in the following format: [𝑎𝑟𝑟𝑖𝑣𝑎𝑙 𝑡𝑖𝑚𝑒, 𝑑𝑒𝑝𝑎𝑟𝑡𝑢𝑟𝑒 𝑡𝑖𝑚𝑒). Only one
train can use the platform at a time.
Suppose that you have got the following train-use requests for the next day.
{ [8, 12), [6, 9), [11, 14), [2, 7), [1, 7), [12, 20), [7, 12) , [13, 19) }
i) Find the maximum number of trains that can use the platform without any
collision by using.
ii) Determine the minimum number of platforms necessary to ensure the arrival
and departure of all these trains without collision.
Ans
wers a) Huffman Tree
i)
ii) Decode: DCCA#B
b) Activity Selection
i) Total 3 activities selected: (2, 7), (8, 13), (13, 19)
ii) the minimum number of platforms needed to ensure the arrival
and departure of all these trains without collision would be 3.
Possible solution can be
Decode: C#CACDC
3 Full marks
Set A
#, Co Question Marks
1 Suppose you went to Miniso to buy a Teddy Bear Plushie (a soft toy or doll) as a gift for 6 +
your younger sister’s birthday. The plushie is 700 BDT. At Miniso, all items are subject to 2 +
a 6% additional VAT charge. 2
You bought one plushie and gave the cashier 750 BDT. The cashier has a huge supply
of 1 taka, 2 taka, and 5 taka coins in the cashbox. You don’t want to carry many coins,
so you asked her to return the change using a minimum number of coins.
(a) Using the Dynamic Programming approach, determine how many coins she
should return in this scenario.
(b) Which coins did you get from the cashier? Show how your table was used to pick
up these coins. You may use arrows and circles to point to the chosen cells.
(c) Suppose you did not apply memoization to find the answer for question (a). What
will be the time complexity of that brute force approach? Explain with proper
reasoning.
(c) The student should show the proper logic on how memoization is superior in the
advantage. Marks can be deliberated based on the examiner’s best judgment.
Set B
#, Co Question Marks
1 A team of two infamous thieves, Denver and Nairobi, planned to rob the famous Louvre 6+2
Museum. Before the scene, they both agreed on the fact that none of them will break + 2
any item as all the items in the Louvre are too precious, and taking a fraction of any item
won’t sell in the black market. If it fits in the bag as a whole, they will take it, otherwise,
leave it as it is.
Both of them arrived at the Louvre with an empty knapsack weighing a total of 8 kg.
Despite the fact that both thieves are experts in their fields, they take slightly different
approaches. Denver believes he will use a Dynamic Programming Approach to rob the
items in the most efficient manner possible. Nairobi, on the other hand, believes that if
she chooses a Greedy Approach, she will make the most money.
Profit ($) 5 9 5 4 6
Weight 3 5 4 1 12
(Kg)
(a) What is the maximum profit Denver can make using his strategy? What items did
he pick up? Show how Denver used the DP table to select these objects. You
may use arrows and circles to point to the chosen cells.
(b) Does Nairobi’s belief remain valid after the robbery? Prove it.
b) For Nairobi:
Objects Jewelry Sculpture Painting Book Mummy
8 Book 1 4
7 Sculpture 5 9
Total Profit: 4 + 9 = 13 $
Even if Nairobi took Jewelry and Sculpture (3 kg + 5 kg = 8 Kg), She couldn’t make
more profit than Denver. In this case, her profit would be 14 $ too.
Rubr For DP problems, usually no partials are assigned. Because error in one cell is
ics propagated through other cells.