09.09.2014 Views

algorithms

algorithms

algorithms

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Common subproblems<br />

Finding the right subproblem takes creativity and experimentation. But there are a few<br />

standard choices that seem to arise repeatedly in dynamic programming.<br />

i. The input is x 1 , x 2 , . . . , x n and a subproblem is x 1 , x 2 , . . . , x i .<br />

x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10<br />

The number of subproblems is therefore linear.<br />

ii. The input is x 1 , . . . , x n , and y 1 , . . . , y m . A subproblem is x 1 , . . . , x i and y 1 , . . . , y j .<br />

x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10<br />

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

The number of subproblems is O(mn).<br />

iii. The input is x 1 , . . . , x n and a subproblem is x i , x i+1 , . . . , x j .<br />

x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10<br />

The number of subproblems is O(n 2 ).<br />

iv. The input is a rooted tree. A subproblem is a rooted subtree.<br />

If the tree has n nodes, how many subproblems are there?<br />

We’ve already encountered the first two cases, and the others are coming up shortly.<br />

169

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

Saved successfully!

Ooh no, something went wrong!