Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Question # 1

Tom and Jerry find boxes of diamonds. The boxes arranged in a line, each containing random number of
diamonds. Tom and Jerry can see how many diamonds are in each box and they both get a turn in which
they can pick a box from one of the ends of the line. The winner is the player who has a maximum
number of diamonds at the end. The objective is to maximize the number of diamonds collected.

a) Design a memoized recursive algorithm assuming they both play smartly. What will be time and
space complexity of your algorithm?

b) Design a greedy approach to this problem. And prove the correctness of your approach.

Question # 2

Consider we have n benches of different capacities (one seater, two seater, three seater and
so on). These benches are labeled from 1 to n. Labeling is done randomly, this means, the
bench labeled 1 can have seating capacity 5 while labeled 2 may have capacity one. You are
not allowed to rearrange/change the bench label. Your aim is to place these benches in the
row-first order starting from the bench labeled 1 in a classroom of fixed width and infinite
length. Furthermore, you are required to keep one seat space between the benches placed in
a row. Your objective is to neatly place the benches per row by reducing the number of spaces
at the end of rows.
For example, consider the sequence of benches < 5, 3, 5, 8, 4, 4, 7 > which needs to places in a
classroom with a width wise seating capacity of 15. Then optimal arrangement will be:
row1: 5_3_5 row2: 8_4 row3: 4_7
row1 has no space at the end while row2 and row3 have 2 and 3 respectively.

a) Design a greedy approach to this problem and prove the correctness of your approach
in both algorithms.

b) Consider Student-A uses sum of the spaces at the end of rows to calculate the quality of
the solution. Whereas Student-B uses sum of the cube of the space count at the end of
each row. For the above example, the metric of Student-A will generate 0 + 2 + 3 = 5
while, Student-B’s will generate 03 + 23 + 33 = 36. Which one do you think is a better
metric. Justify your answer with an example.
Question # 3

Suppose you are given a connected graph G with n vertices and m edges. All edge weights are
distinct. Determine a particular edge e is contained in MST of G. Mention the running time of
your solution

Question # 4

Given a graph G = (V, E), will Dijkstra’s algorithm and Bellman-Ford algorithm produce different
or same shortest path if multiple shortest paths exist? Prove your solution by
example/induction.

Question # 5

Consider NUCES has expanded by building 6 campuses. NUCES HQ wants to lease phone lines
to connect them up with each other; and the phone company charges different amounts of
money to connect different pairs of campuses. Figure 1 shows different campuses labelled as
1,2,3, so on. 0 labelled node is HQ. The edges between the campuses show the cost of
connecting them. Come up with a strategy to connect all your campuses with a minimum total
cost.

You might also like