0% found this document useful (0 votes)
3 views

problem set-2

The document contains practice problems for the MA252 Design and Analysis of Algorithms course. It includes tasks such as finding the median of two sorted arrays, implementing a queue using stacks, and solving dynamic programming problems related to subsequences and box stacking. Additionally, it addresses calculating the edit distance between two strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

problem set-2

The document contains practice problems for the MA252 Design and Analysis of Algorithms course. It includes tasks such as finding the median of two sorted arrays, implementing a queue using stacks, and solving dynamic programming problems related to subsequences and box stacking. Additionally, it addresses calculating the edit distance between two strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

MA252 Design and Analysis of Algorithms

Practice problems - Set 2

1. Let X[1:n] and Y[1:n] be two arrays, each containing n numbers already in
sorted order. Give an O(log n)- time algorithm to nd the median of all 2n
elements in arrays X and Y. Assume that all 2n numbers are distinct.

2. Show how to implement a queue with two ordinary stacks so that the amortized cost
of each ENQUEUE and each DEQUEUE operation is O(1).

3. Solve the following problems using dynamic programming:

3.1. Given a sequence of ``n’’ real numbers A(1) ... A(n), determine a contiguous
subsequence A(i) ... A(j) for which the sum of elements in the subsequence is
maximized.

3.2. Given a sequence of n real numbers A(1) ... A(n), determine a subsequence
(not necessarily contiguous) of maximum length in which the values in the
subsequence form a strictly increasing sequence.

3.3. You are given a set of n types of rectangular 3-D boxes, where the i^th box
has height h(i), width w(i) and depth d(i) (all real numbers). You want to create a
stack of boxes which is as tall as possible, but you can only stack a box on top of
another box if the dimensions of the 2-D base of the lower box are each strictly
larger than those of the 2-D base of the higher box. Of course, you can rotate a
box so that any side functions as its base. It is also allowable to use multiple
instances of the same type of box.

3.4. Given two text strings A of length n and B of length m, you want to
transform A into B with a minimum number of operations of the following types:
delete a character from A, insert a character into A, or change some character in A
into a new character. The minimal number of such operations required to
transform A into B is called the edit distance between A and B.
fi

You might also like