Professional Documents
Culture Documents
Graph Prog Application
Graph Prog Application
LIST OF SYMBOLS
XI~ X2~ Operational elements
. .. ~ X~
a, ~, % . . . Decision elements
mij E l e m e n t of a c o n n e c t i o n m a t r i x
C = {ci} Set of i n s t r u c t i o n s d e p e n d e n t on a g i v e n condi-
tion
D = {d~.} Set of i n s t r u c t i o n s which cause a decision n o t to
hold
S =- {sk} Set of i n s t r u c t i o n s which set u p a c o n d i t i o n
e, e' A preset b i n a r y v a r i a b l e a n d its n e g a t i o n
P 1 , P~ A pair of p r o g r a m s to be c o m b i n e d
M 1 , M2 M a t r i c e s associated w i t h P1 a n d P2
M C o n n e c t i o n m a t r i x describing a composite pro-
gram
* This paper is derived from a dissertation submitted in partial fulfillment of
the requirements for the Ph.D. degree in applied mathematics at Harvard Uni-
versity, Cambridge, Massachusetts. This work was partially supported by Bell
Telephone Laboratories, Inc. through a contractual agreement with Harvard Uni-
versity.
179
180 ic~Rv
M S Revised form of M
p~. Conditional probability that Xj will follow X~-
N A vector of expected frequencies of elements
Ni The ith element of N
P The matrix (Pc')
Ti The execution time of X~
Ccy N~(1 - plj)
Xij One if X~- follows X~ in storage, zero otherwise
I. INTRODUCTION
In any discussion of a digital computer program, reference is inevitably
made to the "pattern of control" of the program, and to the "paths"
and "loops" which may be traversed in the course of the calculation.
The use of such descriptive terms indicates ~ widespread awareness of
the relevance to programming of the concepts of graph theory. It is
therefore surprising that these concepts have rarely been applied ana-
lytically to programs.
The desirability of such analysis was recognized as early as 1947,
when Goldstine and yon Neumann suggested the development of a
formal logic of programs, based on the flow diagram. Since that time,
however, progress in this area has been slow. A few writers (Blum, 1956;
Perlis and Smith, 1957; Janov, 1957a, b; and Voorhees, 1958) have sug-
gested interesting notations for describing the manner in which the vari-
ous sections of a program are connected together. The work of Janov
also contains some results on the equivalence transformations of pro-
grams.
In spite of the contributions of these writers, there remains a need for
a systematic study of the application of graph theory to digital computer
programming. A model suitable for such a study is developed in the
writer's doctoral thesis. This paper presents the essential features of this
model, and describes some of the applications which have been investi-
gated. A recent paper by Prosser (1959) employs Boolean matrices to
derive independently some of the results given in Section III of this
paper.
Ii. THE REPRESENTATION OF FLOWCHARTS AND PROGRAMS
The flowchart is a commonly used device for the representation of
algorithms. In the form considered here (see Fig. 1), it consists of an
arrangement of elements connected by directed ares. These elements
APPLICATION OF GRAPH THEORY TO PROGRAMMING 181
FIG. 1. A f l o w c h a r t
a; $ X5
I ~'1'~ 2 aX2 } ,B' '~ Y ~ 6 X6 7
TtX3
FIG. 2. G r a p h corresponding to t h e flowchart of Fig. 1
mij = al + a2 + . . . + a~.
The diagonal element m , is zero unless there exists an arc whose head
and tail meet at the node i.
0 X1 0 0 0 0 0
0 aX 2 0 0 0
~0 0 0 0 0
~' 0 o ~'
y'x 3 r o iI
0 0 0 0 5X 5 + 6~X4
0 0 0 0 0 X6 /
0 0 0 0 0 /
FIG. 3. A connection m a t r i x
A P P L I C A T I O N OF G R A P H T H E O R Y TO P R O G R A M M I N G 183
XtaX25
"y'Xa
Convenient procedures for enumerating the proper paths and proper
cycles of a connection matrix (or the corresponding directed graph)
have been given by Hohn et al. (1957) and by Lunts (1950). The avail-
ability of these procedures will be assumed.
M a n y properties desirable in a "good" flowchart m a y be expressed
in terms of the graph-theoretic concepts just introduced. The first such
property is called eligibility. A flowchart is said to be eligible if each of
its elements lies in a finite path from the initial node to some terminal
node. If a flowchart is ineligible, at least one of the following undesirable
conditions must hold:
1. There is an element which cannot be reached from the initial node,
and hence is totally redundant.
2. There is an element from which no path leads to a terminal node,
184 KARe
(a)
( b)
FIG. 5. A p a i r of p r o g r a m s to be c o m b i n e d
186 KARP
0 1 0 0 0 0 1 0 0
: a' 0 ~ : 13 I 0 , 8 0 0
M 1= 0 0 1 M2= 0 0 0 0 1
i 0 yl 0 o
° 0 0 0 o
0 0 0 0 0 0
FIG. 6. Matrices representing the structures of P1 and P2
Y
2. Construct a matrix M such that
(M)i~ = e(M1)~ + d ( M 2 ) ~ .
This matrix is shown in Fig. 7.
3. Form a matrix M* from M as follows:
(a) If (M),~. = e + g, (M*)i~ = 1
(b) If {E:} does not appear in some row of M delete all occurrences
/c~ ~-F~l o o o1
;!oo. ;1
,
M =
0 ~ 7 "l 0
0 0 0
0 1 0 0 0
e/~l E~ I E I/3 E~ Oi
M " 0 0 0 E •
t
0 0 )" 0 -
0 0 0 0
F i e . 8. R e v i s e d m a t r i x for a c o m p o s i t e p r o g r a m
~X43" X3
Removing the symbol e from these paths, and constructing the unique
eligible program which has the resulting proper path and proper cycles,
we obtain the program of Fig. 5a, as expected.
I F I o . 9. A c o m p o s i t e p r o g r a m
188 KARF
REFERENCES