18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Lecture 13 - dynamic programming applications<br />

Next: Lecture 14 - data Up: No Title Previous: Lecture 12 - introduction<br />

Lecture 13 - dynamic programming<br />

applications<br />

Listen To Part 13-1<br />

16.3-5 Give an algorithm to find the longest montonically increasing sequence in a sequence of n<br />

numbers.<br />

Build an example first: (5, 2, 8, 7, 1, 6, 4)<br />

Ask yourself what would you like to know about the first n-1 elements to tell you the answer for the<br />

entire sequence?<br />

1. <strong>The</strong> length of the longest sequence in . (seems obvious)<br />

2. <strong>The</strong> length of the longest sequence will extend! (not as obvious - this is the idea!)<br />

Let be the length of the longest sequence ending with the ith character:<br />

How do we compute i?<br />

sequence 5 2 8 7 3 1 6 4<br />

1 1 2 2 2 1 3 3<br />

To find the longest sequence - we know it ends somewhere, so Length =<br />

Listen To Part 14-5<br />

file:///E|/LEC/LECTUR16/NODE13.HTM (1 of 7) [19/1/2003 1:35:01]<br />

<strong>The</strong> Principle of Optimality

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!