0% found this document useful (0 votes)
48 views49 pages

Dynamic Programming in Computer Science

This document presents an overview of dynamic programming and its applications in computer science. It introduces dynamic programming with an example, then provides theoretical background. Several subclasses of dynamic programming problems are covered, including shortest path problems, optimal parenthesization problems, optimal partition problems, optimal matching problems, and hard combinatorial problems. Dynamic programming is described as a technique that breaks problems down into subproblems in a way that avoids redundant computations. It is most applicable when the problem can be expressed as a sequence of decisions across multiple stages.

Uploaded by

y z
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
48 views49 pages

Dynamic Programming in Computer Science

This document presents an overview of dynamic programming and its applications in computer science. It introduces dynamic programming with an example, then provides theoretical background. Several subclasses of dynamic programming problems are covered, including shortest path problems, optimal parenthesization problems, optimal partition problems, optimal matching problems, and hard combinatorial problems. Dynamic programming is described as a technique that breaks problems down into subproblems in a way that avoids redundant computations. It is most applicable when the problem can be expressed as a sequence of decisions across multiple stages.

Uploaded by

y z
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 49

Carnegie Mellon University

Research Showcase @ CMU


Computer Science Department School of Computer Science

1979

Dynamic programming in computer science


Kevin Q. Brown
Carnegie Mellon University

Follow this and additional works at: htp://repository.cmu.edu/compsci

his Technical Report is brought to you for free and open access by the School of Computer Science at Research Showcase @ CMU. It has been
accepted for inclusion in Computer Science Department by an authorized administrator of Research Showcase @ CMU. For more information, please
contact research-showcase@andrew.cmu.edu.
NOTICE WARNING CONCERNING COPYRIGHT RESTRICTIONS:
The copyright law of the United States (title 17, U.S. Code) governs the making
o f photocopies or other reproductions of copyrighted material. Any copying of this
document without permission of its author may be prohibited by law.
CMU-CS-79-106

Dynamic Programming in Computer Science University Libraries


Carnegie Mellon University
Pittsburgh PA 1 5 2 1 3 - 3 8 9 C
K e v i n Q. B r o w n
F e b r u a r y 1979

DEPARTMENT
of
COMPUTER SCIENCE

510.7808
C28R
79-106

Carnegie-Mel Ion University


PAGE I

T a b l e of C o n t e n t s

1. I n t r o d u c t i o n
2. A n Example
3 . B r i e f S u m m a r y of t h e T h e o r y
4 . S i n g l e S o u r c e S h o r t e s t Path Problems
5. Optimal Parenthesization Problems

5.1 O p t i m i z i n g t h e M u l t i p l i c a t i o n of N M a t r i c e s
5.2 C o n t e x t F r e e Language Recognition
5.3 O p t i m a l A l p h a b e t i c E n c o d i n g and Optimal S e a r c h T r e e s
5.4 O p t i m i z i n g t h e S e a r c h f o r N O r d e r Statistics

6. Optimal Partition Problems


7. Optimal Matching Problems
8. ' H a r d ' Combinatorial Problems
9. Conclusion
References
PAGE 1

1. I n t r o d u c t i o n
" D y n a m i c p r o g r a m m i n g is an important t e c h n i q u e f o r t h e s o l u t i o n o f p r o b l e m s
i n v o l v i n g t h e o p t i m i z a t i o n of a s e q u e n c e of d e c i s i o n s . T h e simple i d e a u n d e r l y i n g
t h i s t e c h n i q u e is to r e p r e s e n t the p r o b l e m b y a p r o c e s s w h i c h e v o l v e s f r o m s t a t e
t o s t a t e in r e s p o n s e to d e c i s i o n s . A t y p i c a l o p t i m i z a t i o n p r o b l e m t h e n b e c o m e s
o n e o f g u i d i n g t h e s y s t e m to a terminal s t a t e at minimum c o s t . W h e n t h e c o s t
s t r u c t u r e is a p p r o p r i a t e , t h e d e t e r m i n a t i o n of an optimal p o l i c y ( s e q u e n c e o f
d e c i s i o n s ) m a y b e r e d u c e d to the s o l u t i o n of a functional e q u a t i o n in w h i c h t h e
s t a t e a p p e a r s as an i n d e p e n d e n t v a r i a b l e . " Karp and Held, 1 9 6 7 .

Dynamic programming ( D P ) is o n e of s e v e r a l problem solving methods u s e d in computer


science (and operations research). O n e of t h e d i s t i n g u i s h i n g f e a t u r e s of a D P a l g o r i t h m is t h e
way it d e c o m p o s e s a p r o b l e m into s u b p r o b l e m s . A p r o b l e m of s i z e N ( t h a t is, N stages)
t y p i c a l l y d e c o m p o s e s t o s e v e r a l p r o b l e m s of s i z e N - 1, e a c h of w h i c h d e c o m p o s e s t o s e v e r a l
p r o b l e m s o f s i z e N - 2, e t c T o a v o i d r e c o m p u t a t i o n of common s u b p r o b l e m s , a DP a l g o r i t h m
typically records t h e s o l u t i o n s to all s u b p r o b l e m s it e n c o u n t e r s . T h u s , at t h e e x p e n s e of
e x t r a s t o r a g e , a D P a l g o r i t h m c a n r e d u c e the time r e q u i r e d to s o l v e t h e o r i g i n a l p r o b l e m . DP
is m o s t a p p r o p r i a t e l y a p p l i e d to p r o b l e m s f o r w h i c h this table of s u b p r o b l e m s o l u t i o n s helps
e l i m i n a t e a g r e a t n u m b e r of r e d u n d a n t c o m p u t a t i o n s . A s t h e q u o t e at t h e b e g i n n i n g o f this
c h a p t e r s u g g e s t s , D P is a p p l i c a b l e p r i m a r i l y to t h e t y p e s of p r o b l e m s t h a t c a n b e expressed
a s a s e q u e n c e o f d e c i s i o n s to b e made at e a c h of s e v e r a l s t a g e s .

For other t y p e s o f p r o b l e m s t h e r e are c o r r e s p o n d i n g problem solving methods. These


m e t h o d s i n c l u d e d i v i d e - a n d - c o n q u e r , linear and i n t e g e r p r o g r a m m i n g , and b r a n c h - a n d - b o u n d .
Divide-and-conquer is applicable to problems that can be divided into subproblems of
( a p p r o x i m a t e l y ) e q u a l s i z e , the r e s u l t s of w h i c h c a n b e e f f i c i e n t l y u s e d t o s o l v e t h e original
problem [2]. F o r e x a m p l e , a d i v i d e - a n d - c o n q u e r d e c o m p o s i t i o n of a p r o b l e m o f s i z e N m a y
produce two s u b p r o b l e m s of s i z e N/2. Linear and i n t e g e r p r o g r a m m i n g are applicable to
problems with linear optimization functions and linear constraints. [11]. (Gilmore [23]
describes some interesting interrelationships b e t w e e n linear and i n t e g e r programming and
dynamic programming.) Branch-and-bound is commonly used for pruning of large tree
s e a r c h e s , a n d is also c l o s e l y r e l a t e d to DP [ 3 9 , 4 9 ] .

Dynamic programming o r i g i n a t e d w i t h the w o r k of Bellman [ 5 ] and has b e e n applied to


problems in o p e r a t i o n s r e s e a r c h , economics, control t h e o r y , computer s c i e n c e , and several
o t h e r areas. T h e t h e o r y has e v o l v e d in s e v e r a l d i r e c t i o n s : discrete vs. continuous states,
finite vs. infinite (countable and uncountable) number of states, and deterministic vs.
stochastic systems. N o t s u r p r i s i n g l y , the l i t e r a t u r e o n d y n a m i c p r o g r a m m i n g is enormous.
The survey p a p e r b y T h o m a s [ 6 9 ] is a g o o d o v e r v i e w of t h e s e v e r a l b r a n c h e s o f D P . The
orientation of this paper is toward the uses of DP in c o m p u t e r science, in particular
combinatorial problems. T h e DP algorithms f o r t h e s e p r o b l e m s a r e t y p i c a l l y d i s c r e t e , f i n i t e ,
PAGE 2

and deterministic. T a r j a n ' s [ 6 8 ] r e c e n t s u r v e y article o n c o m b i n a t o r i a l a l g o r i t h m s i n c l u d e s a


b r i e f d e s c r i p t i o n o f t h e a p p l i c a t i o n s of DP t o c o m p u t e r s c i e n c e .

T h i s p a p e r is i n t e n d e d t o b e a r e f e r e n c e to the uses of d y n a m i c p r o g r a m m i n g in c o m p u t e r
science. M a n y p r o b l e m s a r e c o v e r e d , along w i t h the DP a l g o r i t h m s and r e f e r e n c e s t o r e l a t e d
p r o b l e m s and more advanced results. W e i n t r o d u c e dynami c p r o g r a m m i n g in t h e f o r m o f an
example in Chapter 2 below, and in C h a p t e r 3 present some of t h e t h e o r y of DP and
subsequently apply it t o t h e p r o b l e m of C h a p t e r 2. In the f o l l o w i n g four chapters we
p r e s e n t a n d a n a l y z e e x a m p l e s f r o m s e v e r a l s u b c l a s s e s of DP p r o b l e m s . These subclasses are
(for the most part) defined by the f o r m of t h e recursion for breaking a problem into
subproblems. C h a p t e r 4 c o v e r s Single S o u r c e S h o r t e s t Path P r o b l e m s , C h a p t e r 5 d e s c r i b e s
O p t i m a l P a r e n t h e s i z a t i o n P r o b l e m s , Optimal P a r t i t i o n P r o b l e m s a r e a n a l y z e d in C h a p t e r 6, i n
C h a p t e r 7 w e p r e s e n t Optimal M a t c h i n g P r o b l e m s , and ' H a r d ' C o m b i n a t o r i a l P r o b l e m s a r e t h e
t o p i c o f C h a p t e r 8. E a c h of t h e s e c h a p t e r s a r e i n d e p e n d e n t and c a n b e r e a d s e p a r a t e l y from
the others. ( I t is s u g g e s t e d , h o w e v e r , that C h a p t e r s 2 and 3 b e r e a d b e f o r e a t t a c k i n g a n y o f
t h e material in t h e later chapters.)
PAGE 3

2. A n E x a m p l e
B e f o r e d i v i n g i n t o t h e t h e o r y , it will b e helpful to g i v e some of t h e f l a v o r o f D P a l g o r i t h m s
by g i v i n g an example. T h e d i a g r a m in F i g u r e 2-1 is a g r a p h w i t h ( n o n - n e g a t i v e ) weighted
edges. These weights a r e i n t e r p r e t e d as the " d i s t a n c e s " along t h e e d g e s c o n n e c t i n g the
nodes. T h u s , t h e d i s t a n c e f r o m n o d e (1,1) to n o d e (2,1) is 3 and t h e d i s t a n c e f r o m n o d e ( 2 , 1 )
to n o d e ( 3 , 2 ) is 2. ( T h e d i s t a n c e f r o m n o d e (2,1) to n o d e ( 1 , 1 ) , o n t h e o t h e r h a n d , is not
d e f i n e d i n t h e g r a p h a n d c a n t h u s b e assumed to b e infinite.) T h e d i s t a n c e a l o n g p a t h ( 1 , 1 ) -
( 2 , 1 ) - ( 3 , 2 ) is 3 + 2 = 5. T h e p r o b l e m is to f i n d t h e s h o r t e s t p a t h f r o m n o d e ( 0 , 1 ) t o n o d e ( 4 ,
1).

F i g u r e 2 - 1 : F i n d t h e s h o r t e s t p a t h f r o m Node (0,1) t o N o d e ( 4 , 1 )

There a r e s e v e r a l a p p r o a c h e s that w e can take t o s o l v e this p r o b l e m . O n e a p p r o a c h is t o


e n u m e r a t e all o f t h e p a t h s f r o m n o d e (0,1) to n o d e (4,1) and c h o o s e t h e o n e w i t h minimum
distance. F o r t h e g r a p h o f F i g u r e 2-1 t h e r e a r e 3 3
= 27 d i f f e r e n t p a t h s f r o m n o d e ( 0 , 1 ) t o
node (4,1). Examing all t h e s e p a t h s is s o m e w h a t tedious, but definitely manageable. If,
h o w e v e r , i n s t e a d o f 3 c o l u m n s of 3 n o d e s t h e r e w e r e K columns of L n o d e s , t h e n t h e r e w o u l d
be L K
paths to examine! T h u s , t h e n u m b e r of p a t h s g r o w s v e r y r a p i d l y w i t h L a n d K a n d f o r
l a r g e p r o b l e m s o f this t y p e a n o t h e r m e t h o d will h a v e to b e u s e d .

A d y n a m i c p r o g r a m m i n g a p p r o a c h t u r n s o u t to b e j u s t w h a t w e n e e d . Let
- t h e ( n o n n e g a t i v e ) " d i s t a n c e " f r o m n o d e (i,j) t o n o d e ( i + l , k )
PAGE 4

a n d let

M j j = l e n g t h of the s h o r t e s t p a t h f r o m n o d e (0,1) to n o d e ( i , j ) .

T h e o p t i m i z a t i o n f o r t h e p r o b l e m in F i g u r e 2-1 p r o c e e d s in f o u r stages. In e a c h s t a g e i w e
f i n d t h e l e n g t h s o f t h e s h o r t e s t p a t h s f r o m n o d e (0,1) to t h e n o d e s (i,j), f o r ail j , w h i c h we
d e n o t e b y Mjj. S t a g e 1 is e a s y since t h e r e is o n l y o n e p a t h f r o m n o d e ( 0 , 1 ) t o e a c h o f the
n o d e s (1,1), (1,2), and (1,3). Thus, w e have

l l 011» 1 2 M
012' 1 3
= C
013- M = C M = C

S t a g e 2, h o w e v e r , r e q u i r e s some c o m p u t a t i o n since t h e r e a r e t h r e e p a t h s f r o m n o d e ( 0 , 1 ) t o
e a c h o f t h e n o d e s ( 2 , 1 ) , ( 2 , 2 ) , and (2,3). Thus,

M
21 = m i n
< 011
c + C
lll> C
012 + C
121> 0 1 3 C + C
131 *
M 2 2 = min ( C Q 1 1 + C n 2 , C 0 1 2 + 122' 013
c C + C
132 *
M 2 3 = min ( C 0 1 1 + C 1 1 3 , C Q 1 2 + C 1 2 3 , C Q 1 3 + C 1 3 3 )
I n s t a g e 3 w e f i n d t h e l e n g t h s of the s h o r t e s t path s f r o m n o d e (0,1) to n o d e s ( 3 , 1 ) , ( 3 , 2 ) , a n d
(3,3). H e r e is w h e r e t h e g r e a t a d v a n t a g e of dynamic p r o g r a m m i n g b e c o m e s a p p a r e n t . It is
n o t n e c e s s a r y t o e x a m i n e ail p a t h s f r o m n o d e (0,1) to n o d e s (3,1), (3,2), a n d ( 3 , 3 ) b e c a u s e we
c a n u s e t h e r e s u l t s f r o m s t a g e 2 as f o l l o w s :

M | = min ( M j ^ + C ^ | , M
3 2 2 2 2 * ^ 2 2 1 ' ^ 2 3 **" ^ 2 3 1 ^
M 3 2 = min ( M ^ + ^212* ^ 2 2 2 ^222* ^ 2 3 +
^232 ^
M 3 3 = min ( M j ^ + C j ^ , M 2 2 3 2 2 + ^223* ^ 2 3 ^233 ^
S i m i l a r l y , in s t a g e 4 w e c a n u s e the r e s u l t s f r o m s t a g e 3.
M 4 1 - min ( M 3 1 + C 3 1 1 , M 3 2 + C 3 2 1 , M 3 3 + C 3 3 1 )
T h e s o l u t i o n f o r F i g u r e 2 - 1 is p a t h (0,1) - (1,1) - (2,2) - (3,3) - (4,1) of l e n g t h 7. N o t e t h a t it
is s t r a i g h t f o r w a r d t o d e t e r m i n e that the l e n g t h M ^ j = 7, but r e c o v e r i n g t h e corresponding
path (or paths) is a slightly different problem. It is, h o w e v e r , s i m p l y s o l v e d by simply
recording a pointer Pjj w i t h e a c h d i s t a n c e Mjj w h i c h p o i n t s back to t h e n o d e ( i - l , k ) from
w h i c h t h e s h o r t e s t p a t h to n o d e (i,j) came.

Why c a n t h e r e s u l t s o f s t a g e 2 be u s e d to s o l v e s t a g e 3, and the r e s u l t s o f s t a g e 3 be


u s e d t o s o l v e s t a g e 4? T h i s is b e c a u s e of the Markov property of this t y p e o f p r o b l e m . The
o p t i m u m p a t h f r o m a n o d e (i,j) to n o d e (4,1) d o e s not d e p e n d o n t h e p a t h t a k e n f r o m n o d e ( 0 ,
1) t o n o d e (i,j). T h i s p r o p e r t y c a n be e x p r e s s e d as Bellman's P r i n c i p l e of O p t i m a l i t y :
" A n o p t i m a l p o l i c y has the p r o p e r t y that w h a t e v e r t h e initial s t a t e a n d initial
d e c i s i o n a r e , t h e r e m a i n i n g d e c i s i o n s must c o n s t i t u t e an optimal p o l i c y w i t h r e g a r d
to t h e s t a t e resulting from the first decision." Bellman[57], p.83.
PAGE 5

W e c a n u s e t h i s p r i n c i p l e f o r t h e g e n e r a l case of K columns of L n o d e s . The dynamic


programming approach will take only 0(K*L^) time, a significan t improvement over the
exhaustive approach of examining all L K
paths. B o t h of t h e s e methods require 0(K*L^)
storage to s t o r e the distances ( C j j ) . k T h e g e n e r a l formulas d e s c r i b i n g t h e o p t i m i z a t i o n for
t h i s t y p e o f p r o b l e m , k n o w n as t h e functional equations f o r this p r o b l e m , a r e

M
ij =
T ( M
<i-i),k + c
<i-n,k,j >

w h e r e M . i t = 0 , f o r all k. I n t h e n e x t c h a p t e r w e s h o w h o w to d e r i v e t h i s e q u a t i o n .
n
PAGE 6

3 . B r i e f S u m m a r y of the T h e o r y

B e l l m a n ' s P r i n c i p l e of O p t i m a l i t y , as s h o w n in the example of C h a p t e r 2, is an i m p o r t a n t a n d


p o w e r f u l p r i n c i p l e for dynamic programming. It is, h o w e v e r , lacking in at least t w o w a y s : (1)
I t is n o t s t a t e d v e r y r i g o r o u s l y , and ( 2 ) the p r o b l e m of o b t a i n i n g t h e f u n c t i o n a l e q u a t i o n s is
not e v e n addressed. T o o b t a i n the functional e q u a t i o n s , w e must r e l y o n m e t h o d s b e y o n d t h e
s c o p e of the P r i n c i p l e of Optimality.

By the mid 1960's several people had s o l v e d the first problem by showing that the
P r i n c i p l e o f O p t i m a l i t y d e r i v e s f r o m a m o n o t o n i c i t y p r o p e r t y of t h e c o s t f u n c t i o n s . (See Karp
a n d H e l d [ 4 4 ] f o r r e f e r e n c e s . ) K a r p and Held s u b s e q u e n t l y made c o n s i d e r a b l e p r o g r e s s o n t h e
second problem. In their f o r m u l a t i o n , a c o m b i n a t o r i a l d e c i s i o n p r o b l e m is a s s u m e d t o be
expressed in t h e f o r m o f a discrete decision process (DDP). T h i s f o r m is u s u a l l y a fairly
natural way to express the problem. The dynamic programming algorithm to solve the
p r o b l e m , o n t h e o t h e r h a n d , c o r r e s p o n d s to a sequential decision process ( S D P ) . Karp and
Held describe the t r a n s f o r m (if it e x i s t s ) f r o m a d i s c r e t e d e c i s i o n p r o c e s s t o a s e q u e n t i a l
decision process.

T h e r e s u l t o f K a r p a n d Held c a n be u s e d to d e r i v e the f u n c t i o n a l e q u a t i o n s f o r t h e p r o b l e m
of Figure 2-1. Their r e s u l t , h o w e v e r , will not be f o l l o w e d e x a c t l y b e c a u s e it is l o n g and
complicated to e x p l a i n (and thus discouraging for readers). T h u s , to d e r i v e t h e functional
e q u a t i o n s as p a i n l e s s l y as p o s s i b l e , a modified a p p r o a c h will be d e s c r i b e d w h i c h s h o u l d n ' t go
too far wrong. The f i r s t s t e p is to d e f i n e the d i s c r e t e d e c i s i o n p r o c e s s . The D D P is a
f o u r - t u p l e D « ( A , S, P, f ) w h e r e

A = { p r i m i t i v e d e c i s i o n s },

S = { f e a s i b l e p o l i c i e s } = { tuples of p r i m i t i v e d e c i s i o n s w h i c h t r a n s f o r m the
s t a r t s t a t e to a final s t a t e },

P = { s e t s o f d a t a u s e d b y the c o s t f u n c t i o n f }, and

f = c o s t f u n c t i o n , d e f i n e d o v e r all x £ A*,

w h e r e A * is t h e s e t o f all n - t u p l e s of elements of A f o r n > 0. T h e case n = 0 is t h e empty


s t r i n g a n d is d e n o t e d V \ F o r t h e p r o b l e m of F i g u r e 2-1 the DDP D = ( A , S, P, f ) is d e f i n e d
by

A = { aj, a 2 a 3 } w h e r e aj t r a n s f o r m s t h e s t a t e f r o m n o d e ( i - l , k ) t o n o d e ( i , j ) ,

S = { a a a ai j k 1 | i,j,k < { 1 , 2 , 3 } },

P = { matrices C | C j f k > 0, V i < {0,1,2,3}, j , k < {1,2,3} }, and

f is d e f i n e d r e c u r s i v e l y b y : f ( e , p ) = 0, f(aj,p) - C 0 1 j , f(xajaj,p) - f(xaj,p) + C n j j


w h e r e n = l e n g t h ( x ) + 1, and p * P.
PAGE 7

The c o n v e r s i o n f r o m D D P to SDP ( s e q u e n t i a l d e c i s i o n p r o c e s s ) is not e n t i r e l y automatic.


W e m u s t f i r s t d e f i n e t h e s t a t e s f o r the SDP (and thus the DP a l g o r i t h m ) o r d o s o m e t h i n g else
t h a t is e q u i v a l e n t . * Q n c e t h e s t a t e s a r e d e f i n e d , the o t h e r c o m p o n e n t s o f t h e S D P convert
fairly automatically from the DDP. The discrete decision process D is t r a n s f o r m e d to a
s e q u e n t i a l d e c i s i o n p r o c e s s W = ( Z, P, h, k ) w h e r e

Z is a f i n i t e s t a t e a u t o m a t o n Z = ( A , Q, qQ, F, \ ) w h e r e

A = a l p h a b e t f o r Z (same A as f o r the DDP a b o v e ) ,

Q = { s t a t e s },

q Q = initial s t a t e ,

F = { final s t a t e s }, / correspond to S in the DDP

X = transition function,

P = d a t a f o r t h e c o s t f u n c t i o n s h and k (same as P f o r t h e DDP),

h = c o s t f u n c t i o n d e f i n e d b y : h(r,q,a,p) = cost of r e a c h i n g s t a t e X ( q , a ) b y f i r s t
r e a c h i n g s t a t e q at a c o s t r and t h e n a p p l y i n g t h e s e q u e n c e of d e c i s i o n s a. T h e
f u n c t i o n h r e l a t e s to f b y : h(r,q,a,p) » f ( x a , p ) w h e r e f ( x , p ) = r and X ( q Q , x ) - q .

k ( p ) is t h e c o s t o f t h e null s e q u e n c e (of p r i m i t i v e d e c i s i o n s ) e.

T h e S D P f o r t h e p r o b l e m o f F i g u r e 2 - 1 is a f o u r - t u p l e W = ( Z, P, h, k ) w h e r e

Z is an f s a Z * ( A , Q, qQ, F, X ) w h e r e

A = { aj, a , a 2 3 },

Q 88
( 01>
s s
l 1' 1 2 > 13> 21> 22> 23> 31> 32> 33> 4 1 J»
s s s s s s s s s

^0 =
f s
01
F - { s 4 i },

X is d e f i n e d b y : X(sjj,a^) • s ^ + i ) ^

P = { matrices C | C j j k > 0, V i * {0,1,2,3}, j,k ^ {1,2,3} },

h is d e f i n e d b y : h ( r , S j j , a ^ , p ) = r + C j j ^ , and

k is d e f i n e d b y : k ( p ) = 0.

N o w t h a t w e h a v e d e f i n e d t h e S D P , if t h e m o n o t o n e p r o p e r t y ( d e s c r i b e d b e l o w ) is s a t i s f i e d

then the SDP is a monotone sequential decision process ( M S D P ) f r o m w h i c h t h e functional

e q u a t i o n s f o r the DP algorithm can be d e r i v e d .

1
Karp and Hold use a complicated argument that involves a (finite rank) equiresponse relation of an automaton
w h i c h the states are derived.
PAGE 8

Monotone property: If r^ < r 2 then h(rj,qQ,x,p) < h(r ,qQ,x,p), V x ( A * . 2

( F o r t h e p r o b l e m o f F i g u r e 2 - 1 this is e a s i l y s a t i s f i e d b e c a u s e o f t h e a d d i t i v i t y o f h ( r , q , a ,
p ) . ) T h e f u n c t i o n a l e q u a t i o n s d e f i n e a f u n c t i o n G s u c h that

G
< ^ > - { * | x C > - q } < <e>'V<>P>- h k

T h a t i s , G ( q , p ) is t h e minimum p o s s i b l e cost t o g e t t o state q , u n d e r t h e c o s t f u n c t i o n h. N o w it


is p o s s i b l e t o d e f i n e t h e f u n c t i o n a l e q u a t i o n s .

Functional Equations:

G ( q , p ) = m i n ( k(p),
0 { ( S ( a ) | x ^ ) = q o } h<G<s,p),q,a,p> )

G ( q
' p ) =
{<s,a)|X<T,a)-q} < < >P>.q»a>P> h G s f o r
<* * % •

F o r t h e p r o b l e m o f F i g u r e 2 - 1 this is

G(s ,p) = 0
0 1

G ( S
" P ) =
<W i > ( G(S
«-W P) + >

L e t t i n g M y = G ( s j j , p ) , this is

M Q 1 = 0

M
ii = t n ( M
(i-l),k + C
( -l).K,i '
i
) f 0 r (
^^ ( 0 1 )
-

T h i s e q u a t i o n is t h e same as t h e f u n c t i o n a l e q u a t i o n g i v e n f o r this p r o b l e m in C h a p t e r 2.

The results of Karp a n d Held p r o v i d e a p o w e r f u l a p p r o a c h f o r t h e c o n s t r u c t i o n o f D P


a l g o r i t h m s b u t s e v e r a l d e t a i l s a r e left u n s o l v e d . F o r e x a m p l e , K a r p a n d H e l d n o t e t h a t a g o o d
h e u r i s t i c f o r r e d u c i n g t h e time r e q u i r e d b y a DP algorithm is t o minimize t h e n u m b e r o f s t a t e s
in t h e S D P . T h e p r o b l e m o f minimizing the n u m b e r of s t a t e s , h o w e v e r , is n o t in g e n e r a l
s o l v a b l e i n a f i n i t e n u m b e r o f s t e p s [ 3 8 ] . A n o t h e r detail left u n s o l v e d b y K a r p a n d H e l d i s
t h e p r o b l e m o f t r a n s f o r m i n g t h e p r o b l e m statement to a d i s c r e t e d e c i s i o n p r o c e s s . Given a
p r o b l e m s t a t e m e n t , t h e r e may b e s e v e r a l w a y s t o r e p r e s e n t t h e c o r r e s p o n d i n g D D P .

I n t h e f o l l o w i n g c h a p t e r s w e will a p p l y t h e t e c h n i q u e s p r e s e n t e d in this c h a p t e r t o s e v e r a l
subclasses of DP problems. S i n c e t h e n o t a t i o n is s o m e w h a t c u m b e r s o m e a small c o m p r o m i s e
has b e e n made. T h e c o s t f u n c t i o n s f ( x , p ) and h(r,q,a,p) shall b e ( m o r e c o n v e n i e n t l y , a l t h o u g h
l e s s c o r r e c t l y ) d e n o t e d b y s i m p l y f ( x ) and h(r,q,a), r e s p e c t i v e l y .
PAGE 9

4. S i n g l e S o u r c e S h o r t e s t Path Problems
T h e p r o b l e m o f C h a p t e r 2 is a s p e c i a l case of the single s o u r c e s h o r t e s t p a t h p r o b l e m . But
b e f o r e d e s c r i b i n g t h e g e n e r a l p r o b l e m , w e s h o u l d f i r s t n o t e some o t h e r i n t e r e s t i n g problems
that fall into this special case. O n e of the b e t t e r known problems of this type is the
s t a g e c o a c h p r o b l e m ( [ 7 2 ] ] ) , w h i c h is commonly u s e d as an i n t r o d u c t i o n to D P in operations
research textbooks. A r a t h e r c u r i o u s e x a m p l e of this t y p e of a l g o r i t h m is t h e o r d i n a r y , g r a d e
school a l g o r i t h m f o r long division [8]. But of more i n t e r e s t to c o m p u t e r s c i e n t i s t s is the
V i t e r b i algorithm. T h e V i t e r b i a l g o r i t h m [71, 19] is f o r m a l l y a s t a g e c o a c h t y p e o f p r o b l e m , s o
it is n o t n e c e s s a r y t o d e s c r i b e it in detail h e r e . Its a p p l i c a t i o n s , h o w e v e r , i n c l u d e n o t only
e s t i m a t i o n p r o b l e m s in digital communications [ 9 ] b u t also t e x t r e c o g n i t i o n [ 1 9 ] a n d s y n t a c t i c
pattern recognition [61]. The s t a g e c o a c h p r o b l e m has also b e e n e n c o u n t e r e d in speech
r e c o g n i t i o n [ 3 ] a n d in image u n d e r s t a n d i n g s y s t e m s [ 1 6 ] .

We will now describe the general single source shortest path problem. Let G be a
( d i r e c t e d ) g r a p h o f N n o d e s and E e d g e s . T h e e d g e (if a n y ) f r o m n o d e Nj t o n o d e N j is e d g e
Ejj. T h e c o s t s t r u c t u r e is d e f i n e d b y the w e i g h t s C j j > 0 c o r r e s p o n d i n g to t h e e d g e s E j j . The
p r o b l e m is t o f i n d t h e s h o r t e s t p a t h f r o m node N j to node N^. F o r n o w w e w i l l a s s u m e t h a t
t h e g r a p h G is a c o m p l e t e g r a p h . ( F o r e a c h pair of n o d e s Nj and Nj t h e r e is an e d g e E j j . ) If a
particular g r a p h is n o t a l r e a d y c o m p l e t e , w e can e a s i l y make it so b y augmenting it with
e d g e s Ejj w i t h w e i g h t s C j j = oo.

Our goal now is t o o b t a i n the functional e q u a t i o n s f o r a DP a l g o r i t h m t h a t s o l v e s this


problem. T o d o t h i s , h o w e v e r , the p r o b l e m will h a v e to r e w o r d e d s l i g h t l y . Instead of d i r e c t l y
f i n d i n g t h e s h o r t e s t p a t h f r o m n o d e N j to n o d e N , the a l g o r i t h m will f i n d t h e length o f
N the
shortest path. F o r t h i s p r o b l e m o n l y a t r i v i a l modification of t h e a l g o r i t h m is t h e n necessary
to obtain the actual shortest path. F o r some p r o b l e m s in o t h e r c h a p t e r s , h o w e v e r , the
d i s t i n c t i o n is n o t s o t r i v i a l .

T o o b t a i n t h e f u n c t i o n a l e q u a t i o n s the first s t e p is to d e f i n e t h e d i s c r e t e d e c i s i o n p r o c e s s

( D D P ) D = ( A , S , P, f ). F o r t h e s i n g l e s o u r c e s h o r t e s t p a t h p r o b l e m this i s :

A = { a a2> }, where "af means "go to node L"

S = { A*a|vj }, = set of all feasible paths from node 1 to node N

P = { m a t r i c e s C | C j j > 0, Cjj = 0, i,j=l,2,...N }, and


f, t h e c o s t f u n c t i o n , is d e f i n e d r e c u r s i v e l y b y : f ( e ) = 0, f ( a j ) - C^, f(xajaj) =
f ( x a j ) + C j j , V x c A*.

T h e c o r r e s p o n d i n g S D P W - ( Z, P, h, k ) is
PAGE 10

Z = f s a ( A , Q , q Q , F, X ) w h e r e

A = s a m e as f o r t h e DDP,

Q = { Sj, s 2 > . . . S|\j }, where "s^" means "at node i"

qo =
{ s
l )>
I 7
= { s N },

X(Sj,aj) = Sj,

P = s a m e as f o r t h e DDP,

h(r,Sj,aj) = r + C j j , and

M p ) = 0.

T h e m o n o t o n i c i t y p r o p e r t y is s a t i s f i e d e a s i l y b y the a d d i t i v i t y of t h e c o s t f u n c t i o n . Thus, the


functional equations are:

G(s ) = 0{

G ( s
i> - h ( G ( s
iVi) " T < < i> G s + C
Ji>

L e t t i n g M ( i ) = G ( s j ) t h i s is

M(1) = 0

M(i) = ^ ( M ( j ) + C,.)

W e w i l l n o w s h o w h o w to s o l v e t h e s e functional e q u a t i o n s .

It is n o t as i n t u i t i v e l y o b v i o u s h o w to s o l v e t h e s e e q u a t i o n s as it w a s f o r t h e stagecoach
problems. T h e s o l u t i o n is k n o w n as D i j k s t r a ' s algorithm [ 1 2 , 6, 6 0 ] and r e q u i r e s O ( N ^ ) time
and storage. ( F o r a g e n e r a l g r a p h this is the b e s t that o n e c a n d o b e c a u s e t h e r e a r e O(N^)
edges and any shortest p a t h a l g o r i t h m w i l l , in the w o r s t c a s e , h a v e t o l o o k at all o f the
edges.) The a l g o r i t h m r u n s in N - 1 s t a g e s and in e a c h s t a g e i f i n d s t h e i t h c l o s e s t n o d e to
node Nj.. But e a c h stage requires a comparison b e t w e e n 0(N) nodes, so the total time is
0(N ).
2
PAGE 11

A l g o r i t h m f o r S i n g l e S o u r c e S h o r t e s t Path

I n p u t : C o m p l e t e g r a p h G w i t h i n t e r n o d e distance s C ( I , J ) .
O u t p u t : G ( I ) = d i s t a n c e of s h o r t e s t p a t h f r o m Node 1 to Node I.
H(I> = last n o d e b e f o r e Node I in an optimal path f r o m N o d e 1 t o N o d e I.
Time: 0 ( N ) , Storage: 0 ( N )
2 2

/ Initialization;
For I « - 1 t h r u N d o
b e g i n G ( I ) <- C ( 1 , I ) ; H(I) <- 1; e n d ;
N O D E S <- { 1, 2, 3 , . . . N );

! S - set of nodes for which an optimal path has been found;


S <- { 1 }; N E W <- 1;

/ Optimization;
F o r I <- 2 t h r u N d o
begin
M I N C O S T <- co;
F o r J < N O D E S - S do
begin
N E W C O S T <- G ( i , N E W ) + C ( N E W , J ) ;
If N E W C O S T < G ( J ) t h e n
begin
G ( J ) <- N E W C O S T ; H(J) <- N E W ;
end;
If G ( J ) < M I N C O S T t h e n
begin
M I N C O S T <- G ( J ) ; M I N J 4 - J ;
end
end;
S 4 - S U { M I N J }; N E W <- M I N J ;
end;

This a l g o r i t h m c a n b e m o d i f i e d to r u n in 0 ( E l o g N ) time and 0 ( E ) s t o r a g e , w h e r e E is the


n u m b e r o f e d g e s in t h e g r a p h . ( A h o , H o p c r o f t , and Ullman [ 2 ] g i v e c r e d i t t o J o h n s o n [42].)
F o r g r a p h s w h e r e E < N / l o g N this is b e t t e r than 0 ( N ) time and s p a c e .
2 2
For example, any
p l a n a r g r a p h o f N n o d e s ( N > 2 ) has at most 3*N - 6 ( u n d i r e c t e d ) e d g e s ( o r 6*N - 12 d i r e c t e d
edges) [26]. T h u s , the single source shortest path problem for a planar g r a p h can b e s o l v e d
i n 0 ( N l o g N ) time a n d 0 ( N ) s t o r a g e . T h e s e and r e l a t e d g r a p h algorithms a r e d e s c r i b e d i n A h o ,
H o p c r o f t , a n d Ullman [ 2 ] . A n i n t e r e s t i n g a p p l i c a t i o n of D i j k s t r a ' s a l g o r i t h m s i n c e 1974 is
d e s c r i b e d in Duncan [14]. A r e c e n t s u r v e y of fast expected time a l g o r i t h m s f o r t h e s h o r t e s t
p a t h p r o b l e m ( a n d o t h e r s i m p l e p a t h p r o b l e m s ) is p r o v i d e d in P e r l [ 5 7 ] . Fredman [20] (and
r e f e r e n c e s ) d e s c r i b e t h e all points s h o r t e s t p a t h p r o b l e m .
PAGE 12

5. O p t i m a l Parenthesization Problems

In this chapter we present several problems that can be described as optimal


parenthesization problems. T h a t is, t h e y c a n all be p u t in the f o r m :

G i v e n a s t r i n g of N e l e m e n t s , find an optimal (in some s e n s e ) p a r e n t h e s i z a t i o n o f


the string.

T h e s e p r o b l e m s i n c l u d e o p t i m i z a t i o n of the multiplication of N m a t r i c e s , c o n t e x t f r e e l a n g u a g e
recognition, various k i n d s o f optimal s e a r c h t r e e s , and o p t i m i z i n g t h e s e a r c h f o r N order
statistics.

The obvious brute force method for solving an optimal p a r e n t h e s i z a t i o n problem is to


s i m p l y e x a m i n e all o f t h e p o s s i b l e c o m p l e t e p a r e n t h e s i z a t i o n s of N e l e m e n t s a n d c h o o s e the
best one. Unfortunately, this rapidly becomes unmanageable. The number of ways to
c o m p l e t e l y p a r e n t h e s i z e a s t r i n g of N elements is the Nth Catalan n u m b e r

It c a n b e s h o w n that X ( N ) > 2 ~ N 2
( [ 2 ] , p.73).

The DP a l g o r i t h m s f o r these problems o f f e r substantial improvement o v e r the b r u t e force


method. T h i s is b e c a u s e an o p t i m a l l y p a r e n t h e s i z e d s t r i n g must b e c o m p o s e d o f optimally
parenthesized substrings. (If a s u b s t r i n g c a n b e b e t t e r p a r e n t h e s i z e d , t h e n t h e e n t i r e string
c a n b e b e t t e r p a r e n t h e s i z e d . ) DP uses this p r o p e r t y of optimal p a r e n t h e s i z a t i o n p r o b l e m s to
a c h i e v e f u n c t i o n a l e q u a t i o n s of the f o r m

M., = m , n

ik i<j<k ijk
= f ( M
i j ' ( j * l ) , k >•
M

T h e o p t i m a l p a r e n t h e s i z a t i o n f o r t h e s u b s t r i n g (i,k) is d e t e r m i n e d b y e x a m i n i n g t h e k - i p a i r s
of Mjj and + ( w h i c h have already been computed). Since t h e r e a r e 0 ( N ) s u b s t r i n g s ( i ,
2

k ) , t h e t o t a l t i m e is 0 ( N ) , much less than 0 ( X ( N ) ) .


3

For two of the p r o b l e m s , optimal alphabetic encoding and optimal s e a r c h for N order
s t a t i s t i c s , t h e 0 ( N ) time c a n b e i m p r o v e d to 0 ( N log N) time.
3
Unfortunately, this speedup
r e l i e s o n p r o p e r t i e s t h a t a r e p e c u l i a r to t h e s e individual p r o b l e m s and c a n n o t b e a p p l i e d t o
all of the parenthesization problems. A nice decomposition into parallel computations,
h o w e v e r , is a v a i l a b l e f o r a n y optimal p a r e n t h e s i z a t i o n p r o b l e m . Guibas, Kung, and T h o m p s o n
[ 2 5 ] h a v e s h o w n h o w ( N + 1) ( N + 2) / 2 - 0 ( N ) mesh-connected parallel p r o c e s s o r s
2
can
solve an optimal parenthesization p r o b l e m in 0 ( N ) time. (In general, a K b y K triangular
m e s h - c o n n e c t e d p r o c e s s o r c a n i m p r o v e the time to 0 ( N / K ) . ) 3 2
PAGE 13

5*1 Optimizing the Multiplication of N Matrices


The first p r o b l e m that w e will d e s c r i b e in this c h a p t e r is t h e p r o b l e m o f o p t i m i z i n g the
multiplication of N matrices. Since matrix multiplication is a s s o c i a t i v e , t h e m u l t i p l i c a t i o n s can
b e g r o u p e d as d e s i r e d a n d ( m a t h e m a t i c a l l y ) the r e s u l t will still be t h e same. Computationally,
however, it may make a tremendous difference. For example, consider the following
multiplication problem:

M = M 1 x M 2 x M 3 x M 4 x M .
5

[5x10] [10x100] [100x2] [2x20] [20x50]

W e w i l l a s s u m e in t h i s d i s c u s s i o n that the multiplication of a p x q matrix a n d a q x r matrix


costs pqr operations. (Probert [62] generalizes this problem to allow Strassen matrix
m u l t i p l i c a t i o n as w e l l as t h e o r d i n a r y b l o c k multiplication.) If the m u l t i p l i c a t i o n s a r e g r o u p e d
. M = M 1 x ( M 2 x ( ( M 3 x M 4 ) x M 5 ) )
t h e n t h e m u l t i p l i c a t i o n w i l l c o s t 156,500 o p e r a t i o n s . If, h o w e v e r , t h e g r o u p i n g is

M = ( M 1 x ( M 2 x M 3 ) ) x ( M 4 x M 5 )

t h e n t h e multiplication will cost o n l y 4600 operations.

W e w i l l n o w d e s c r i b e t h e g e n e r a l p r o b l e m and the c o r r e s p o n d i n g O ( N ^ ) time D P a l g o r i t h m . *

Let

M = Mj x M 2 x . . . x Mjvj

where Mj is a c q b y c± m a t r i x , M 2 is a c j b y c 2 matrix, e t c . The discrete decision process

D - ( A , S , P, f ) is d e f i n e d b y
A = { a j j k | l < i < j < k < N } , where a^ means "multiply the result of M± x M^+j
x ... x Mj by the result of Mj+i % x x

S = { sequences of a ^ corresponding to complete p a r e n t h e s i z a t i o n of the N


. m a t r i c e s },
P = { c <E ( I )
+ N + 1
}, a n d

f ( e ) = 0 , f ( x a j j ) - f ( x ) + C j . j * Cj * c .
k k

W e m u s t f i r s t d e f i n e t h e s t a t e s Q b e f o r e c o n s t r u c t i n g the SDP. T h e most n a t u r a l s e t o f s t a t e s

for this problem is the set of all partial parenthesizations of N elements. The SDP

W = ( Z, P, h , k ) is t h e n d e f i n e d b y

^ h i n [ 1 0 ] describes a non-DP O(N) time approximation algorithm that is never w o r s e than a factor of 5/4 f r o m
optimal.
PAGE 14

Z = ( A , Q , q Q , F, \ ), ( T h e c o m p o n e n t s are o b v i o u s . )

P = s a m e as f o r t h e DDP,

h ( r , q , a j j ^ ) = r + c , _ i * Cj * c^, and

k ( p ) = 0.

M o n o t o n i c i t y o f t h e S D P is a s s u r e d b y the a d d i t i v i t y of h. T h u s t h e f u n c t i o n a l e q u a t i o n s a r e

G ( q ) » 0, and
Q

G
<«> = {(s,a)|Ms a)= } ( q
h ( G ( s )
' '
S a )

The o p t i m i z a t i o n p r o c e d u r e s u g g e s t e d b y t h e s e e q u a t i o n s will c e r t a i n l y p r o d u c e an o p t i m a l
parenthesization. T h e time s p e n t , h o w e v e r , will be p r o h i b i t i v e . T h i s is b e c a u s e t h e number
of states that will have t o b e e x a m i n e d is the n u m b e r of p a r t i a l p a r e n t h e s i z a t i o n s of N
e l e m e n t s , w h i c h is at l e a s t as g r e a t as the Nth C a t a l a n n u m b e r X ( N ) . This does not compare
w e l l w i t h t h e 0 ( N ) time that w a s p r o m i s e d a b o v e .
3
Obviously, the choice of states will h a v e
t o b e made m o r e c a r e f u l l y . T h e n a t u r a l choice is not a l w a y s the b e s t .

Let's re-examine the situation. T o p r o d u c e a f a s t e r DP a l g o r i t h m t h e n u m b e r o f states


must be reduced. T h e r e is no g e n e r a l p r o c e d u r e f o r this. In f a c t , I b a r a k i [ 3 8 ] h a s shown
that t h e p r o b l e m is in g e n e r a l u n s o l v a b l e . T h u s , to r e d u c e the n u m b e r o f s t a t e s w e must
exploit properties p e c u l i a r to this p a r t i c u l a r p r o b l e m . In this c a s e a c l u e is p r o v i d e d b y a
c l o s e r e x a m i n a t i o n o f t h e p r i m i t i v e o p e r a t o r s a ^ in t h e set A. If t h e s u b s t r i n g s (Mj,Mj j,...Mj) +

and (Mj |,Mj 2>—^K^


+ +
a r e a
' r e a c
* y ^ " y p a r e n t h e s i z e d , t h e n a p p l i c a t i o n of t h e o p e r a t o r a ^
u
will
m a k e ( M j , M j |,...Mj,...M^) a f u l l y p a r e n t h e s i z e d s u b s t r i n g .
+ T h i s implies that t h e s t a t e s should
b e o f t h e f o r m S j j , l < i < j < N w h e r e s y has the i n t e r p r e t a t i o n " s u b s t r i n g (Mj,Mj ^,...Mj) is f u l l y +

parenthesized."

U n f o r t u n a t e l y , t h e r e is n o w a y that a p a r e n t h e s i z a t i o n s u c h a s ( ( M x M ) x ( M x M ) ) can
b e p r o d u c e d b y the primitive o p e r a t o r s with only these states Sjj. Thus, another property
p e c u l i a r t o p a r e n t h e s i z a t i o n p r o b l e m s will h a v e to b e p u l l e d out of a hat. T h i s o n e is a k i n d
of decomposition property and it looks more like divide-and-conquer [2] than dynamic
programming. T h e p r o p e r t y is that the p a r e n t h e s i z a t i o n of a s u b s t r i n g (i,j) is i n d e p e n d e n t of
t h e p a r e n t h e s i z a t i o n o f a s u b s t r i n g (k,Z) iff i < j < k < L o r k < L < i < j . T h u s , t h e p r o b l e m o f
p r o d u c i n g a s t a t e , call it ( S j j u S g + j ^ ) , f o r w h i c h a j ^ f u l l y p a r e n t h e s i z e s s u b s t r i n g ( i , k ) ( a n d
produces s t a t e S j ^ ) c a n b e d e c o m p o s e d into the p r o b l e m of s o l v i n g Sjj a n d s o l v i n g S^j+i)^-
S i n c e t h e c o s t f u n c t i o n is a d d i t i v e ,

< < ij (j+l),k> > - G s u s G


< ij>
s + G
<S(j+i), >- k

T h u s , the f u n c t i o n a l equations become


PAGE 15

G ( q ) = 0, and
Q

G
< i k > = (S, u 1 " , )
S
M k
G ( ( S
ii U S
<M>^ + C
-i * i* *
C C

- m
j n
G( S j j ) + G(S ( M ) > k ) + c M * c, * c . k

L e t t i n g Gjj - G ( S j j ) , this becomes

G H = 0, and

G., = m i n
G-. + G/- . + c , * c. * c . .
ik j u <j*l ),k i-l j n
k

w h i c h is t h e t y p e o f r e c u r r e n c e desired. H e r e is a p s e u d o - A l g o l a l g o r i t h m t h a t solves

functional equations:

A l g o r i t h m F o r C o m p u t i n g Optimal Multiplication of N Matrices

I n p u t : i n t e g e r N > 0 , array C [ 1 : N + 1 ] of p o s i t i v e i n t e g e r s
Output: A r r a y G w h e r e G ( i , j ) = minimum c o s t of p a r e n t h e s i z i n g s u b s t r i n g (i,j>.
A r r a y H w h e r e H(i,j) = s u b s c r i p t K w h e r e optimal p a r e n t h e s i s f o r s u b s t r i n g ( i , j ) i s
located.
Time: 0(N ), Storage: 0 ( N )
3 2

F o r L <- 1 t h r u N d o
G(L,L) 4- 0;
F o r L <- 2 t h r u N d o / L = length of substrings optimized
F o r I 4- 1 t h r u N + l - L do
begin
M I N C O S T <- oo;
J 4- I + L -1;
F o r K 4- I t h r u J - l do / Find optimal paren for substring (IJ)
begin
C O S T 4 - G(I,K) + G ( K + 1 , J ) + C ( I - l ) * C ( K ) * C ( J ) ;
If C O S T < M I N C O S T t h e n
begin
MINCOST 4- COST;
G(I,J) 4- C O S T ;
H(I,J) 4 - K
end
end
end;
PAGE 16

5.2 Context Free Language Recognition


C o n t e x t f r e e l a n g u a g e r e c o g n i t i o n is a w e l l s t u d i e d p r o b l e m . Younger [75] s h o w e d that a
Turing m a c h i n e c a n r e c o g n i z e a g e n e r a l c o n t e x t f r e e l a n g u a g e in 0 ( N ) t i m e , w h e r e 3
N is the
l e n g t h of the s t r i n g being recognized. Kasami and T o r i i [ 4 5 ] c o n s t r u c t e d an 0 ( N ) t i m e ( R A M ) 2

algorithm for unambiguous context free language recognition and E a r l y [15] produced an
algorithm that not only recognizes general context free languages in O ( N ^ ) t i m e , b u t also
u n a m b i g u o u s l a n g u a g e s in O ( N ^ ) time, and some f u r t h e r r e s t r i c t e d c l a s s e s of l a n g u a g e s (such
a s L R ( k ) ) in 0 ( N ) time. S i n c e t h e n Valiant [ 7 0 ] c o n s t r u c t e d an 0 ( N ^ 1 ) 1 time g e n e r a l context
f r e e r e c o g n i t i o n a l g o r i t h m ( b y using S t r a s s e n matrix multiplication), a n d G r a h a m , H a r r i s o n , a n d
Ruzzo [24] produced an 0(N^/logN) time on-line algorithm for general context free
recognition. I n t h i s p a p e r w e d e s c r i b e the simplest O ( N ^ ) time a l g o r i t h m f o r g e n e r a l context
f r e e language recognition.

The DP algorithm for general context free recognition that is p r e s e n t e d in t h i s paper


r e q u i r e s t h e c o n t e x t f r e e g r a m m a r to be put in C h o m s k y normal f o r m [ 3 2 ] . (Early [15] does
n o t r e q u i r e C h o m s k y n o r m a l f o r m , but his a l g o r i t h m is more c o m p l i c a t e d , t o o . ) T h e g r a m m a r is
a 4 - tuple

G = (Nonterminals, Terminals, Productions, Start symbol).


N o n t e r m i n a l s y m b o l s a r e i n d i c a t e d b y u p p e r case l e t t e r s ( A , B, C , . . .) a n d t e r m i n a l s y m b o l s
a r e i n d i c a t e d b y l o w e r c a s e l e t t e r s (a, b, c, . . .). T h e p r o d u c t i o n s a r e all o f t h e f o r m A - » B C
or A -» a ( C h o m s k y normal form). If m, n, and q a r e s t r i n g s of t e r m i n a l s a n d nonterminals,
t h e n m A n -> m q n iff A - » q is a p r o d u c t i o n . T h e l a n g u a g e g e n e r a t e d b y t h e g r a m m a r is t h e set
o f s t r i n g s o f t e r m i n a l s w s u c h that S -** w w h e r e - » * is the t r a n s i t i v e c l o s u r e o f

To construct t h e D P a l g o r i t h m w e must f i r s t d e f i n e t h e DDP. T h e DDP makes use of a


f u n c t i o n c a l l e d " P r e f i x " d e f i n e d as f o l l o w s :

L e t t h e i n p u t s t r i n g b e Z = z^Z2— |\j» * ' * ^ * ' S °f p r i m i t i v e o p e r a t o r s


z a n c e x e a s r n

aj^. P r e f i x ( x , a j j ) = t h e s t r i n g x minus all o p e r a t o r s to t h e r i g h t o f a ^ .


k If a ^
d o e s n o t o c c u r in x t h e n P r e f i x ( x , a j j ^ ) = e.

F o r e x a m p l e , if x « a
233 123 455 135>
a a a t h e n
Prefixfoa^g)- a
233 123 455*
a a T h e D D P i s

D - ( A , S , P, f ):

A = { a j f k | 1 < i < j < k < N } where ajj k produces the set { B | B - » C D and
c
^ * i i +l~ j
z z z a n d D
- > * j + l j - f 2 - k }»
z z z

S - { A*a l j N },

N o w improved to 0 < N ' ) with tho new matrix multiplication algorithm of Pan [54].
2 7 9
PAGE 17

P = { p r o d u c t i o n s }, a n d
f(e) = e, f<xajj ) k = { B | B->CD w h e r e 3p C ( f(Prefix(x,a j)) j p and 3q D (
f(Prefix(x,a ( j + 1 ) > q > k ) ) }.

T h i s is a m o s t c u r i o u s w a y t o d e f i n e a DDP. The primitive o p e r a t o r s and, e s p e c i a l l y , t h e c o s t


f u n c t i o n r e t u r n sets r a t h e r t h a n s c a l a r s . T h e r e a s o n f o r r e t u r n i n g s e t s is t h a t i n t h i s problem
we a r e i n t e r e s t e d in f i n d i n g all of the n o n t e r m i n a l s that p r o d u c e t h e s u b s t r i n g s Z j Z j j . . . Z j . + If
t h e r e a r e t w o o r m o r e n o n t e r m i n a l s that can g e n e r a t e a s u b s t r i n g Z j Z j j . . . Z j it is n o t s u f f i c i e n t +

to keep only one n o n t e r m i n a l and t h r o w t h e o t h e r s a w a y b e c a u s e t h e p r o d u c t i o n s d o not


t r e a t the nonterminals equivalently. T h u s , if f ( x a j p ) = { B, D, E } a n d f ( x a j ) = { D, E }, t h e n
k q k

a
ipk w
'" c e r
^ ' 'y
a n
be p r e f e r r e d over a | q k . If, h o w e v e r , f ( x a j ) = { B, D, E } a n d f ( x a j ) = { C
p k r k

} then we cannot say w h i c h is b e t t e r because the t w o s e t s are not comparable. This


s i t u a t i o n is d e s c r i b e d as a partial order r e l a t i o n . It is d e f i n e d b y
f(xa j p k ) < f(xa j q k ) iff f ( x a j p k ) c f(xa j q k ).
F u r t h e r m o r e , t h e o b j e c t is t o maximize r a t h e r t h a n minimize f u n d e r t h e p a r t i a l o r d e r in t h i s
problem. ( A c c o r d i n g l y , w e w i l l r e p l a c e " m i n " w i t h " u n i o n " in the f u n c t i o n a l e q u a t i o n s . )

N o w it is time t o p r o d u c e the SDP. Let the s t a t e Sjj be i n t e r p r e t e d as " z j Z j j . . . Z j h a s b e e n +

parsed". To produce an e f f i c i e n t algorithm, w e use p s e u d o - s t a t e s (Sjj U S pk as in the


p r e v i o u s parenthesization problem. T h e SDP is W = ( Z, P, h, k ) w h e r e

Z = f s a ( A , Q , q Q , F, X ) w h e r e

A » s a m e as f o r t h e DDP,

Q =» { S j j , ( S j j U S k Z ) },

qo - ( Jt e

F = { S 1 N } ,

X( (Sjj U S j + ( 1 ) > k ), ajj k ) = s , ik

P = s a m e as f o r t h e D D P ,

h(r,(Sjj u S j ( + 1 ) ) k ),ajj ) = f(xak j j k ) w h e r e X ( q , x ) = (Sjj u S j


0 ( + 1 ) > k ) , and

k ( p ) = e.
B e f o r e w e d e r i v e t h e f u n c t i o n a l e q u a t i o n s w e must f i r s t s h o w that t h e m o n o t o n i c i t y property
is s a t i s f i e d . N o t e t h a t t h e c o s t f u n c t i o n is not s i m p l y a d d i t i v e as in t h e p r e v i o u s p r o b l e m s so
m o n o t o n i c i t y d o e s n o t c o m e q u i t e as automatically. T h u s , w e must s h o w t h a t if x , y « A * , t h e n
If X ( q , x ) - X ( q , y ) and f ( x ) > f ( y ) t h e n f ( x w ) > f ( y w ) , V w < A * .
0 0

T h i s is t r u e b e c a u s e if f ( x ) => f ( y ) t h e n c e r t a i n l y Vw<=A* f ( x w ) f(yw). We conclude that the

functional equations are


PAGE 18

G ( q ) = e, and
Q

G ( S
^ =
,o ,c U
,W G(S
ii (i*i),K>> <V <M), >> a , , p )
US S
k j k

<V (M>,k' ijk>


S
a

U f(x x a 1 2 j j k ) where M q ^ ) = S j j and X C q ^ ) = S ^

H e r e is a n a l g o r i t h m f o r s o l v i n g the f u n c t i o n a l e q u a t i o n s :

A l g o r i t h m F o r G e n e r a l C o n t e x t F r e e Language Recognition

Input: Nonterminals = {Aj,A2, . . . A ^ j } / = start symbol


T e r m i n a l s = { t i » t 2 » • • • *T^
F i n i t e s e t o f p r o d u c t i o n s of the f o r m : Aj->AjA^ o r A j - » t j
S t r i n g Z = Z2Z2».Z|\j w h e r e Zj ( T e r m i n a l s
O u t p u t : A r r a y M w h e r e M(I,K) = { A | A -»* z j Z j + 1 ...z k }
T h u s , Z is r e c o g n i z e d iff s t a r t s y m b o l « A j ( M(1,N).
Time: 0(N ), 3
Storage: 0(N ). 2

F o r I «- 1 t h r u N do
M(I,I) 4 - { A | " A - ^ a f < Productions }
F o r L *- 2 t h r u N d o / L = length of string;
F o r I <- 1 t h r u N + l - L do
begin
K « - I + L - 1;
M(I,K) «- e; / e = empty set
F o r J <- I t h r u K - l d o
M ( I , K ) <- M(I,K) u { A | 3 ^ M ( I , J ) , / S € M ( J + 1 , K ) ( A ^ / S ) }
end;

N o t e t h a t t h e i n n e r l o o p is n o t i m p l e m e n t e d t h e same h e r e as f o r t h e p r e v i o u s t w o algorithms.
T h i s is b e c a u s e t h e p a r t i a l o r d e r r e l a t i o n f o r c e s us to use t h e u n i o n o p e r a t i o n r a t h e r t h a n a
min. S i n c e t h e s e t o f n o n t e r m i n a l s is f i n i t e , the s i z e of e a c h of t h e s e t s M ( I , K ) is b o u n d e d by
a constant. T h u s , t h e e n t i r e a l g o r i t h m still r e q u i r e s o n l y O ( N ^ ) time.

5.3 Optimal Alphabetic Encoding and Optimal Search Trees


T h e r e a r e m a n y k i n d s o f optimal s e a r c h t r e e s and optimal a l p h a b e t i c e n c o d i n g corresponds
naturally to one of the simpler kinds. An optimal alphabetic encoding bears several
similarities to a Huffman code [34]. W e a r e g i v e n an a l p h a b e t A L P H of N c h a r a c t e r s a n d t h e
p r o b a b i l i t i e s p j t h a t a r a n d o m l y c h o s e n c h a r a c t e r is c h a r a c t e r i. E a c h of t h e c h a r a c t e r s must
PAGE 19

be represented by a prefix code c h o s e n f r o m a set of r s y m b o l s . * Furthermore, for an


a l p h a b e t i c e n c o d i n g , t h e c o d e s f o r t h e l e t t e r s of A L P H must be in i n c r e a s i n g n u m e r i c a l o r d e r .
( F o r a H u f f m a n e n c o d i n g t h e c o d e s a r e not r e s t r i c t e d to b e o r d e r e d . ) L e t l { « length of the
e n c o d i n g o f c h a r a c t e r i. T h e o b j e c t i v e is to minimize t h e e x p e c t e d l e n g t h o f a m e s s a g e , t h a t is

N
min T\ i
D

{alphabetic encodings} "\ i"


1=1
Gilbert a n d M o o r e [ 2 2 ] w e r e t h e f i r s t to use DP to s o l v e the p r o b l e m o f c o n s t r u c t i n g an
optimal alphabetic encoding. T h e i r a l g o r i t h m is v e r y similar t o t h e a l g o r i t h m s f o r t h e other
o p t i m a l p a r e n t h e s i z a t i o n p r o b l e m s , and it r e q u i r e s O(IM^) time and O ( N ^ ) s t o r a g e .

The tree corresponding t o an optimal a l p h a b e t i c e n c o d i n g is i l l u s t r a t e d in F i g u r e 5 - 1 . A


" 0 " i n t h e e n c o d i n g c o r r e s p o n d s to a left b r a n c h o f the t r e e and a " 1 " c o r r e s p o n d s t o a r i g h t
branch. E a c h l e a f o f t h e t r e e c o r r e s p o n d s t o o n e of t h e l e t t e r s of t h e a l p h a b e t . The internal
n o d e s d o not r e p r e s e n t l e t t e r s of the alphabet. A general binary search t r e e , on the other
h a n d , m a y h a v e e l e m e n t s at i n t e r n a l n o d e s as w e l l as t h e l e a v e s .

OPTIMAL
ALPHABETIC
OPTIMAL ALPHABETIC TREE
CHARACTER PROBABILITY CODE

A 0.15 000
B 0.10 001 ,
C 0.15 010
D 0.10 Oil
E 0.20 10
F 0.05 1100
0.10 1101
G
0.15 111
H

F i g u r e 5 - 1 : E x a m p l e o f Optimal A l p h a b e t i c E n c o d i n g and R e l a t e d D e c i s i o n T r e e

Knuth describes the c o n s t r u c t i o n of a g e n e r a l optimal s e a r c h t r e e in 0 ( N ) 2


time (and
storage) ( [ 4 6 ] , [47J,p.433-439, [2], p.l 19-123). Not o n l y does this search tree include
elements at internal nodes but it also is e x t e n d e d to allow (nonzero) probabilities that

For this presentation w e will assume that r - 2, thus making the codes binary codes.
l
PAGE 20

unsuccessful searches a r e made in the t r e e . T h a t is, the s e a r c h k e y m a y b e less t h a n A,


b e t w e e n A a n d B, b e t w e e n B and C, e t c . Hu and T u c k e r [ 3 6 ] p r o d u c e d a m u c h d i f f e r e n t (and
c o m p l i c a t e d ) a l g o r i t h m to c o n s t r u c t an optimal a l p h a b e t i c t r e e in 0 ( N ) time a n d 0 ( N )
2
storage
( s e e a l s o H u [ 3 3 ] ) , w h i c h K n u t h [ 4 7 ] i m p r o v e d to O ( N l o g N ) time a n d 0 ( N ) s t o r a g e . Since t h e n ,
I t a i [ 4 0 ] h a s p r o d u c e d DP s o l u t i o n s f o r s e v e r a l c o n s t r a i n e d v a r i a t i o n s of t h e p r o b l e m . Payne
a n d M e i s e l [ 5 6 ] d e s c r i b e an i n t e r e s t i n g DP a l g o r i t h m f o r an optimal m u l t i - d i m e n s i o n a l binary
tree. W e w i l l p r e s e n t t h e o p t i m a l a l p h a b e t i c e n c o d i n g a l g o r i t h m of G i l b e r t a n d M o o r e . (For
treatments o f t h e g e n e r a l o p t i m a l s e a r c h t r e e t h e r e a d e r is r e f e r r e d to t h e t e x t s o f Knuth
a n d A h o , H o p c r o f t , a n d Ullman c i t e d a b o v e . )

T h e f i r s t s t e p t o w a r d s o l v i n g the optimal a l p h a b e t i c e n c o d i n g p r o b l e m is t o d e f i n e t h e D D P .
L e t t h e a l p h a b e t A L P H = ( z j , z , . . . z ) . T h e DDP D = ( A , S, P, f ) is
2 N

A = { a ^ | 1 < i < j < k < N } w h e r e a - ^ a p p e n d s a " 0 " to the front of t h e c o d e


f o r Z j , Zj j , .
+ . . Z j a n d a p p e n d s a " 1 " to t h e f r o n t of t h e c o d e f o r Z j j + f Zj+2> •
• • k> z

S = { s e q u e n c e s o f a ^ c o r r e s p o n d i n g to total p a r e n t h e s i z a t i o n s of N e l e m e n t s },

P = { (p ,p , . . .
x 2 p ) « (Reals )
N
+ N
}, and
f(e) = 0, f ( x a j j k ) = f(x) + X P . m

m=i,k

Note t h a t t h e c o s t f u n c t i o n f d o e s not seem to d e p e n d o n j at all. The dependence on j


comes from the constraint o n the legal p a r e n t h e s i z a t i o n s in S , as w i l l be shown in the
functional equations.

T o c o n s t r u c t t h e S D P w e must f i r s t d e f i n e t h e s t a t e s . Let t h e s t a t e Sjj b e i n t e r p r e t e d as


"an optimal alphabetic code has b e e n c o n s t r u c t e d f o r ZjZj j...Zj". T o
+ produce an efficient
algorithm, w e w i l l u s e p s e u d o - s t a t e s (Sjj U S | ) as in t h e p r e v i o u s o p t i m a l
k parenthesization
problems. T h e S D P is W = ( Z, P, h, k ) w h e r e
PAGE 21

Z = ( A , Q , q , F, X ) w h e r e
Q

A = s a m e as f o r t h e DDP,

Q - { S j j , ( S j j u S ) | l<i<j<k<l<N } U { e },
K I

= e
% '
F = { S 1 N } ,

X( (Sjj U S j ( + 1 ) > k ) , ajj k ) = s ,


ik

P = s a m e as f o r t h e D D P ,
h( r, ( S . . u S ( > U k ) f a. ) = r +
jk S P , and
m

k ( p ) = 0.

The monotonicity property is s a t i s f i e d b y the a d d i t i v i t y of t h e c o s t f u n c t i o n and thus the

functional equations are

G ( e ) = 0, a n d

« V - (S US 8 "i" ),a, ) * « V W
k ik V W '*>
k

= 1" G
ii +
W +
2 P m .
m=i
L e t t i n g Gjj = G ( S j j ) this becomes

Gjj - 0, and
k

G
iK - T G
ii + G
(M).K +
2 P -
m

These f u n c t i o n a l e q u a t i o n s c a n b e s o l v e d in O ( N ^ ) time b e c a u s e t h e s u m m a t i o n f r o m m=i to

m=k of p m c a n b e c o m p u t e d in 0 ( 1 ) time a f t e r some p r e p r o c e s s i n g . The following algorithm

• s h o w s h o w t h a t is d o n e .
PAGE 22

A l g o r i t h m f o r O p t i m a l A l p h a b e t i c Encoding

I n p u t : i n t e g e r N > 0 , a r r a y P [ 1 : N ] of p o s i t i v e r e a l s
O u t p u t : G ( I , K ) = c o s t of o p t i m a l e n c o d i n g of 2jZj+^...z«.
H ( I , K ) = s u b s c r i p t J f o r optimal p a r t i t i o n of ZjZj ^...z^.
+

Time: 0 ( N ) , Storage: 0 ( N )
3 2

/ Initialization of G and C;
C ( 0 ) 4 - 0;
F o r I «- 1 t h r u N do
begin
G ( I , I ) «- 0; C ( I ) «- C ( I - l ) + P(I)
end;
/ Optimization over all pairs (I>K).;
F o r L *- 2 t h r u N d o / L = length of string;
F o r I «- L t h r u N + l - L do
begin
K <~ I + L - 1;
M I N C O S T <- oo;
F o r J «- I t h r u K - l d o
begin
C O S T «- G ( I , J ) + G(J+1,K) + C ( K ) - C ( I - l ) ;
If C O S T < M I N C O S T t h e n
begin
M I N C O S T <- C O S T
G(I,K) <- C O S T ;
H(I,K) *- J ;
end
end
end;

5.4 Optimizing the Search for N Order Statistics


O p t i m i z i n g t h e s e a r c h f o r N o r d e r statistics is v e r y similar t o optimal a l p h a b e t i c encoding.
T h e p r o b l e m is d e s c r i b e d as f o l l o w s :

L e t X b e a s e t o f M r e a l n u m b e r s Xj. W e w a n t to find N ( N < M) o r d e r s t a t i s t i c s


Sj w h e r e Sj e q u a l s t h e aj'th smallest element of X. F o r e x a m p l e , if X = { 1 , 5 , 2 , 9 , - 2 } ,
M = 5 , N = 1, a n d a^ = 4 , t h e n s ^ = 5. T h e p r o b l e m is to f i n d t h e N o r d e r s t a t i s t i c s
Sj as q u i c k l y as p o s s i b l e .

One way t o f i n d t h e o r d e r s t a t i s t i c s is to s o r t t h e M e l e m e n t s of X in O ( M l o g M ) t i m e and


t h e n o b t a i n t h e N o r d e r s t a t i s t i c s in 0 ( N ) time ( b y using the aj as indices i n t o t h e s o r t e d set
X ) f o r a total time of O(MlogM); F o r large M we can do better. F o r the c a s e N = 1, t h e o r d e r
s t a t i s t i c s Sj c a n b e f o u n d in 0 ( M ) t i m e [ 7 , 6 3 ] . P o h l [ 5 9 ] d e s c r i b e s a s p e c i a l c a s e o f N « 2,.the
PAGE 23

m i n a n d t h e m a x , a n d s h o w s h o w t h e y can be f o u n d in | 3 M / 2 - 2 | comparisons, which is


b e t t e r t h a n t h e o b v i o u s 2 M - 2 c o m p a r i s o n algorithm. T h e DP a l g o r i t h m t h a t w e d e s c r i b e in
t h i s p a p e r m a k e s o p t i m a l u s e of a linear time s e l e c t i o n a l g o r i t h m . It d o e s n o t a t t e m p t t o do
a n y o p t i m i z a t i o n of the kind d e s c r i b e d b y Pohl.

To construct t h e D P a l g o r i t h m w e s t a r t , as a l w a y s , w i t h t h e d i s c r e t e decision process

D - < A , S , P, f ):

A = { aQ, a ^ , a2> . . . ajvj, ajvj+j }, / where a^ 1 < i < N finds the order statistic
s
i* 0
a
~ ^» anc
^ N+l
a =
M+i.
S = { x € A * | all aj a r e in x },
p = { a < M N
}, a n d
f ( e ) = 0 , f ( a j ) = M, f ( x a j ) = f ( x ) + a k - aj w h e r e j = max s u b s c r i p t o f a in x t h a t is
l e s s t h a n i, a n d k = min s u b s c r i p t of a in x that is g r e a t e r t h a n i.

When constructing t h e S D P w e e n c o u n t e r e x a c t l y the same p r o b l e m s w i t h t h e number of

states as with the problem of optimal multiplication of N matrices. Fortunately, the

d e c o m p o s i t i o n p r o p e r t y still a p p l i e s s o the trick of c o n s t r u c t i n g " s t a t e s " ( S j j U S p w i l l


k work.

S i n c e t h e d e t a i l s a r e b a s i c a l l y the same h e r e as f o r the p r e v i o u s p a r e n t h e s i z a t i o n problems,

w e w i l l p r e s e n t o n l y t h e r e c u r r e n c e r e l a t i o n and the a l g o r i t h m .

F u n c t i o n a l E q u a t i o n s f o r O p t i m i z i n g the S e a r c h f o r N O r d e r S t a t i s t i c s

G(i,i+1) = 0

G(i,K) = G(i,j) + G(j,k)


PAGE 24

A l g o r i t h m f o r O p t i m i z i n g t h e use of a Linear Selection A l g o r i t h m


t o F i n d N O r d e r Statistics

I n p u t : V e c t o r A s u c h that 0 = A ( 0 ) < A ( l ) < A(2) < . . . A(N) < A ( N + i ) = M + l


O u t p u t : A r r a y G w h e r e G ( I , K ) = minimum cost of finding all o r d e r s t a t i s t i c s A ( J ) ,
I < J < K, g i v e n that A ( I ) and A ( K ) h a v e a l r e a d y b e e n d e t e r m i n e d .
A r r a y H w h e r e H(I,K) = s u b s c r i p t J of optimal A ( J ) f o r s u b d i v i d i n g
the interval [A(I),A(K)].
Time: 0(N >, Storage: 0(N )
3 2

F o r L <- 0 t h r u N d o
G ( L , L + 1 ) <- 0;
F o r L <- 2 t h r u N + l d o / L =» Length of substrings optimized
F o r I <- 0 t h r u N + i - L d o
begin
M I N C O S T <- oo;
K <- I + L;
/ Find optimal paren for substring (7,K;)
F o r J *- 1+1 t h r u K - l do
begin
C O S T <- G ( I , J ) + G(J,K) + A ( K ) - A ( I ) - 1;
If C O S T < M I N C O S T t h e n
begin
G ( I , K ) <- M I N C O S T f - C O S T ;
H(I,K) <- J
end
end
end;

W e c a n i m p r o v e t h i s a l g o r i t h m to O ( N l o g N ) time and 0 ( N ) s t o r a g e . T h i s is b e c a u s e it c a n b e
put it i n t h e f o r m o f an o p t i m a l a l p h a b e t i c e n c o d i n g p r o b l e m . In the f u n c t i o n a l equations
above, the quantity G(i,k) is i n t e r p r e t e d to equal the minimum c o s t of finding all order
s t a t i s t i c s a j , i < j < k, g i v e n t h a t aj and a k have already been determined. C h a n g e this to

G ( i , k ) = minimum c o s t o f finding all o r d e r statistics a j , i < j < k, g i v e n t h a t aj a n d


a
k + l h a v e already been determined.

A l s o r e w r i t e the quantity a ^ j - a as the sum ( f r o m m=i to m=k) of ( a + j - a ) .


} m m The new
f u n c t i o n a l equations are
PAGE 25

N = 4
M = 100 G 0 1 2 CO 4 5 H 0 1 2 3 4 5
0 0 34 103 177 229 0 1 2 2 2
ORDER
1 0 49 118 159 l 2 3 3
STATISTICS
2 0 54 95 2 3 3
20 3 0 30 3 4

35 4 0 4
70 5 5

F i g u r e 5 - 2 : E x a m p l e of f i n d i n g optimal u s e of a linear s e l e c t i o n a l g o r i t h m .

G(i,i) = 0, and
k

G(i,k> = G(i,j) + GCJ+1.K) • X (a m + 1 - a > - 1.


m

J m=i

The functional equations are now in the same f o r m as t h e f u n c t i o n a l e q u a t i o n s for an


optimal alphabetic encoding. T h u s , the O ( N l o g N ) time and 0 ( N ) s t o r a g e a l g o r i t h m f o l l o w s .
PAGE 26

6 . O p t i m a l Partition Problems

O p t i m a l p a r t i t i o n p r o b l e m s a r e not e n t i r e l y unlike optimal p a r e n t h e s i z a t i o n p r o b l e m s . They


b o t h i n v o l v e a p a r e n t h e s i z a t i o n of a s t r i n g of N e l e m e n t s . The partition problem, however,
does not p r o d u c e a complete p a r e n t h e s i z a t i o n of the N e l e m e n t s . I n s t e a d , it p a r t i t i o n s the
s t r i n g i n t o K s e t s o f c o n s e c u t i v e e l e m e n t s ( w i t h K s e t s of u n n e s t e d p a r e n t h e s e s ) f o r some
v a l u e o f K. T h e v a l u e o f K m a y b e a g i v e n c o n s t a n t o r it may b e left u n s p e c i f i e d .

P e t e r s o n , B i t n e r , and H o w a r d [ 5 8 ] describe a problem for which the number of p a r t i t i o n s K


is u n s p e c i f i e d . T h e p r o b l e m is to s e l e c t optimal tab s e t t i n g s to minimize t h e n u m b e r o f b l a n k s
in a document. N is t h e n u m b e r of columns and K is t h e n u m b e r of t a b s s e t . The functional
e q u a t i o n s , h o w e v e r , are of the form

G Q = 0, and

G. = m a x
G. + C
i l l ! )
w h i c h is v e r y s i m i l a r t o t h e s o l u t i o n i o r the single s o u r c e s h o r t e s t p a t h p r o b l e m d e s c r i b e d i n
Chapter 4. Because of this similarity this p r o b l e m will not b e d i s c u s s e d further. The
r e m a i n d e r o f t h i s c h a p t e r w i l l i n s t e a d d e s c r i b e an e x a m p l e w h e r e K is a g i v e n c o n s t a n t .

T h e a u t h o r k n o w s o f t w o n o n t r i v i a l p r o b l e m s w h i c h a r e of t h e optimal p a r t i t i o n t y p e (with
a given value for the required n u m b e r of p a r t i t i o n s K). One is the resource allocation
problem ( [ 1 3 ] , c h . 3 ) , b u t t h e b e s t example of this t y p e of p r o b l e m is t h e o n e s o l v e d by
Fisher's a l g o r i t h m [ 1 7 , 2 7 ] . * T o d e s c r i b e the p r o b l e m w e will f i r s t h a v e t o i n t r o d u c e some
notation. L e t t h e i n p u t s t r i n g of N elements be d e n o t e d x j , x , X 3 , . . . X|\j, w h e r e Xj is a r e a l .
2

A cluster ( i , j ) is s i m p l y t h e s u b s t r i n g (xj,Xj + j , . . . X j ) . C o r r e s p o n d i n g to e a c h c l u s t e r ( i , j ) is a
diameter D ( i , j ) > 0 t h a t is a f u n c t i o n of ( x j , X j j , . . . X j ) . T h e d i a m e t e r f u n c t i o n t h a t w i l l b e u s e d
+

i n t h i s d e s c r i p t i o n is

D(i,j) = jL ( x . - x ) , w h e r e x » ^2

k=i " k
" k-i (
J- , + 1 )

L e t a K - partition o f t h e N e l e m e n t s be r e p r e s e n t e d b y a K + l - t u p l e (Io*'l*^2* • " • W w


^ e r e

0 = Iq < I| < I2 < • • • < I « - l < I « = N. T h e i n t e r p r e t a t i o n is that t h e f i r s t c l u s t e r is (Iq+I,^),


t h e s e c o n d c l u s t e r is ( I j + 1 , I ) I 2
e t c
- T h e optimal p a r t i t i o n p r o b l e m ( w h i c h F i s h e r ' s algorithm
s o l v e s ) is

Vast
algorithms f o r several special cases of Fisher's clustering problem will be presented b y Shamos, B r o w n . Saxe
and Weide [66]. '
PAGE 27

k
m ,
^n
D ( I +1 I )
{K-partitions} ~ u
^j ' j.l -
+ i 1 ;

O n e m e t h o d o f s o l u t i o n is t o s i m p l y g e n e r a t e all p o s s i b l e K - p a r t i t i o n s a n d c h o o s e t h e one

w i t h minimum cost. But t h e r e are

( N - 1)!
(ID- ( N - K)! * (K - 1)!

possible partitions, which for large K and N will be prohibitive. Dynamic programming

p r o v i d e s considerable improvement. T o p r o d u c e the DP a l g o r i t h m w e f i r s t c o n s t r u c t t h e DDP

D - ( A , S , P, f ):

A = { a j j | 1 < i < j < N } w h e r e ajj d e f i n e s t h e s u b s t r i n g ( x j X j i...Xj) as o n e o f t h e +

K sets of the partition,

S = { s e q u e n c e s o f K a^'s that p r o d u c e legal p a r t i t i o n s },

P = { N - t u p l e s o f r e a l s }, and

f ( e ) = 0 , f ( x a j j ) = f ( x ) + D(i,j) f o r all legal s e q u e n c e s x a j j .

To define the S D P w e must f i r s t d e f i n e the s t a t e s . One w a y t o d o this is t o let S ^ j j be

interpreted " s u b s t r i n g (i,j) is p a r t i t i o n e d into h sets of c o n s e c u t i v e e l e m e n t s . " T h i s l e a d s t o a

D P a l g o r i t h m t h a t c o s t s 0 ( K N ) time and 0 ( K N ) s t o r a g e .
3 2
A n o t h e r c h o i c e o f s t a t e s is a v a i l a b l e ,

h o w e v e r , t h a t n a t u r a l l y l e a d s t o a DP algorithm that c o s t s o n l y O ( K N ^ ) time a n d 0 ( K N ) s t o r a g e .

The improvement is to c o n s i d e r o n l y s t a t e s S ^ j = S ^ i j , w h i c h a r e i n t e r p r e t e d as "substring

( l , j ) is p a r t i t i o n e d i n t o h s e t s of c o n s e c u t i v e e l e m e n t s . " T h u s , t h e S D P W = ( Z, P, h, k) is

Z = ( A , Q , q , F, X ) w h e r e Q

A = s a m e as f o r t h e DDP,

Q = { S h j | 1 < h < k, 1 < j < N } u { e },

qo = > e

F - { S K N },

x ( s
hi' (i+l),j
a ) = S
(h+l),j'

P = s a m e as f o r t h e D D P ,

h(r,S ,a(
h i j + 1 ) j ) = r + D(i,j), and

k(p) = 0.

M o n o t o n i c i t y o f t h e S D P f o l l o w s f r o m a d d i t i v i t y of t h e c o s t f u n c t i o n D and t h e f a c t t h a t D ( i , j ) >

0. T h u s , t h e functional equations are


PAGE 28

G ( e ) = 0, a n d

G ( S
^ =
<Vui"(i.l>,i> h ( G (
Vl>,i>. W a
(i.D,i>

-1" G
<Vn,i> +
°< 'i>i+1

L e t t i n g G j = G(S| j) this becomes


h 1 >

Fisher's version of the algorithm for solving these equations first computes all of the
diameters D ( i , j ) a n d s t o r e s t h e m in an a r r a y , c o s t i n g O ( N ^ ) s t o r a g e . The algorithm below
c r e a t e s v e c t o r s S U M a n d S U M S Q , w h i c h e n a b l e the diameter to b e c o m p u t e d in 0 ( N ) s t o r a g e
at n o e x t r a e x p e n s e in time. ( T h i s trick d o e s not w o r k f o r ail d i a m e t e r f u n c t i o n s , t h o u g h . )
PAGE 29

A l g o r i t h m f o r C o n s t r u c t i n g an Optimal K - P a r t i t i o n w i t h the Sum of S q u a r e s


A b o u t the M e a n Diameter Function

I n p u t : X « N - t u p l e o f r e a l s , K = no. of s e t s in the p a r t i t i o n .
O u t p u t : A r r a y G s u c h t h a t G ( h , j ) = minimum cost f o r p a r t i t i o n i n g x j X 2 . » X j i n t o h sets
c o n s e c u t i v e elements. A r r a y H s u c h that H(h,j) = s u b s c r i p t k f o r t h e h'th
s e t o f t h e o p t i m a l p a r t i t i o n of x^x^y-y
T i m e : 0 ( K N ) , S t o r a g e : 0<KN)
2

/ Define statement function;


D(I,J) = (SUMSQ(J> - S U M S Q ( I - l ) ) - (SUM(J) - S U M ( I - l ) ) 2
/ ( J - I + 1)
/ Compute partial sums and sums of squares of X(I\)
S U M ( O ) <- S U M S Q ( O ) <- 0;
F o r J <- 1 t h r u N d o
begin
S U M ( J ) <- S U M ( J - l ) + X ( J ) ;
S U M S Q ( J ) <- S U M S Q ( J - l ) + X ( J ) * X ( J ) ;
G(1,J) «- D(1,J); H(1,J)«-J;
end;
/ Optimization;
F o r L <- 2 t h r u K d o / L = no. of sets in partition;
F o r J «- L t h r u N d o
M I N C O S T <- oo;
F o r I <- L - l t h r u J - l d o
begin
C O S T <- G ( L - 1 , I ) + D ( I + 1 , J ) ;
If C O S T < M I N C O S T t h e n
begin
MINCOST 4- COST;
G ( L , J ) <- C O S T ;
H(L,J) 4 - I;
end
end;

W e c a n f u r t h e r r e d u c e t h e s t o r a g e r e q u i r e d b y this a l g o r i t h m to 0 ( N ) . T o f i n d t h e cost o f the


optimal partition in 0 ( N ) s t o r a g e and 0 ( K N ) time is f a i r l y s i m p l e , b u t t h e r e c o v e r y
2
of the
o p t i m a l p a r t i t i o n i t s e l f ( w i t h i n t h e same time and s p a c e b o u n d s ) is m o r e d i f f i c u l t . First, we
c o n s i d e r f i n d i n g t h e cost o f t h e optimal p a r t i t i o n in 0 ( N ) s t o r a g e a n d 0 ( K N ) t i m e .
2

The only trick is t o eliminate unnecessary storage that is b e i n g used. The diameter
f u n c t i o n is a l r e a d y c o m p u t e d in 0 ( N ) s t o r a g e . O n l y the a r r a y G c o s t s 0 ( K N ) s t o r a g e . (Forget
a b o u t H f o r n o w s i n c e o n l y t h e optimal cost is b e i n g c o m p u t e d . ) B u t in t h e i n n e r t w o l o o p s of
t h e a b o v e a l g o r i t h m o n l y t h e v e c t o r s G ( l - 1 , * ) and G(L,*) are r e f e r e n c e d . T h a t i s , at s t a g e L
o n l y t h e v e c t o r s G ( L - 1 , * ) a n d G(L,*) a r e n e e d e d . T h u s , the K x N a r r a y G c a n b e r e p l a c e d by
t w o v e c t o r s o f l e n g t h N a n d t h e c o s t of t h e optimal p a r t i t i o n c a n b e c o m p u t e d in O ( N ) s t o r a g e
PAGE 30

a n d 0 ( K I \ n time.

The recovery o f t h e o p t i m a l p a r t i t i o n itself, r a t h e r than j u s t t h e c o s t , in 0 ( N ) s t o r a g e and


0<KN ) 2
time can be accomplished by combining divide - and - conquer with dynamic
programming. The method is similar to the a l g o r i t h m of H i r s c h b e r g [29] that s o l v e s the
l o n g e s t c o m m o n s u b s e q u e n c e p r o b l e m ( t o be d e s c r i b e d later in t h i s p a p e r ) in 0 ( N ) storage
a n d 0 ( N ) ti me.
2

R e c a l l t h a t t h e s t a t e S^j is i n t e r p r e t e d to mean " x ^ X 2 » . X j a r e p a r t i t i o n e d i n t o h s e t s of


consecutive e l e m e n t s . " D e f i n e a n e w set of s t a t e s S'^j that a r e i n t e r p r e t e d "xjXj + j . . . xjnj are
p a r t i t i o n e d i n t o h s e t s of c o n s e c u t i v e e l e m e n t s . " Let G'(h,i) = the minimum c o s t t o r e a c h s t a t e
S'hj. Also, assume for convenience that K is a power of 2. Here is how the
d i v i d e - a n d - c o n q u e r algorithm works:

1. C o m p u t e G ( K / 2 , i ) f o r all i in 0 ( K / 2 * N ) time and c o m p u t e G'(K/2,j) f o r all j in


2

0 ( K / 2 * N ) time f o r 0 ( K N ) total time.


2 2

2 . F i n d t h e s u b s c r i p t i that minimizes G(K/2,i) + G'(K/2,i + i ) . T h i s s u b s c r i p t i e q u a l s


t h e I « / 2 ' t h e K + i - t u p l e (Iq,I|,I2,...I|<) that r e p r e s e n t s t h e optimal p a r t i t i o n o f
n

the N elements.

3. N o w f i n d a n d I3K/4 b y a p p l y i n g s t e p s 1. and 2. to the r e s p e c t i v e


subproblems. ( T h i s is the d i v i d e s t e p - s o l v i n g t w o s u b p r o b l e m s o f half t h e
size.)

4. R e p e a t t h e d i v i d e s t e p of s t e p 3. T h a t is, find I|</g, l3K/8> *5K/8> * *7K/8> * * a n c e c

A f t e r l o g K i t e r a t i o n s w e will h a v e d e t e r m i n e d the e n t i r e optimal p a r t i t i o n .

T h e t o t a l t i m e t o r e c o v e r t h e optimal p a r t i t i o n may at first a p p e a r to be 0 ( K N * l o g K ) . 2


With
careful a n a l y s i s , h o w e v e r , w e can s h o w it to be o n l y 0 ( K N ) . 2
Let U(K,N) be the time to
c o n s t r u c t t h e o p t i m a l K - p a r t i t i o n of N elements and let T ( K , N ) = 0 ( K N ) b e t h e time t o f i n d t h e
2

cost of the optimal K-partitions f o r all the c l u s t e r s (1,N), ( 1 , N - 1 ) , ( l , N - 2 ) , e t c . The above


d i v i d e - a n d - c o n q u e r a l g o r i t h m leads to the f o l l o w i n g e q u a t i o n s :
PAGE 31

T(I,J) = I J 2

logK 2 ' 1 1

U(K,N> = I I [ 2 T
( | . W ' " Q-W->) l +
°( iM2'-'
I
" ^j-Dk/a-)]
l o g K [" 2 j l
"J

i=l L J = l 2' J
logK

< S |"o<> N +
-^T N1- 2
0(KN )2

T h e time U(K,N) d e p e n d s s o m e w h a t o n t h e optimal p a r t i t i o n (Iq,Ij,...I )


k b u t in t h e w o r s t case
t h e t o t a l t i m e is still 0 < K N ) .
2
PAGE 32

7 . O p t i m a l Matching Problems

One of the major differences between optimal matching problems and optimal
p a r e n t h e s i z a t i o n o r p a r t i t i o n p r o b l e m s is that i n s t e a d of j u s t o n e s t r i n g of e l e m e n t s , t w o (or
m o r e ) are involved. T h e a u t h o r K n o w s of t w o p r o b l e m s in this class. The first, and most
i m p o r t a n t , is t h e l o n g e s t c o m m o n s u b s e q u e n c e ( L C S ) p r o b l e m ( a n d its v a r i a t i o n s ) , f o r which
DP produces a g o o d (if n o t o p t i m a l ) algorithm. T h e s e c o n d p r o b l e m is t h e g a m e o f N I M , f o r
w h i c h a m u c h f a s t e r a l g o r i t h m is k n o w n and thus will not be d e s c r i b e d f u r t h e r [ 2 1 ] . We will
n o w describe the LCS problem.

L e t Y = y 1Y2 • • • N y a n c
* ^ - z
i 2 • • •
z
be * w 0 s t r
' S
n s
°* l e n g t h N w h o s e e l e m e n t s y- f and
Zj a r e c h o s e n f r o m a finite alphabet ALPH. ( T h e s t r i n g s Y and Z a r e c h o s e n t o b e t h e s a m e
length only for c o n v e n i e n c e in p r e s e n t a t i o n . ) A s t r i n g B is a subsequence o f Y if B c a n be
o b t a i n e d b y d e l e t i n g c h a r a c t e r s f r o m Y. F o r e x a m p l e , if Y = "dyanamic p r o g r a m m i n g " , t h e n B =
" m a i n " is a s u b s e q u e n c e of Y. T h e l o n g e s t common s u b s e q u e n c e p r o b l e m ( f o r t h e t w o strings
Y a n d Z ) is t o f i n d t h e ( n o t n e c e s s a r i l y u n i q u e ) l o n g e s t s t r i n g B that is a s u b s e q u e n c e o f b o t h
Y a n d Z.

T h e L C S p r o b l e m c a n b e s o l v e d in 0 ( N ) time and s p a c e [ 2 9 ] .
2
The string editing p r o b l e m , a
g e n e r a l i z a t i o n o f t h e L C S p r o b l e m , is to d e t e r m i n e the minimum n u m b e r of c h a n g e s , i n s e r t i o n s ,
o r d e l e t i o n s t o t r a n s f o r m a s t r i n g Y to a s t r i n g Z. T h i s p r o b l e m c a n also b e s o l v e d in 0(N ) 2

time and space [73]. T h e r e h a v e b e e n s e v e r a l e f f o r t s to i m p r o v e t h e s e a l g o r i t h m s and/or


'-how lower bounds for the problems. Hirschberg [29] reduced the s p a c e for the LCS
problem from 0(N ) 2
to 0(N) while maintaining the b o u n d of 0 ( N ) 2
time. Paterson [55]
produced a n 0 ( N l o g l o g N / l o g N ) time algorithm f o r the LCS p r o b l e m [ 3 0 ] ) , w h i c h M a s e k
2
and
Paterson [52] have recently i m p r o v e d to 0 ( N / l o g N )
2
time w i t h t h e i r s o l u t i o n t o t h e string
editing problem. H u n t a n d S z y m a n s k i [ 3 5 ] h a v e c o n s t r u c t e d an a l g o r i t h m t h a t s p e n d s 0 ( ( R + N )
l o g N ) time w h e r e R is t h e total n u m b e r of pairs of c h a r a c t e r s at w h i c h t h e t w o sequences
match. T h u s , R m a y b e as l a r g e as N 2
but if it is small, t h e n t h e a l g o r i t h m t a k e s o n l y 0(N
l o g N ) time. W o n g a n d C h a n d r a [ 7 4 ] s h o w e d an fl(N )
2
l o w e r (time) b o u n d of t h e s t r i n g editing
problem for a model of computation allowing o n l y equal / u n e q u a l c o m p a r i s o n s between
e l e m e n t s of strings. A h o , H i r s c h b e r g , and Ullman [ 1 ] s h o w e d t h e ft(N ) 2
lower bound for the
LCS problem (with only equal / unequal comparisons). Hirschberg [ 3 1 ] has p r o d u c e d an
O(NlogN) lower bound for the LCS problem where less-than-or-equal comparisons are
allowed. Hirschberg [30] provides an o v e r v i e w of the r e s u l t s for the LCS and related
p r o b l e m s a n d S e l k o w [ 6 5 ] d e s c r i b e s an e x t e n s i o n of t h e s e s t r i n g p r o b l e m s t o t r e e s . Itakura
[41] gives an interesting a p p l i c a t i o n of the L C S p r o b l e m to s p e e c h r e c o g n i t i o n . Fitch and
M a r g o l i a s h [ 1 8 ] a p p l y t h e s t r i n g e d i t i n g p r o b l e m to d e t e r m i n a t i o n o f t h e m u t a t i o n d i s t a n c e of
t h e D N A of s e v e r a l species.
PAGE 33

W e w i l l n o w p r e s e n t t h e 0 ( N ) time and 0 ( N ) s p a c e a l g o r i t h m f o r t h e L C S p r o b l e m .
2 2
The
t w o s t r i n g s a r e , as b e f o r e , Y and Z, e a c h c o n s i s t i n g of N c h a r a c t e r s f r o m t h e a l p h a b e t ALPH.
T h e D D P D - ( A , S , P, f ) is d e f i n e d b y

A = { ajj } w h e r e aj j c o m p a r e s y j and Z j f o r e q u a l i t y ,

S = { e } U { a j | i,j < N } U { x a j j a j I x « S and i<k and ]<L }, /


} k The subscripts of
the a — must be strictly increasing.;

P = { 2 * N - t u p l e s o f e l e m e n t s in the a l p h a b e t A L P H }, and

f ( e ) = 0 , f ( a j j ) = C ( y j , Z j ) , f ( x a j j a ) = f(xajj> + C ( y j , Z j ) f o r x € A L P H * a n d i<k a n d j<Z,


w

w h e r e C ( y j , z j > = 1 if y j = Z j and C ( y j , Z j ) = 0 o t h e r w i s e .

Note that the cost function f is w r i t t e n s o that t h e o b j e c t ' is t o maximize f rather than
m i n i m i z e it. L e t t h e s t a t e s o f t h e SDP b e w r i t t e n Sjj and be i n t e r p r e t e d " ( y i , y 2 > — Y j ) h a s been
compared with (Z|Z2-..Zj) by a sequence ending in a j j . " T h u s , t h e S D P is W = ( V , P, h , k )
where

V = ( A , Q , q , F, X ) w h e r e
Q

A « s a m e as f o r t h e DDP,

Q = { Sjj | i,j = 1,2,...N } u { S 0 0 },

^ 0 oo> = s

F = { S N N },

X<Sjj,3 K Z > = S k / for k>i, Z>j,

P = s a m e as f o r t h e D D P ,

h ( r , S j j , a ) = r + C ( y , z j ) f o r i<k, j<Z, and


k i k

k(p) = 0.

T h e S D P is m o n o t o n e b y a d d i t i v i t y of the cost f u n c t i o n . Thus, the functional equations are

G(S 0 0 ) = 0 , and

G ( S
ii> =
{ ( S ^ ) | K <i and K j J
m 3 G ( S
M> + C
^i' i>-
z

This gives an 0 ( N ) 4
time a l g o r i t h m . H o w e v e r , a monotone p r o p e r t y of the f u n c t i o n G c a n
minimize the search for max in the e q u a t i o n a b o v e . Since t h e s u b s c r i p t s of the ajj are
r e q u i r e d t o b e s t r i c t l y i n c r e a s i n g in e a c h legal s e q u e n c e of c o m p a r i s o n s , it f o l l o w s t h a t

If i < k and j < /, t h e n G ( S j j ) < G(S />. k

T h u s , t o f i n d G ( S j j ) it is s u f f i c i e n t to c o m p u t e
PAGE 34

G( S j j ) = max ( [™* * S K ( h l ) ) ] , [ ™ G(S , ( 1 ) > k )] ) + C(y.^.

T h e t i m e is n o w r e d u c e d t o O ( N ^ ) but f u r t h e r i m p r o v e m e n t is p o s s i b l e . T h e max(k<i) and the


max(k<j) can be propagated throughout the c o m p u t a t i o n of all G ( S j j ) s o t h a t o n l y constant
time per state Sjj is required. One way to do this is to c r e a t e an array MAXG(iJ) to
propagate these max's. Let G(i,j) = G(Sjj). When G(i,j) is d e f i n e d , p r o p a g a t e the max's
t h r o u g h the steps

G ( i , j ) <- M A X G ( i - l , j - l ) + C ( y j , z : )
M A X G ( i J ) <- G ( i , j )
M A X G ( i + l , j ) <- max( M A X G ( i + l , j ) , G(i,j) )
M A X G ( i , j + l ) <- max( M A X G ( i , j + l ) , G(i,j) ).

A n o t h e r w a y t o a c c o m p l i s h t h e p r o p a g a t i o n is to make a small c h a n g e in t h e d e f i n i t i o n o f G
so t h a t it a c c o m p l i s h e s t h e same task as M A X G , thus s a v i n g o n e a r r a y [ 2 9 ] . T h i s is w h a t is
d o n e in t h e f o l l o w i n g algorithm.

A l g o r i t h m f o r t h e L o n g e s t C o m m o n S u b s e q u e n c e of T w o S t r i n g s

I n p u t : i n t e g e r N > 0, a r r a y s Y [ 1 : N ] , Z[1:N]
O u t p u t : A r r a y G s u c h t h a t G ( I , J ) = l e n g t h of longest common s u b s e q u e n c e o f (yj,y2>—Yj)
and (zj,Z2,.»Zj). ^rray H s u c h that H(I,J) = p o i n t e r to e i t h e r ( I , J - 1 ) o r
( I - 1 , J ) , w h i c h e v e r has the l a r g e s t v a l u e of G.
Time: 0(N >, Storage: 0(N )
2 2

/ initialization;
F o r I <r- 0 t h r u N d o
F o r J 4- 0 t h r u N do
G ( I , J ) <- H(I,J) 4 - 0;
/ optimization;
F o r I <- 1 t h r u N do
F o r J «- 1 t h r u N do
begin
If Y ( I ) = Z ( J ) t h e n
G(I,J) G(I-1,J-1) + 1
else
G ( I , J ) <- max( G ( I , J - 1 ) , G ( I - 1 , J ) );
If G ( I , J - 1 ) > G ( I - 1 , J ) t h e n
H ( I , J ) <- ( I , J - 1 )
else
H ( I , J ) «- ( I - 1 . J )
end;
PAGE 35

G B A B B A H B A B B A
A 0 1 1 1 1 A 0,0 0,0 1,2 1,3 1,4
B A B B A B 1 1 2 2 2 B 0,0 2,1 2,2 2,3 2,4
\\\ I
A B A B A A 1 2 2 2 3 A 2,1 3,1 3,2 3,3 3,4
B 1 2 3 3 3 B 3,1 3,2 4,2 4,3 4,4

1 2 3 3 4 A 4,1 4,2 4,3 5,3 5,4


A

F i g u r e 7 - 1 : T h e m a t r i c e s G and H p r o d u c e d f o r the s t r i n g s A B A B A a n d B A B B A .
PAGE 36

8 . ' H a r d Combinatorial Problems


1

T h e p r o b l e m s d e s c r i b e d in t h e p r e v i o u s s e c t i o n s can all be s o l v e d in 0 ( N ) , O ( N ^ ) , o r
2
more
g e n e r a l l y t i m e t h a t is b o u n d e d a b o v e b y a p o l y n o m i a l in N. T h e p r o b l e m s in t h i s s e c t i o n h a v e
n e v e r b e e n s o l v e d in l e s s t h a n 0 ( 2 ^ ) time. M a n y of t h e s e p r o b l e m s a r e N P - C o m p l e t e [ 4 3 , 2 ] .
( T h e o t h e r p r o b l e m s a p p e a r to be at least this hard.) F o r p r o b l e m s w h e r e a n a i v e algorithm
c o s t s 0 ( N ! ) t i m e , D P c a n t y p i c a l l y b r i n g an i m p r o v e m e n t to 0 ( P ( N ) * 2 ) time w h e r e P ( N ) is a
N

p o l y n o m i a l in N. F o r e x a m p l e , the t r a v e l i n g s a l e s p e r s o n p r o b l e m ( T S P ) r u n s in t i m e 0(N^2'v
[28, 6]. An improved DP algorithm for the TSP and knapsack problems that utilizes
b r a n c h - a n d - b o u n d is d e s c r i b e d b y M o r i n [ 5 3 ] . C o n s t r u c t i n g optimal d e c i s i o n t r e e s f r o m a s e t
o f y e s / n o t e s t s is N P - c o m p l e t e [ 3 7 ] and the DP algorithm r u n s in 0 ( 3 ^ ) time a n d s p a c e [ 6 4 ] .
( L e w [ 5 0 ] d e s c r i b e s a s o l u t i o n to a g e n e r a l i z a t i o n of this p r o b l e m . ) B a y e s [ 4 ] d e s c r i b e s a d i s k
f i l e p l a c e m e n t p r o b l e m - a v a r i a t i o n of the module placement p r o b l e m in K a r p a n d H e l d [ 4 4 ] -
f o r w h i c h a D P a l g o r i t h m s p e n d s 0 ( 2 ) time and 0 ( C ( N , N / 2 ) ) s t o r a g e .
N
Kohler and Steiglitz [49]
and Kohler [48] describe DP ( a n d b r a n c h - a n d - b o u n d ) s o l u t i o n s of N P - C o m p l e t e scheduling
problems. G i l m o r e [ 2 3 ] s h o w s interconnections b e t w e e n cutting stock, linear programming,
k n a p s a c k i n g , d y n a m i c p r o g r a m m i n g , and i n t e g e r p r o g r a m m i n g . Shapiro [67] s h o w s h o w the
knapsack problem can be reduced to a (huge) shortest path problem, and Lloyd [51]
d e s c r i b e s a D P a l g o r i t h m f o r t h e minimum w e i g h t t r i a n g u l a t i o n p r o b l e m .

There a r e f a r t o o m a n y p r o b l e m s to d e s c r i b e them all in full d e t a i l . But to g i v e s o m e of


t h e f l a v o r o f w h a t a DP a l g o r i t h m f o r this t y p e of p r o b l e m c a n b e like, w e w i l l n o w describe
t h e t r a v e l i n g salesperson (TSP) problem.

The s a l e s p e r s o n must t r a v e l to e a c h of N cities, s t a r t i n g and e n d i n g at c i t y n u m b e r one.


The distances Djj between the cities are given. The p r o b l e m is to f i n d t h e route with
minimum total distance traveled. T h e n a i v e s o l u t i o n is to s i m p l y c o m p a r e all ( N - l ) ! possible
r o u t e s a n d c h o o s e t h e minimum. Use of a DP a l g o r i t h m , h o w e v e r , c a n r e d u c e t h i s t o CXN^^)
time.

The f i r s t s t e p in c o n s t r u c t i o n of the DP algorithm is to d e f i n e t h e D D P D = ( A , S , P, f )


where

A = { aj } w h e r e aj means "go to c i t y i",

S = { p e r m u t a t i o n s o f t h e aj e n d i n g in a^ },

P =* { m a t r i c e s Djj | Djj > 0, Vi,j }, and

f ( e ) = 0, f ( ) = D
a j u> f ( x a j a j ) = f ( x a j ) + Djj.

T o c o n s t r u c t t h e S D P w e must f i r s t d e f i n e the s t a t e s . It is t e m p t i n g to let t h e s t a t e s b e Sj


w h e r e Sj is i n t e r p r e t e d "at c i t y i". B u t since w e must t r a v e l to all o f the N c i t i e s , n o t j u s t t h e
PAGE 37

c l o s e s t o n e , this won't w o r k . I n s t e a d , w e must c o n s i d e r the cities a l r e a d y v i s i t e d b y t h e t i m e


the salesperson r e a c h e s c i t y i. Let C = { cities } = { 1, 2, 3 , . . . N }. If M is a s u b s e t o f C
r e p r e s e n t i n g t h e c i t i e s t h a t h a v e b e e n v i s i t e d b y the s a l e s p e r s o n a n d i £ M is t h e c i t y where
t h e s a l e s p e r s o n is c u r r e n t l y l o c a t e d , t h e n t h e s t a t e is Sj^jj. W i t h t h i s d e f i n i t i o n t h e S D P is
W - ( Z, P, h, k > w h e r e

Z = ( A , Q , q , F, \ ) w h e r e
Q

A = s a m e as f o r t h e DDP,

Q - { S M > i | M c C and i (• M },

^0 = S
{1},1'
F
- « s , i }, c

x ( s
M,i' j a ) = S
Mu{j},j'

P = s a m e as f o r t h e D D P ,

h(r,S M > j , a j ) - r + D y , and

k(p) - 0.

M o n o t o n i c i t y o f t h e S D P f o l l o w s f r o m the a d d i t i v i t y of the cost f u n c t i o n . T h u s , the functional

equations are

G(S { 1 } ) » 0, and

G(S ,) = j
M
m n
G(S .
M { i } i J ) • D j f

H e r e is a n a l g o r i t h m t o s o l v e t h e functional e q u a t i o n s :
PAGE 38

A l g o r i t h m for T r a v e l i n g Salesperson Problem

I n p u t : " D i s t a n c e " m a t r i x D ( I , J ) , VI,J=1,...N


O u t p u t : ( L e t M b e a s u b s e t o f {1,2,...N}.) A r r a y G s u c h that G(M,I) = minimum c o s t
o f t r a v e l i n g t o t h e c i t i e s of M and ending at c i t y I. A r r a y H s u c h t h a t
H ( M , I ) = last c i t y r e a c h e d b e f o r e c i t y I in t h e optimal s u b t o u r c o r r e s p o n d i n g
to G(M,I).
T i m e : 0 ( N 2 ) , S t o r a g e : 0 ( N 2 ) ( T h e a n a l y s i s is in [ 2 8 ] . )
2 N N

/ MINIMIZE finds the best subtour for (M,ti)


p r o c e d u r e M I N I M I Z E * G , H, D, M, I )
begin
M I N C O S T « - oo;
F o r all J < M - { I } d o
begin
C O S T <- G ( M - { I } , J ) + D(J,I);
If C O S T < M I N C O S T t h e n
begin
G ( M , I ) <- M I N C O S T <- C O S T ;
H ( M , I ) *- J ;
end
end
end;

/ main routine;
! Initialization;
C « - { 2, 3 , 4, . . . N };
F o r I *- 1 t h r u N d o
G ( { I } , I ) «- D(1,I);
/ Optimization;
F o r K « - 2 t h r u N - l d o / K = size of subsets;
F o r all M c C s u c h that |M| = K do
F o r all I c M d o
MINIMIZE(G,H,DMI)j
MINIMIZE(G,HACu {!},!);
PAGE 39

9. C o n c l u s i o n
D y n a m i c P r o g r a m m i n g is a u s e f u l p r o b l e m s o l v i n g m e t h o d f o r many p r o b l e m s in c o m p u t e r
science. I n t h i s p a p e r w e h a v e d e s c r i b e d p r o b l e m s in s e v e r a l c a t e g o r i e s o f D P : Shortest
Path Problems, Optimal Parenthesization Problems, Optimal Partition Problems, Optimal
Matching P r o b l e m s , and ' H a r d ' Combinatorial Problems. T h e a p p r o a c h t a k e n in t h i s paper
t o w a r d s o l u t i o n o f t h e s e p r o b l e m s is a modification of the t r e a t m e n t in K a r p a n d H e l d [ 4 4 ] .
E a c h a n a l y s i s o f a p r o b l e m p r o c e e d s in the f o l l o w i n g s t e p s :

1. P r o d u c e t h e d i s c r e t e d e c i s i o n p r o c e s s f o r the p r o b l e m ,

2 . D e c i d e w h a t a r e t h e r e l e v a n t states and c o n s t r u c t the c o r r e s p o n d i n g sequential


decision process,

3. Check the monotonicity conditions and (if satisfied) produce the functional
equations, and

4. F r o m t h e f u n c t i o n a l e q u a t i o n s c o n s t r u c t a d y n a m i c p r o g r a m m i n g algorithm that
solves the problem.

In this paper we have also p r e s e n t e d n e w p r o b l e m s and r e s u l t s i n c l u d i n g optimizing the


s e a r c h f o r N o r d e r s t a t i s t i c s and a more s p a c e e f f i c i e n t v e r s i o n of F i s h e r ' s a l g o r i t h m f o r an
optimal partition.

Acknowledgments

Jon Bentley s u g g e s t e d d y n a m i c p r o g r a m m i n g as t h e topic f o r my a r e a q u a l i f i e r and has


g i v e n n u m e r o u s h e l p f u l c o m m e n t s that h a v e i m p r o v e d the q u a l i t y o f t h i s p a p e r .
PAGE 40

References

[I] A . V . A h o , D.S. H i r s c h b e r g , and J.D. Ullman, Bounds on the Complexity of the Longest
Common Subsequence Problem, J . A s s o c . C o m p . Mach., 23 ( 1 9 7 6 ) , p p . 1 - 1 2 .

[2] A . V . A h o , J . H o p c r o f t , a n d J.D. Ullman, The Design and Analysis of Computer


Algorithms, A d d i s o n - W e s l e y , Reading, Mass., 1974. C o n s t r u c t i n g o p t i m a l b i n a r y
s e a r c h t r e e , pp. 119-123..

[3] J . K . B a k e r , The DRAGON System - An Overview, I E E E T r a n s . A c o u s t . S p e e c h S i g n a l


P r o c e s s . , A S S P - 2 3 (1975), pp. 24-29.

[4] A . J . B a y e s , The Optimised Placing of Files on Disk Using Dynamic Programming,


O p t i m i z a t i o n , R.S. A n d e r s s e n , L S . J e n n i n g s , and D M R y a n , e d . , U n i v e r s i t y o f
Q u e e n s l a n d P r e s s , St. L u c i a , Q u e e n s l a n d , 1972, p p . 1 8 2 - 1 8 6 .

[5] R. B e l l m a n , Dynamic Programming, Princeton University Press, Princeton, N e w


J e r s e y , 1957.

[6] R. B e l l m a n , On a routing problem, Q u a r t . A p p l . Math., 16 ( 1 9 5 8 ) , p p . 8 7 - 9 0 .

[7] M. B l u m , R.W. F l o y d , V . R . P r a t t , R.L. R i v e s t , and R.E. T a r j a n , Time bounds for selection,


J . C o m p u t . S y s t e m Sci., 7 ( 1 9 7 2 ) , p p . 4 4 8 - 4 6 1 .

[8] D.W. B o y d , Long Division: An Example of Dynamic Programming, Amer. Inst. Indust.
E n g i n . T r a n s . , volume (1974), pp. 365-366.

[9] C . C a f f o r i o a n d F. R o c c a , Methods for Measuring Small Displacements of Television


Images, IEEE Trans. Information T h e o r y , I T - 2 2 (1976), pp. 5 7 3 - 5 7 9 .

[10] F.Y. C h i n , An 0(N) Algorithm for Determining a Near-Optimal Computation Order of


Matrix Chain Products, Comm. A C M , 21 ( 1 9 7 8 ) , p p . 5 4 4 - 5 4 9 .

[II] G . B . D a n t z i g , Linear Programming and Extensions, Princeton University Press,


P r i n c e t o n , N e w J e r s e y , 1963.

[12] E.W. D i j k s t r a , A Note on Two Problems in Connection With Graphs, Numer. Math., 1
(1959), pp. 269-271.

[13] S . E . D r e y f u s and A . M . L a w , The Art and Theory of Dynamic Programming, Academic


P r e s s , N e w Y o r k , 1977.

[14] G . T . D u n c a n , Optimal Diagnostic Questionnaires, O p e r a t i o n s Res., 23 ( 1 9 7 5 ) , p p .


22-32.

[15] J . E a r l y , An efficient context-free parsing algorithm, Comm. A C M , 13 ( 1 9 7 0 ) , p p .


94-102.

[16] M.A. F i s c h l e r and R.A. E l s c h l a g e r , The Representation and Matching of Pictorial


Structures, IEEE Trans. Computers, C - 2 2 (1973), pp. 67-92.

[17] W . D . F i s h e r , On grouping for maximum homogeneity, J . Amer. Statist. Assoc., 5 3


(1958), pp. 789-798.

[18] W . M . F i t c h a n d E. M a r g o l i a s h , Construction of Phylogenetic Trees, S c i e n c e , 155 ( 1 9 6 7 ) ,


pp. 279-284.
PAGE 41

[19] G . D . F o r n e y J r . , The Viterbi Algorithm, P r o c . I E E E , 61 ( 1 9 7 3 ) , p p . 2 6 8 - 2 7 8 .

[20] M.L. F r e d m a n , On the Decision Tree Complexity of the Shortest Path Problems, 1 6 t h
A n n u a l S y m p o s i u m o n F o u n d a t i o n s of C o m p u t e r S c i e n c e , I E E E , L o n g B e a c h , C A . , O c t . ,
• 1975, p p . 9 8 - 9 9 .

[21] M. G a r d n e r , Concerning the game of nim and its mathematical analysis* Mathematical
G a m e s s e c t i o n of S c i e n t i f i c A m e r i c a n , 198 ( 1 9 5 8 ) , p p . 1 0 4 - 1 1 1 .

[22] E.N. G i l b e r t a n d E.F. M o o r e , Variable length encodings, Bell S y s t e m T e c h . J . , 3 8 ( 1 9 5 9 ) ,


pp. 933-968.

[23] P. G i l m o r e , Catting stock, Linear Programming, knapsacking, Dynamic Programming*


Integer Programming: some interconnections, T e c h . Rep. R C 6 5 2 8 ( 2 8 1 8 8 ) , I B M
T J . W a t s o n R e s e a r c h C e n t e r , Y o r k t o w n Heights, N e w Y o r k , S e p t 1 9 7 7 . 3 3 p a g e s .

[24] S . L . G r a h a m , M.A. H a r r i s o n , and W.L. R u z z o , On Line Context Free Language


Recognition in Less Than Cubic Time, 8 t h A n n u a l A C M S y m p o s i u m o n T h e o r y o f
C o m p u t i n g , A s s o c . C o m p u t . Mach. Special I n t e r e s t G r o u p o n A u t o m a t a a n d C o m p u t i n g
T h e o r y , N e w Y o r k , M a y , 1976, p p . 1 1 2 - 1 2 0 .

[25] I I. G u i b a s , H.T. K u n g , and C D . T h o m p s o n , Direct VLSI Implementation of


Combinatorial Algorithms, C o n f e r e n c e o n V e r y L a r g e Scale I n t e g r a t i o n , I n d u s t r i a l
A s s o c i a t e s , C a l i f o r n i a I n s t i t u t e of T e c h n o l o g y , J a n . , 1979,

[26] F. H a r a r y , Graph Theory, A d d i s o n - W e s l e y Publishing C o m p a n y , R e a d i n g , M a s s . , 1 9 6 9 .

[27] J . A . H a r t i g a n , Clustering Algorithms, John Wiley & Sons, New York, 1975. Fisher
Algorithm on pages 130-140.

[28] M. H e l d a n d R.M. K a r p , A Dynamic Programming Approach to Sequencing Problems,


J . S I A M , 10 ( 1 9 6 2 ) , p p . 1 9 6 - 2 1 0 .

[29] D.S. H i r s c h b e r g , A Linear Space Algorithm for Computing Maximal Common


Subsequences, C o m m . A C M , 18 ( 1 9 7 5 ) , p p . 3 4 1 - 3 4 3 .

[30] D.S. H i r s c h b e r g , Complexity of Common Subsequence Problems, Springer-Verlag, New


Y o r k , 1977. L e c t u r e N o t e s in C o m p u t e r Science,No. 5 6 , F u n d a m e n t a l s o f C o m p u t a t i o n
Theory.

[31] D.S. H i r s c h b e r g , An information - theoretic lower bound for the longest common
subsequence problem, I n f o r m a t i o n P r o c e s s i n g Lett., 7 ( 1 9 7 8 ) , p p . 4 0 - 4 1 .

[32] J . E . H o p c r o f t a n d J . D . Ullman, Formal Languages and Their Relation to Automata,


A d d i s o n - W e s l e y , R e a d i n g , Mass., 1969.

[33] T . C . H u , A new proof of the T - C algorithm, S I A M J . A p p l . M a t h . , 25 ( 1 9 7 3 ) , p p .


83-94.

[34] D.A. H u f f m a n , A Method for the Construction of Minimum Redundancy Codes, Proc.
Inst. Radio Engin., 40 (1952), pp. 1098-1101.

[35] J . W . H u n t a n d T . G . S z y m a n s k i , A Fast Algorithm for Computing Longest Common


Subsequences, C o m m . A C M , 20 ( 1 9 7 7 ) , p p . 3 5 0 - 3 5 3 .
PAGE 42

[36] T . C . H u a n d A . C . T u c k e r , Optimum Binary Search Trees, S I A M J . A p p l . M a t h . , 21


(1971), pp. 514-532.

[37] L. H y a f i l a n d R.L. R i v e s t , Constructing Optimal Binary Decision Trees is NP-Complete,


I n f o r m a t i o n P r o c e s s i n g Lett., 5 (1976), pp. 15-17.

[38] T . I b a r a k i , Minimal Representations of Some Classes of Dynamic Programming,


I n f o r m a t i o n a n d C o n t r o l , 27 ( 1 9 7 5 ) , p p . 2 8 9 - 3 2 8 .

[39] T . I b a r a k i , Branch-and-bound procedure and state-space representation of


combinatorial optimization problems. I n f o r m a t i o n and C o n t r o l , 3 6 ( 1 9 7 8 ) , p p . 1 - 2 7 .

[40] A . I t a i , Optimal alphabetic trees, S I A M J . C o m p u t . , 5 ( 1 9 7 6 ) , p p . 9 - 1 8 .

[41] F. I t a k u r a , Minimum Prediction Residual Principle Applied to Speech Recognition,


I E E E T r a n s . A c o u s t . S p e e c h Signal P r o c e s s . , A S S P - 2 3 ( 1 9 7 5 ) , p p . 6 7 - 7 2 .

[42] D.B. J o h n s o n , Algorithms for shortest paths, Ph.D. T h e s i s , D e p t . of C o m p u t e r S c i e n c e ,


C o r n e l l U n i v e r s i t y , I t h a c a , N e w Y o r k , 1973. C i t e d in A h o , H o p c r o f t , a n d U l l m a n .

[43] R.M. K a r p , Reducibility among combinatorial problems, C o m p l e x i t y of C o m p u t e r


C o m p u t a t i o n s , M i l l e r a n d T h a t c h e r , e d . , Plenum P r e s s , N e w Y o r k , 1 9 7 2 , p p . 8 5 - 1 0 4 .

[44] R.M. K a r p a n d M. H e l d , Finite-State Processes and Dynamic Programming, SIAM


J . A p p l i e d M a t h , 15 ( 1 9 6 7 ) , p p . 6 9 3 - 7 1 8 .

[45] T . K a s a m i a n d K. T o r i i , A syntax-analysis procedure for unambiguous context-free


grammars, J . A s s o c . C o m p . Mach., 16 ( 1 9 6 9 ) , p p . 4 2 3 - 4 3 1 .

[46] D.E. K n u t h , Optimal Binary Search Trees, A c t a Informat., 1 ( 1 9 7 1 ) , p p . 1 4 - 2 5 .

[47] D.E. K n u t h , Sorting and Searching, A d d i s o n - W e s l e y , R e a d i n g , Mass., 1 9 7 3 . Algorithm


f o r b i n a r y s e a r c h t r e e in S e c t i o n 6.2.2.

[48] W . H . K o h l e r , Computational Experience with Efficient Exact and Approximate


Algorithms for an NP-Complete Scheduling Problem, P r o c e e d i n g s o f t h e N i n t h H a w a i i
I n t e r n a t i o n a l C o n f e r e n c e o n S y s t e m S c i e n c e s , U n i v e r s i t y of H a w a i i , M a n o a , 1 9 7 6 , p p .
11/- 1 1 o

[49] W . H . K o h l e r a n d K. S t e i g l i t z , Enumerative and Iterative Computational Approaches,


C o m p u t e r a n d J o b - S h o p S c h e d u l i n g T h e o r y , E.G. C o f f m a n , J r . , e d . , J o h n W i l e y & S o n s ,
N e w Y o r k , 1976, pp. 2 2 9 - 2 8 7 .

[50] A . L e w , Optimal Conversion of Extended-Entry Decision Tables with General Cost


Criteria, C o m m . A C M , 21 ( 1 9 7 8 ) , p p . 2 6 9 - 2 7 9 .

[51] E.L. L l o y d , On triangulations of a set of points in the plane, 18th A n n u a l S y m p o s i u m


o n F o u n d a t i o n s o f C o m p u t e r S c i e n c e , IEEE, Long B e a c h , C A , 0 c t . 3 1 - N o v . 2 , 1 9 7 7 , p p .
228-240. A l s o a v a i l a b l e as M I T T e c h n i c a l R e p o r t M I T / L C S / T M - 8 8 .

[52] W . J . M a s e k a n d M.S. P a t e r s o n , A Faster Algorithm Computing String Edit Distances,


T e c h . Rep. M I T / L C S / T M - 1 0 5 , MIT Laboratory for Computer Science, C a m b r i d g e , Mass.

[53] T . L . M o r i n , Branch and Bound Strategies for Dynamic Programming, Operations Res .
24 (1976), pp. 611-627.
PAGE 43

[54] V . Y . P a n , An introduction to the trilinear technique of aggregating, uniting and


cancelling and applications of the technique for constructing fast algorithms for
matrix operations,' P r o c e e d i n g s of the N i n e t e e n t h A n n u a l S y m p o s i u m o n t h e
F o u n d a t i o n s o f C o m p u t e r S c i e n c e , I E E E , Long B e a c h , C A , 1978,

[55] M.S. P a t e r s o n , U n i v e r s i t y of W a r w i c k , E n g l a n d .

[56] H J . P a y n e a n d W.S. M e i s e l , An Algorithm for Constructing Optimal Binary Decision


Trees, I E E E T r a n s . C o m p u t e r s , C - 2 6 ( 1 9 7 7 ) , p p . 9 0 5 - 9 1 6 .

[57] Y . P e r l , Average Analysis of Simple Path Algorithms, T e c h . R e p . U I U C D C S - R - 7 7 - 9 0 5


U I L U - E N G 7 7 1 7 5 9 , D e p t . of C o m p u t e r S c i e n c e , U n i v e r s i t y o f Illinois,
U r b a n a - C h a m p a i g n , N o v . 1977.

[58] J . L . P e t e r s o n , J.R. B i t n e r , and J.H. H o w a r d , The Selection of Optimal Tab Settings,


C o m m . A C M , 21 ( 1 9 7 8 ) , p p . 1 0 0 4 - 1 0 0 6 .

[59] I. P o h l , A sorting problem and its complexity, Comm. A C M , 15 ( 1 9 7 2 ) , p p . 4 6 2 - 4 6 4 .

[60] M. P o l l a c k a n d W. W i e b e n s o n , Solutions of the shortest route problem - A review,


O p e r a t i o n s Res., 8 ( 1 9 6 0 ) , p p . 2 2 4 - 2 3 0 .

[61] F.P. P r e p a r a t a and S.R. R a y , An approach to artificial symbolic cognition, Information


Sci., 4 (1972), pp. 6 5 - 8 6 .

[62] R.L. P r o b e r t , An Extension of Computational Duality To Sequences of Bilinear


Computations, S I A M J . Comput., 7 (1978), pp. 9 1 - 9 8 .

[63] A . S c h o n h a g e , M. P a t e r s o n , and N. P i p p e n g e r , Finding the median, J. Comput. System


S c i . , 13 ( 1 9 7 6 ) , p p . 1 8 4 - 1 8 9 .

[64] H. S c h u m a c h e r and K.C. S e v c i k , The Synthetic Approach to Decision Table Conversion,


C o m m . A C M , 19 ( 1 9 7 6 ) , p p . 3 4 3 - 3 5 1 . See also t h e T e c h n i c a l C o r r e s p o n d e n c e s e c t i o n
of the C . A C M 21(1978), pp. 179-180.

[65] S . M . S e l k o w , The tree-to-tree editing problem, I n f o r m a t i o n P r o c e s s i n g L e t t . , 6 ( 1 9 7 7 ) ,


pp. 184-186.

[66] M . I . S h a m o s , K.Q. B r o w n , J . S a x e , and B.W. W e i d e , C l u s t e r i n g in O n e D i m e n s i o n , I n


preparation.

[67] J . F . S h a p i r o , Shortest Route Methods for Finite State Space Deterministic Dynamic
Programming Problems, S I A M J . , 16 ( 1 9 6 8 ) , p p . 1 2 3 2 - 1 2 5 0 .

[68] R.E. T a r j a n , Complexity of Combinatorial Algorithms, S I A M R e v i e w , 2 0 ( 1 9 7 8 ) , p p .


457-491.

[69] M.E. T h o m a s , A Survey of the State of the Art in Dynamic Programming, Amer. Inst,
of Indust. Engin., 8 (1976), pp. 59-69.

[70] L . G . V a l i a n t , General Context-Free Recognition in Less than Cubic Time, J. Comput.


S y s t e m S c i . , 10 ( 1 9 7 5 ) , p p . 3 0 8 - 3 1 5 .

[71] A . J . V i t e r b i , Error bounds for convolutional codes and an asymptotically optimum


decoding algorithm, I E E E T r a n s . I n f o r m a t i o n T h e o r y , I T - 1 3 ( 1 9 6 7 ) , p p . 2 6 0 - 2 6 9 .
PAGE 44

[72] K M . W a g n e r , Principles of Operations Research, Prentice-Hall, E n g l e w o o d C l i f f s , N.J.,


1969.

[73] R.A. W a g n e r a n d M.J. F i s c h e r , The siring-to-string correction problem, J. Assoc. Comp.


M a c h . , 21 ( 1 9 7 4 ) , p p . 1 6 8 - 1 7 3 .

[74] C K . W o n g a n d A.K. C h a n d r a , Bounds for the String Editing Problem, J. Assoc. Comp.
Mach., 23 (1976), pp. 13-16.

[75] D.H. Y o u n g e r , Recognition and parsing of context-free languages, Infomation and


C o n t r o l , 10 ( 1 9 6 7 ) , p p . 1 8 9 - 2 0 8 .
UNCLASSIFIED llllSlffilllM ..... , 0 flM
SECURITY CLASSIFICATION O F T H I S P A G E (When Data Entered) I11 l|l 1 l|j ||i 1 If| || l| l|l 11|| 11| 1 If 1
1 11(I111 IfJ11 ||lfll f 1J11
REPORT DOCUMENTATION PAGE 3 fl4fl5 D ] i n pp ) m p l e t i n g N
f S
o r m

1. REPORT NUMBER 2. G O V T A C C E S S I O N ww. ^. . _ _ TALOG NUMBER

CMU-CS-79-106
5. TYPE OF REPORT & PERIOD COVERED
4. T I T L E (and Subtitle)

• Interim
DYNAMIC PROGRAMMING IN COMPUTER SCIENCE 6. PERFORMING ORG. REPORT NUMBER

8. CONTRACT OR GRANT NUMBERf*)


7. AUTHORS

Kevin Q. Brown N00014-76-C-0370

9. PERFORMING ORGANIZATION NAME AND ADDRESS 10. PROGRAM ELEMENT. PROJECT, TASK
A R E A 4 WORK U N I T N U M B E R S
Carnegie-Mellon University
Computer Science Department
Pittsburgh, PA 15213
11. CONTROLLING OFFICE NAME ANO ADORESS _ • 12. REPORT DATE

February 1979
Office of Naval Research
13. NUMBER OF PAGES
Arlington, VA 22217 •
49
14. MONITORING AGENCY N A M E & A D O R E S S f / / dltieront from Controlling Office) 15. SECURITY C L A S S , (of thla report)

UNCLASSIFIED
Same as above 15a. D E C L ASSI F l C A T I O N / DOWN G R A D I N G
SCHEDULE

16. DISTRIBUTION STATEMENT (of this Report)

Approved for.public release; distribution unlimited

17. DISTRIBUTION STATEMENT (of the abstract entered In Block 20, it different from Report)

18. SUPPLEMENTARY NOTES

19. KEY W O R D S (Continue on reverse aide if neceaeary and identify by block number)

20. A B S T R A C T (Continue on reverse aide it neceaeary and identify by block number)

DD i jan M
73 1473 E D I T I O N O F 1 N O V 6 5 IS O B S O L E T E UNCLASSIFIED
S/N 0102-014- 6601 | S E C U R I T Y C L A S S I F I C A T I O N O F T H I S P A G E (When Data Entered)

You might also like