Problem

Time and space complexity of dynamic programming. Our dynamic programming algorithm for co...

Time and space complexity of dynamic programming. Our dynamic programming algorithm for computing the edit distance between strings of length m and n creates a table of size n × m and therefore needs O (mn) time and space. In practice, it will run out of space long before it runs out of time. How can this space requirement be reduced?

(a) Show that if we just want to compute the value of the edit distance (rather than the optimal sequence of edits), then only O (n) space is

needed, because only a small portion of the table needs to be maintained at any given time.


(b) Now suppose that we also want the optimal sequence of edits. As we saw earlier, this problem can be recast in terms of a corresponding grid-shaped dag, in which the goal is to find the optimal path from node (0, 0) to node (n, m). It will be convenient to work with this formulation, and while we’re talking about convenience, we might as well also assume that m is a power of 2.

Let’s start with a small addition to the edit distance algorithm that will turn out to be very useful. The optimal path in the dag must pass through an intermediate node (k, m/2) for some k; show how the algorithm can be modified to also return this value k.


(c) Now consider a recursive scheme:

procedure find-path((0, 0) → (n, m))compute the value k abovefind-path((0, 0) → (k, m/2))find-path((k, m/2) → (n, m))concatenate these two paths, with k in the middle

Show that this scheme can be made to run in O (mn) time and O (n) space.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 6
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT