You are on page 1of 3

`CSE 2215 DSA - II

Assignment 1
● Answer all the questions.
● The solutions must be handwritten.
● After the completion of the assignment , assign page numbers to every page.
● Scan every page, attach a cover page (with your name and id) and generate a pdf file
● Submit the assignment in the eLMS portal

SN Problem

1 Express the time complexity of Maximum-sum Subarray problem when Brute Force
method is applied to solve it. Explain why the Divide-and-Conquer approach can
improve the complexity.

2 Given an array of integers A = {-2, 3, -2, 4, -1, 2, 1}, find the Maximum-sum continuous
Subarray using divide-and-conquer. You must show the recursion tree and clearly
mention left, right and crossing sum for each tree node.

3 Suppose we have two sorted sub-arrays: L: 1, 5, 8, 9, 10, 15 and R: 4, 6, 7, 11, 13, 14.
Perform the procedure Merge on L and R to find the final sorted array A. Show each
step of your answer and the number of comparisons required in each step.

4 Given the arrival and the departure times (in minutes) of 8 trains for a railway platform,
find out the maximum number of trains that can use that platform without any collision,
using a greedy algorithm. There must exist at least 10 minutes of safety break between
the departure of one train and arrival of the next one.

[1000, 1030], [840, 1030], [850, 1040], [1700, 2000], [800, 835], [1300, 1800], [1500,
1650], [1200, 1380]

Explain your strategy very briefly and show detailed calculations. No need to write
pseudocode.

5 A document to be transmitted over the internet contains the following characters with
their associated frequencies as shown in the following table:

Use Huffman technique to answer the following questions:


i. Build the Huffman code tree for the message and find the codeword for each
character. Encode “stolen” using the codewords.

ii. What is the percentage saving if the data is sent with fixed-length code values
without compression?

6. Given an infinite number of coins with denominations {1,2,3,4,7}, find the minimum
number of coins required to make an amount of 15. You must show your working in a
tabular format. Also state which coins you are using, and how many of them you are
using

7. For the classical Rod cutting problem, design an example case where a greedy
approach fails to find an optimal solution. What are the optimal and the greedy
solutions for your example?

8. Suppose that you are the owner of an Internet service provider company. The
maximum bandwidth capacity that you can supply is max capacity. There are n
customers who are willing to acquire your Internet service. Each customer has two
attributes: the bandwidth Bi that he/she wants, and the payment Pi that he/she will pay
for that. Provide a Dynamic Programming algorithm to find out the maximum total profit
that you can make by providing bandwidths within your max capacity

9. Solve the following instance of the knapsack problem with knapsack capacity 7 for i)
0/1 knapsack problem ii) fractional knapsack problem

10 Add memoization to the algorithm in given figure to get its Dynamic Programming
version. Then calculate CATALAN(3) using the memoized algorithm. You must
demonstrate the recursion-tree generated and the memo.
11 Derive the exact-cost equation (this was done in DSA I too) for the running-time of
the algorithm in given figure, and express it in the big-Oh (O) notation.

You might also like