# 
problems 

1 
Your favorite sawmill charges by the length to cut a piece of lumber.
(For example, to cut a 7 foot piece at any point costs 7 cents.)
 You bring in a 29 foot board and want it cut at points
4, 14, 19, and 27 feet from the left end.
In what order should the mill cut the wood in order to
minimize your cost?
Use dynamic programming principles to solve this problem.
Example:
To cut the board in 1, 2, 3, 4 order it will cost
29+25+15+10=79 cents.
 Develop and analyze (asymptotic time and space) an
algorithm to solve the previous problem for any length
of lumber and number of cuts.

2 
Consider the function:
f(1) = 1 
f(n) =
∑_{i=1 to n1}
( i f(i) ), for n > 1

 Give a recursive algorithm which,
given n, calculates f(n).
 Give and solve a recurrence, as a function of n,
for the number of scalar multiplications required by your
algorithm from part (a).
 Give a dynamic programming algorithm which,
given n, calculates f(n).
 Find, as a function of n, the number of scalar
multiplication operations required by your algorithm
from part (c).
 Give an algorithm which, given n,
calculates f(n) using only a linear number
of scalar multiplications (this includes
multiplications and divisions).
Hint: First find a closed form for the value of
f(n).

3 
Find an optimal binary search tree for the probabilities
p_{1} = p_{2} =
p_{3} = p_{4} =
p_{5} = 0.05
q_{0}=0.0, q_{1}=0.05,
q_{2}=0.10, q_{3}=0.15,
q_{4}=0.20, q_{5}=0.25

4 
Let T be a complete binary tree with
n = 2^{k}1 nodes.
The nodes are numbered in level order with the root labelled 1,
its two children labelled 2 and 3, etc.
Let T_{i} be the subtree whose root is node i,
and so T_{1} = T.
Every node i has a value VAL[i] which can be positive
or negative or zero.
We define WT(i) to be the weight of subtree i,
given by the sum of all values of the nodes in T_{i}.
The problem is to find the maximum weight of all subtrees of T.
 Give a recurrence for WT(i).
 Give a divideandconquer algorithm that finds the
maximum WT(i) given the array VAL.
 What are the space and time complexities of your D&C algorithm?
 Give a dynamic programming algorithm that finds the
maximum WT(i) given the array VAL.
 What are the space and time complexities of your dynamic programming algorithm?

5 
DPV Exercise 6.4 on page 178
You are given a string of n characters s[1...n],
which you believe to be a corrupted text document in which all
punctuation has vanished (so that it looks something like
"itwasthebestoftimes...").
You wish to reconstruct the document using a dictionary, which
is available in the form of a Boolean function dict(*)
such that, for any string w, dict(w) has
value 1 if w is a valid word, and has value 0 otherwise.
 Give a dynamic programming algorithm that determines
whether the string s[*] can be reconstituted
as a sequence of valid words.
The running time should be at most O(n^{2}),
assuming that each call to dict takes unit time.
 In the event that the string is valid, make your algorithm
output the corresponding sequence of words.

6 
Design an algorithm to determine the number of different ways
there are to give x cents in change using any numbers
of pennies, nickels, dimes, quarters, and halfdollars.
For example, there are six ways to give 17 cents change:
a dime, a nickel, and two pennies;
a dime and seven pennies;
three nickels and two pennies;
two nickels and seven pennies;
one nickel and 12 pennies; and 17 pennies.

7 
Design an algorithm to determine the number of different ways
there are to give x cents in change from a fixed set of coins
consisting of n_{1} pennies,
n_{2} nickels,
n_{3} dimes,
n_{4} quarters, and
n_{5} halfdollars.

8 
Design an efficient algorithm to determine the number of different
sequences there are to give x cents in change
from a fixed set of coins as in Problem 2.
Here, however, the order of giving coins makes a difference.
For example, there are only two ways to give 6 cents change
when order is not important:
six pennies; or one penny and one nickel.
In contrast,
there are three sequences (where order does matter)
of giving 6 cents in change:
PPPPPP, or PN, or NP,
where P is a penny and N is a nickel.

9 
Design an efficient algorithm to determine the fewest number of coins
with which one can make change from a fixed set of coins.
The numbers of coins are as in Problem 2.
Also as in Problem 2, an answer may not exist.
In that case, your algorithm should return 1.

10 
Consider the recurrence b_{n} = 3.7b_{n1}  2.8b_{n2},
with boundary conditions b_{1} = 1.2, b_{2} = 2.1.
 Describe an efficient algorithm that calculates the value of b_{n},
where the measure of efficiency is the number of multiplications performed
 Determine the number of multiplications used by your algorithm to
calculate the value of b_{50}
