A Programming Language
A Programming Language
E.
I \T E R SON
A Programming
Language
Copyright
lUG?
To My MallY Teachers
PREFACE
viii
Preface
Preface
ix
May,1962
Mount Kisco, New York
E.
IVERSON
CONTENTS
I ntrod uction, 1
1.2
Programs, 2
Conventions, 7
Arithmetic operations, 11
Logical operations, 11
Elementary operations, 13
Matrices, 14
Index systems, 14
1.6
Rotation, 14
1. 7
Special vectors, 15
1.8
Reduction, 16
1.9 Selection, 17
Compression, 17
1.12 Transpositions, 25
xi
Contents
xii
1.16 Ranking, 31
Reordering operations, 32
Permutations, 33
Function mapping, 34
Ordering vector, 36
1.18 Maximization, 36
1.21 Subroutines, 39
1.22 Files, 40
Directed graphs, 45
Ordered trees, 46
Well formation, 52
Homogeneous trees, 58
References, 62
Exercises, 62
Chapter 2 MICROPROGRAMMING
2.1 Instruction preparation, 72
Additive indexing, 73
Indirect addressing, 74
Dynamic relocation, 74
Branch instructions, 80
71
Contents
xiii
Logical instructions, 83
Arithmetic instructions, 84
Shift instructions, 85
Convert instructions, 87
Input-output instructions, 88
2.3
References, 103
Exercises, 103
105
Partitions, 115
Pools, 116
Sumnlary, 118
3.3
References, 128
Exercises, 129
133
Contents
4.3
xiv
References, 155
Exercises, 156
Chapter 5 METAPROGRAMS
5.1
5.2
5.3
159
notation, 169
notation, 173
References, 174
Exercises, 175
Chapter 6 SORTING
6.3
176
Contents
xv
References, 240
Exercises, 241
246
References, 262
Exercises, 263
SUMMARY OF NOTATION
265
INDEX
277
ILLUSTRATIONS
Program
Program
Program
Program
Program
Program
Program
1.1
1.2
1.3
1.4
1.5
1.6
1.7
Table 1.8
Program 1.9
Program 1. 10
Table 1. I I
Program 1. 12
Progranl 1. I3
Program I. 14
Progranl I. I5
Figure I. I 6
Figure 1.17
Finite program
2
lnfinite program
Program for :r == n 2/3
Matrix multiplication
4
9
Selection on ban k ledger L (Example I. I)
19
I nterfiling program
20
Il(T) == 26
45
(n, U)
Program 1.18
Table 1.19
Progranl 1.20
Program 1.2 I
Figure 1.22
Progranl 1.23
Figure 1.24
47
54
55
bet)
56
59
xvii
xviii
Illustrations
Figure 1.25
vectors
60
Table 2.1
PrograITI 2.2
Program 2.3
Program 2.4
Program 2.5
Program 2.6
Program 2.7
Program 2.8
Progran1 2.9
Program 2.10
Program 2.11
Progran1 2.12
Table 2.13
Table 2.14
Program 2.15
Program 2.16
Program 2.17
Program 2.18
Progranl 2.19
Program 2.20
Program 2.21
Figure 2.22
Indirect addressing
74
Logical operations
84
Add instructions
85
Shift instructions
86
Convert instructions
87
Channel operands
89
Channel i
93
Data paths
102
Figure 3.1 a
Figure 3.1 h
Representation of a vector x
107
107
of x
112
segments
114
representation of A
121
Figure 3.2
Progranl 3.3
Program 3.4
Program 3.5
Progranl 3.6
Progranl 3.7
Figure 3.8
Illustrations
xix
Program 3.9
Figure 3.10
Program 3.11
list matrix P
128
123
Program 3.12
Table 3.13
Program 3.14
Table 4.1
Figure 4.2
Program 4.3
Program 4.4
Figure 4.5
Figure 4.6
010, 120,001,022,202)
Figure 4.7
Program 4.8
Program 4.9
Program 5.1
Figure 5.2
Table 5.3
Program 5.4
Progranl 5.5
145
168
Program 5.6
Progranl 5.7
Program 5.8
notation
170
xx
Illustrations
Table 6.1
Figure 6.2
Figure 6.3
Prograll1 6.4
Program 6.5
Program 6.6
Prograll1 6.7
Program 6.8
Table 6.9
Table 6.10
Prograll1 6.11
rrable 6.12
Prograll1 6.13
Table 6.14
Table 6.15
Progran1 6.16
Progran1 6.17
Progran1 6.18
Progran1 6.19
Progran1 6.20
Progran1 6.21
Table 6.22
PrograIn 6.23
Progran1 6.24
Table 6.25
Progranl 6.26
'fable 6.27
Program 6.28
Progran1 6.29
Figure 6.30
Figure 6.31
Prograln 6.32
Prograln 6.33
Prograln 6.34
Progran1 6.35
Tahle 6.36
176
Table 6.9
193
An1phisbaenic sort
197
207
Bubble sort
218
219
Ranking sort
222
Ranking by insertion
222
tree
227
234
Illustrations
xxi
Table 6.37
Table 7.1
Table 7.2
Table 7.3
Table 7.4
Progranl 7.5
Table 7.6
chapter
THE LANGUAGE
1.1
INTRODUCTION
l.t
The language
t.2
PROGRAMS
+-- SIn
x.
z
v
+-
x 3.1416
v~vxx
Program 1.1
program
Finite
+-
z~yxz
z+-2xz
Program 1.2
progran1
Infinite
Thus Program 1.1 is a program of two statements defining the result l' as
the (approximate) area of a circle of radius :r~ whereas Program 1.2 is an
infinite program in which the quantity z is specified as (2y)n on the nth
execution of the two-statement loop. Statements will be numbered on the
left for reference.
A number of similar programs may be subsumed under a single more
general progranl as follows. At certain branch points in the program a
finite number of alternative statements are specified as possible successors.
One of these successors is chosen according to criteria determined in the
statelnent or statements preceding the branch point. These criteria are
usually stated as a comparison or test of a specified relation between a
specified pair of quantities. A branch is denoted by a set of arrows leading
to each of the alternative successors~ with each arrow labeled by the
1.2
Progranls
, - - - - - - - - - - ~3
+-
y x y
~4
+-
f31
{J2
+--
k -7 2
~ ~5
>
y +-71 - k
z : n
x x
<
--)'1
k+-kx2
y2
y+--y+k
(51
Program 1.3
1.2
The language
y
~O
~y
x y
z~yxx
>
z . n
k~kx2
y~y+k
k~k+2
y~y-k
Program 1.4
+-
peA)
+-
v(B)
C/ ~O
C/ ~ Cji + Aki
k~k-l
>
>
11
>
v(A)
Bjk
0
~j
j:O
i
10
+-
k
j
Program 1.5
i-I
~
Matrix lTIultiplication
1.2
PrograJJlS
C/ = L
Akl
B/"
k=l
X n
ri
= 1,2,
,p,(A),
lj
1,2,
, v(B),
veX).
Program 1.5. Steps 1-3 initialize the indices, and the loop 5-7 continues to
add successive products to the partial sum until k reaches zero. When this
occurs, the process continues through step 8 to decrement j and to repeat the
entire sunlnlation for the new value ofj, providing that it is not zero. I fj is zero,
the branch to step 10 decrements i and the entire process overj and k is repeated
fronl j = v(B), providing that i is not zero. If i is zero, the process is cOl1lplete,
as indicated by the exit arrow.
The language
t.2
i -(- fleA)
+1
i-(-i-l
.i ~- vCR) +
.i ~-.i - 1
C/ -(- 0
k-(-k-l
C/
Program 1.6
~--
v(A)
~-
C/ + Aki
B/.;
:rr,.IJ holds.
1.3
Structure
(~f
the language
statenlent s. Program 1.7 shows the use of these conventions in a refa fill u
lation of Prograrn 1.6. More generalIy~ two or rnore otherwise independent
progranls may interact through a statenlent in one progranl specifying a
branch in a second. The statenlent nunlber occurring in the branch rllust
then be augrnented by the name of the progranl in which the branch is
effected. Thus the statenlent (0) -~ Program 2.24 executed in Progranl I
causes a branch to step 24 to occur in Program 2.
+1
i +-p(A)
+-
i - I , (=ft, =)
+-
v( B)
j +-j - 1,
+-
v(A)
+-
k - 1, (/, =)
-*
(3, 9)
-*
(5, 2)
+1
(~f~~
=)
-*
(8, 4)
1.3
Conventions
The Sunlrnary of Notation at the end of the book sunlnlarizes the nota
tion developed in this chapter. Although intended prinlarily for reference,
it supplements the text in several ways. It freq uently provides a nl0rc
concise alternative definition of an operation discussed in the text, and it
1.3
The language
also contains inlportant but easily grasped extensions not treated explicitly
in the text. By grouping the operations into related classes it displays
their family relationships.
A concise progralnming language Inust incorporate falnilies of opera
tions whose nleInbers are related in a systenlatic manner. Each fanlily will
be denoted by a specific operation sYInbol~ and the particular nlenlber of the
family will be designated by an associated controlling paranleter (scalar~
vector. Inatrix~ or tree) which inlnlediately precedes the nlain operation
symbol. The operand is placed illlmediately after the nlain operation
synlbol. For exanl ple~ the operation k t x (left rotation of x by k places)
Inay be viewed as the kth melnber of the set of rotation operators denoted
by the symbol t.
Operations involving a single operand and no controlling paranleter
(such as l.r]' or rrl) will be denoted by a pair of operation syInbols which
enclose the operand. Operations involving two operands and a controlling
paralneter (such as the mask operation la~ U, bl) will be denoted by a pair
of operation symbols enclosing the entire set of variables~ and the con
trolling parameter will appear between the two operands. In these cases
the operation symbols themselves serve as grouping synlbols.
In interpreting a compound operation such as k t (j ~ x) it is inlportant to
recognize that the operation symbol and its associated controlling paraln
eter together represent an indivisible operation and must not be separated.
]t would~ for example, be incorrect to assunle that j t (k ~ x) were
equivalent to k t (j ~ x), although it can be shown that the conlplete opera
tions j ~ and k t do commute, that is, k (j ~ x) === j ~ (k x).
The need for parentheses will be reduced by assunling that conlpound
statenlents are, except for intervening parentheses~ executed fronl right to
left. Thus k t j ~ x is equivalent to k (j ~ x), not to (k j) ~ x.
Structured operands such as vectors and nlatrices, together with a
systenlatic component-by-conlponent generalization of elenlentary opera
tions, provide an important subordination of detail in the description of
algorithms. The use of structured operands will be facilitated by selection
operations for extracting a specified portion of an operand, reduction
operations for extending an operation (such as logical or arithInetic
multiplication) over all components~ and permutation operations for
reordering components. Operations defined on vectors are extended to
nlatrices: the extended operation is called a rOlf operation if the under
lying vector operation is applied to each row of the nlatrix and a colurnn
operation if it is applied to each column. A colunln operation is denoted
by doubling the symbol employed for the corresponding row (and vector)
operation.
A distinct typeface will be used for each class of operand as detailed in
1.3
Structure
(~ll he
language
Table 1.8. Special quantities (such as the prefix vectors a/ defined in Sec.
1. 7) will be denoted by Greek letters in the appropriate typeface. For
mneIllonic reasons, an operation closely related to such a special quantity
Rcpresentation
Typc of
Operand
Printed
Typed
Literal
Alphabetic
Nunleric
Variable
Alphabetic
Nunlcric
Unnlarked
Underscore
Vector
Underscore
Matrix
Underscore
Tree
Wavy underscorc
will be denoted by the )ame Greek letter. For exalnple, 'Y.ju denotes the
maxiIllum prefix (Sec. 1.10) of the logical vector u. Where a Greek letter
is indistinguishable from a Roman, sanserif characters will be used, e.g"
E and I for the capitals epsilon and iota.
Literals and variables
10
1.3
The language
----------
The class of arguments and the class of results of a given operator are
called its domain and range, respectively. Thus the domain and range of
the magnitude operation (Ixl) are the real numbers and the nonnegative
real numbers, respectively.
A variable is classified according to the range of values it may assume:
it is logical, integral, or numerical, according as the range is the set of
logical variables (that is, 0 and 1), the set of integers, or the set of real
numbers. Each of the foregoing classes is clearly a subclass of each class
following it, and any operation defined on a class clearly applies to any of
its subclasses. A variable which is nonnumeric will be called arbitrary. In
the Summary of Notation, the range and domain of each of the operators
defined is specified in terms of the foregoing classes according to the
conventions shown in Sec. S.l.
Elenlentary operations
1.4
1.4
11
ELEMENTARY OPERATIONS
Arithmetic operations
The ordinary arithmetic operations will be denoted by the ordinary
symbols +, -, x, and --:-- and defined as usual except that the domain and
range of multiplication will be extended slightly as follows. If one of the
factors is a logical variable (0 or I), the second may be arbitrary and the
product then assumes the value of the second factor or zero according as
the value of the first factor (the logical variable) is I or O. Thus if the
arbitrary factor is the literal "q~" then
Oxq=qxO=O
and
1 x q = q X 1 = q.
Logical operations
The elementary logical operations and, or, and not will be denoted by A ,
V , and an overbar and are defined in the usual way as follows:
H' ~
H' ~ U
H' ~
V v<=>
l1
= I,
= 1
if and only if
u = 1 or v = I,
<=> H~ = 1
if and only if
u = O.
H'
(x
>
0) - (x
<
0)
12
1.4
The language
n == bq
1',
>
j:S:: r < j
b.
The quantity I' is called the j-residue o.l n n10dulo b and is denoted by b Ij n.
For example, 3109 == 0, 3119 == 3, and 310 10 == I. Moreover, if n 2 0,
then b 10 n is the remainder obtained in dividing n by band q is the integral
part of the quotient. A number n is said to be of ecen parity ifits O-residue
modulo 2 is zero and of odd parity if 210 n == I.
If two numbers n and In have the same j-residue Inodulo b, they differ
by an integral multiple of b and therefore have the saIne k-residue Inodulo
b for any k. If b /j n == b /j m, then In and n are said to be congruent rnod b.
Congruency is transitive and reflexive and is denoted by
In
==
n (nlod b).
f3. 141==4,
l3.14J==3,
l-3.14J == -4,
f3.001 == 3,
l3.00 J == 3,
l-3.00J == -3.
In -:-
Structured operands
1.5
1.5
13
STRUCTURED OPERANDS
Elementary operations
Any operation defined on a single operand can be generalized to apply
to each member of an array of related operands. Similarly, any binary
operation (defined on two operands) can be generalized to apply to pairs
of corresponding elenlents of two arrays. Since algorithrTIs conlnlonly
incorporate processes which are repeated on each member of an array of
operands, such generalization permits effective subordination of detail in
their description. For example, the accounting process defined on the
data of an individual bank account treats a number of distinct operands
within the account, such as account number, name, and balance. More
over, the over-all process is defined on a large number of sirTIilar accounts,
all represented in a conlmon format. Such structured arrays of variables
will be called structured operands, and extensive use will be made of three
types, called rector, rnatrix, and tree. As indicated in Sec. S.l of the
SunllTIary of Notation, a structured operand is further classified as logical,
integral, nUlnerical, or arbitrary, according to the type of elenlents it
contains.
A rector x is the ordered array of elements (Xl' X 2 , X 3 ' ,x,'(x). The
variable Xi is called the ith component of the vector x, and the number of
components, denoted by vex) (or simply v when the detennining vector is
clear from context), is called the dinlension of x. Vectors and their conl
ponents will be represented in lower case boldface italics. A nUlnerical
vector X may be rnultiplied by a numerical quantity k to produce the
scalar n1ldtiple k x X (or kx) defined as the vector z such that Zi == k X Xi.
All elementary operations defined on individual variables are extended
consistently to vectors as component-by-corTIponent operations. For
exarTIple,
w == (x
<
y)>w i ==
(Xi
<
yJ.
X /\
+y
== (], 1, 2, 1),
14
1.5
The language
Matrices
A matrix III is the ordered two-dimensional array of variables
M 2 l,
MIl,
M
1 ,
Mf1(M)
1
2 ,
MJ~(M)
MI~(M)
M/I(M)
JI(M)
The vector (M/, M 2 i, . . . , M/) is called the ith rOH' rector of M and is
denoted by Mi. Its dimension v(M) is called the rOH' dimension of the
matrix. The vector (M/, M j 2, . . . , M/l) is called the jth colunul rector
of M and is denoted by M j Its dimension f-1(M) is called the colulnn
dinlension of the matrix.
The variable M/ is called the (i,j)th component or element of the matrix.
A matrix and its elements will be represented by upper case bol.dface
italics. Operations defined on each element of a matrix are generalized
component by component to the entire matrix. Thus, if 0 is any binary
operator,
P = M 0 N<:=>P/ = M/ 0 N/.
Index systems
1.6
ROTATION
= k t
X<:=>Zi
Xj'
where j
vlI(i
+ k).
* Restating the relation in ternlS of the O-residue will illustrate the convenience of the
I -residue used here.
1.7
Special rectors
15
~j
B~Ai
~ k
11
B<=>-C j == k j
==jl
Bi
tB
The first operation is an extension of the basic vector rotation to each row
of the matrix and is therefore called rOlt' rotation. The second operation is
the corresponding column operation and is ,therefore denoted by the
doubled operation synlbol 11. For example, if
k==(0,1,2),
and
C)
.~'
then
~)
and
Ii B
==
(~: ~
:).
.(
1.7
SPECIAL VECTORS
j + wJ(n).
16
The language
1.7
1.8
REDUCTION
x 2)
x:~)
... ) 0 X,,),
1.9
Selection
]7
The relational reductions of practical interest are ~/~/u, and =/u, the
exclusire-or and the equiralence reduction, respectively.
The inductive argument of Exercise 1.10 shows that ~F/U = 210 (+/u).
For example, if U = (1,0,1,1,0), then
-~ / II
= ((((I :1'= 0)
=(((1
1)~
= ((0 ::/= I)
=(1
I)
1)
0)
1)=1=0)
0)
0)=1,
/u
=I)U = =/ii,
a useful companion to De Morgan's law.
To complete the system it is essential to define the value of cJ/e(O), the
reduction of the null vector of dimension zero, as the identity elelnent of
the operator or relation
. Thus + /e(O) = V /e(O) = 0, and x /e(O) =
A /e(O) = 1.
A reduction operation is extended to matrices in two ways. A rOH'
reduction of a matrix X by an operator () is denoted by
Y~
,:)/X
u=
(~ ~ ~)
I
1.9
/)U ==
SELECTION
Compression
The effective use of structured operands depends not only on generalized
operations but also on the ability to specify and select certain elenlents or
groups of elements. The selection of single elements can be indicated by
indices, as in the expressions Vi' Mi, M j , and M/. Since selection is a
binary operation (i.e., to select or not to select), nlore general selection is
18
1.9
The language
ul A ===
AI)
(A/
A
A:
2
A 23
A 43
(A A A A1)
A~3 A A A> '
41
(A
)
A
===
A:3 A
1
vilA ===
and
1. the name, account number, and balance for each account with a balance
less than two dollars.
2. the nan1e, account nun1ber, and balance for each account with a negative
balance exceeding one hundred dollars.
3. the nan1e and account nun1ber of each account with a balance exceeding
one thousand dollars.
4. all unassigned account nun1bers.
Selection
1.9
19
L'I/
with colunln vectors L 1 , L'2' and L 3 representing nanles, account nUIllbers, and
balances, respectively, and with row vectors LI, L'2, ... , LI/I representing
individual accounts. An unassigned account nunlber is identified by the word
"'none" in the nanle position. The four output lists will be denoted by the
Illatrices P, Q, R, and S, respectively. They can be produced by PrograIll 1.9.
R
S
+++-
kth account.
Bank ledger.
Balance of kth account.
Account number of kth
account.
~
L1k
Legend
Program 1.9
20
The language
1.9
+-
j+-O
k~k+l
3/ 1k
ck
10
ck
C ~
~O
\a,u,b\
(b)
v(a) +v(b)
~j
~
+ 1
a, b
Given vectors.
c = (al,bl,b2,a2,b3,b4,a3, ...).
Index of a.
bj
+ 1
-(- (Ii
Index of b.
j
k
Index of c.
u = (0,1,1,0,1,1,0, ...).
(a)
Legend
Program 1.10
Interfiling progran1
(which describes the merging of the vectors a and b, with the first and every
third component thereafter chosen from a) can be described alternatively
as shown in Program 1.1017. Since II == (I, 2, 3, 4, 5, 6, ... ), then
(3) 10 II == (1,2,0, 1,2,0, ... ), and consequently the vector u specified by
step 1 is of the form u == (0, 1, I, 0, 1. 1, 0, ... ).
Mesh operations on matrices are defined analogously, row mesh and
column mesh being denoted by single and double reverse virgules, respec
tively.
The catenation of vectors x, y, ... , z is denoted by x
y
z
and is defined by the relation
x
y EB ... EB z ==
(Xl'
x 2, ... ,
XJ'(X)'
ZI'(Z))'
21
1.9
== \O~
Ii,
0\ + \O~ U~ y\
x\ + \0, U, y\.
The operation \O~ U~ y\ proves very useful in numerical work and \vill be
called expansion of the vector y~ denoted by u\y. Compression of u\y by
II and by u clearly yield y and O~ respectively.Moreover~ any nunlerical
vector x can be deconlposed by a compatible vector u according to the
relation
x == u\ulx + u\ulx.
The two terms are vectors of the same dimension which have no nonzero
conlponents in common. Thus if u == (1,0, 1,0, 1), the decolnposition of
x appears as
x == u\\ul X + u\ul X,
X == u\\uIIX + u\\uIIX.
and
+---Ia~ u~ bl<;~ulc ==
lila,
and
ulc
==
ulb.
la,
\a,
bl == \ula, u, ulb\,
u~ b\ == Iii \a, u, u\bl.
u,
Analogous relations hold for the row mask and row Inesh and for the
colulnn mask and colulnn rnesh.
Certain selection operations are controlled by logical nlatrices rather
than by logical vectors. The rOll' cOfnpressiol1 VIA selects clernents of A
corresponding to the nonzero elenlents of V. Since the nonzero elenlcnts
of V nlay occur in an arbitrary pattern, the result nl ust be construed as a
vector rather than a nlatrix. More precisely, VI A denotes the catenation
of the vectors V) Ai obtained by row-by-row compression of A by V.
22
1.9
The language
u ==
(~ ~ ~ ~)
then
VIA
==
and
VilA
==
1.10
SELECTION VECTORS
==
ai,
1.11
23
+--
(+I'X/(x
==
0))
x.
+--
XY <-~.:> Z/
==
.2 X
(i == 1,2, .. . /l(X)
Y/',
t.i ==
1.'=1
1, 2, . . . 1'( Y).
== +/(X'
Y).
This fonn ulation enlphasizes the fact that nla trix nl ultipl ication incorpor
ates two elCIllentary operations ( +, x) and suggests that they be displayed
explicitly. The ordinary Inatrix product will therefore be written as
X
Y.
24
1.11
The language
ri
i
~ Y)/ = 0I/(X 0 2Yj),
(X
1, 2, ... , /1( X)
1, 2, ... , v( Y) .
tj =
For example, if
A=
then
(~
1 0
A~B=(l~ 14)
5 ,
20
'j
B =
!)
A ~
B=
(l :),
and
B=
and
(A
D'
T 0) ; B
(~
,6
V = U:
ju
and
=ju = -/(ii)
v.
1.12
Transpositions
~ Y<=>Zi ==
C'l!CX i
25
n) or as
02 y),
~ X<=>Zj == C)l!(Y CJ 2 X j ),
~ Y ;,~ x<=>z ==
0I/Cy
02 x).
~ Y
Y2'
(Yl'
==
Yl'
Y2'
Yl'
Y2'
1.12
:~)
Y ~
Y3
(Yl'
==
Yl'
Y2'
Y2'
Y:3'
Y:3'
::)
Y:3
TRANSPOSITIONS
is required,
26
1.12
The language
about either diagonal and about the horizontal and the vertical are also
useful. Each of these transpositions of a matrix B is denoted by a superior
arrow whose inclination indicates the axis of the transposition. Th us:
C/
C~B
---+
C~B
-..
==
B/
C/ == B~::;~;
i == 1,2,
,11(B)
C/
j == 1,2,
, v(B)
== Bj +l-i
For a vector x, either x or x will denote reversal of the order of the com
ponents.
1.13
Certain of the special logical vectors introduced in Sec. 1.7 have useful
analogs in logical matrices. Dimensions will again be indicated in paren
theses (with the column dimension first) and may be elided whenever the
dilllension is determined by context. If not otherwise specified, a matrix is
assumed to be sq uare.
Cases of obvious interest are the ju!1 matrix fern x n), defined by
* These transpositions generate the rotation group of the square [cf. Birkhoff and
MacLane (1941) Chap. VI]. A pair of transpositions commute if and only if their axes
are perpendicular. Hence the pair +-- and t may be written unambiguously as-<t- .
Moreover, ~t- = X. The remaining two transformations can be denoted by 4 and~,
with the convention that the operator nearest the operand (i.e., the horizontal) is
executed first.
Po~vn()fl1ials and
1.14
the
111
X n
C +-- ...-J
C +--
~-=j
(111 X 11)
C ~- '~ (111
(111
C +---~ (111
27
X 11)
<=> C/
<=> C: + 1 _
X 11) <--:?
X
C jl + 1
== (i +.i
In i 11
(111,
11 ) )
for i
andj
== 1, 2,
== 1,2,
, 111
,11.
The use of the matrices E and I will be illustrated briefly. The relation
== 2 10 (u v) can be extended to logical matrices as follovvs:
u ;, v
U / V
== (2 E) 10 ( u ~
V) ~
+ /1/ X.
n/
== 7278
60
60
" ; y ==
1
v
24
/(0)
86400
3600
60
1
(be)
28
1.14
The language
Xl'
X 2 ' , Xl"
(YE) ~
==
xlyV(X)-l
~ X
J_
in the form
==
(D
7y) :
z +---- Xl
Y<=>Z/
==
Y~j.
Xi
1.15
SET OPERATIONS
==
s ==
(a, t, e)
(s, a, t, e, d)
d == (d, u, s, k)
n
==
==
(n,
0,
n, s, e, t)
(r, e, d, u, n, d, a,
ll,
t)
Set operations
1.15
29
==
yx>v(u)
==
v(y), and u j
==
(Yj EX).
==
yXjy.
==
yXjy.
30
The language
1.15
The forward selection alb and the backward selection Tlb defined in
Sec. l.10 can both be used to reduce any vector b to a similar set, that is,
(alb)lb
==
(Tlb)lb
==
b.
E:"
a
a
A=
b
b
c
c
0
1
0
1
0
1
are a complete list of the vectors z belonging to the product set of x and
y. The matrix A will be called the Cartesian product of x andy and will be
denoted by x @ y.
The foregoing definition by example will be formalized in a more
general way that admits the Cartesian product of several vectors (that is,
u ('9 v 09 ... 09 y) which need not be sets, and which specifies a unique
ordering of the rows of the resulting matrix. Consider a family of vectors
Xl, x 2 , .. , x' of dimensions d l , d 2 , . . . , do' Then
+- X
I?
0)
x-
(9 ... (9
A 1 :, d
x'"<=>.
(k -- )
0
= (1
Xk" Xh" . . . ,
xl" '
, )
for all vectors k such that I ::s:: k i ---: d i . Clearly v(A) = s, and ,u(A) =
x Id. As illustrated by Table 1.11, the rows of the Cartesian product A are
not distinct if anyone of the vectors Xi is not a set.
If the vectors Xi are all of the same dimension, they may be considered
as the columns of a matrix X, that is, Xi = Xi. The product Xl (>9 x 2
':'J' . .
x' = Xl @ X 2 09 ... 09 x, may then be denoted by (il X, or
alternatively by (2,IIY, where Y is the transpose of X. For example, if
X
l0(2)
E(3)
(0
0),
the n @IX is the matrix of arguments of the truth table for three variables.
1.16
Rank. in?:
a #
a #
31
*
1
b # 0
b # 1
=
x2 =
x:3 =
d =
Xl
(a, b, a)
(#, *)
(0,1)
(3, 2,2)
*
1
a # 0
*
0
a #
a *
a *
The Cartesian product A =
Table 1.11
1.16
1
Xl
x2
X3
RANKING
+-
==
c<-:>-k;
I Ct.
+-
+-
II
C<=->Ji
G'f<=;>K j
==
==
Bi
Ci,
Bj
C j .
Use of the ranking operator in a lnatrix prod uct reg uires no secondary
scan and is therefore indicated by a superior null synlbol. Moreover,
since the result lnust be linlited to a two-dinlensional array (nlatrix), either
the pre- or post-operand is required to be a vector. Hence
J
K
~- B~) C<:-~->Ji ~
+-
b{ C<~>Kj
==
Bi
I C,
b I Cj .
32
The language
1.16
)=
For example, if x
1.17
-L
(v(b)e)
(b to x).
(2,0,1), and)
51.
Reordering operations
The selection operations employed thus far do not permit convenient
reorderings of the components. This is provided by the mapping operation
defined as follows: *
For example, if a = (a, b, ... , z) and k = (6, 5,4), then C = (f, e, d).
The foregoing definition is meaningful only if the components of k each
lie in the range of the indices of a, and it will be extended by defining a j as
the null element if) does not belong to the index set of a. Formally,
C +--
am<=>c i
am.
if m i
ll(v(a))
if m i ll(v(a)).
The ability to specify an arbitrary index origin for the vector a being
mapped is provided by the following alternative notation for mapping:
am.
c+-mS;a<=?c;=,o
'
{
if m i
li(v(a))
if m i li(v(a)),
(m
* oe)/(m.Lb) = a n b.
* For the purposes of describing algorithms, this notation is superior to the classical
"disjoint cycles" notation for permutations [cf. Birkhoff and MacLane, (1941)] because
(1) the direction of the transformation (from a to c) is unequivocally indicated, and (2)
the notation directly indicates a straightforward and efficient method for actual execu
tion, namely, indirect addressing.
1.17
33
Ji
Mil'
J h Bi ,
MJJII B<=:>Cj =
MjJh B j .
A ~ M JrII B<=:>Ai
C~
J A, and
M Ja.
The alternative notation (that is, c = an}), which does not incorporate
specification of the index origin, is particularly convenient for matrices and
is extended as follows:
A ~ B,n <=> Ai = Bn1,.,
A ~ B n1 <=:> Ai = B,ni'
Permutations
A vector k of dimension n is called a j-origin per/nutation rector if
k == lj(n). A permutation vector used to map any set of the same dinlen
sion produces a reordering of the set without either repetition or suppres
sion of elements, that is, k.L a == a for any set a of dimension v(k). For
example, if a = (f, 4, *, 6, z), and k = (4,2, 5, 1,3), then k Xl a = (6,4,
Z, f, *).
If p is an h-origin permutation vector and q is any j-origin permutation
vector of the same dimension, then q .L p is an h-origin permutation vector.
Since
the interval vector lj(n) will also be called the j-origin identity pernultation
vector. If p and q are two j-origin permutation vectors of the same
dimension n and if q .L p = lien), then p .L q = lien) also and p and q are
said to be inrerse permutations. If p is any j-origin permutation vector,
then q = p lj li is inverse to p.
The rotation operation k x is a special case of permutation.
1.17
The language
34
Function mapping
A function f which defines for each element b i of a set b a unique
correspondent ale in a set a is called a mapping fronl b to a. If f(b i ) = ale,
the element b i is said to map into the element ale. If the elements f(b i )
exhaust the set a, the functionfis said to map b onto a. If b maps onto a
and the elements j'(b i ) are all distinct, the mapping is said to be one-to-one
or biunique. In this case, v(a) = v(b), and there exists an inverse mapping
from a to b with the same correspondences.
A program for performing the mapping f from b to a must therefore
determine for any given element b E b, the correspondent a E a, such that
a = feb). Because of the convenience of operating upon integers (e.g.,
upon register addresses or other numeric synlbols) in the automatic
execution of programs, the mapping is frequently performed in three
successive phases, determining in turn the following quantities:
1. the index i = b l h,
2. the index k such that ale
3. the element ale.
= f(bJ,
The three phases are shown in detail in Program l.I2a. The ranking is
performed (steps 1-3) by scanning the set b in order and comparing each
element with the argument b. The second phase is a permutation of the
integers 1,2, ... , v(b), which may be described by a permutation vector
j, such that Ii = k. The selection of ji (step 4) then defines k, which, in
turn, determines the selection of ale on step 5.
Example 1.2.
If
b
Apfel
(1,3,5,2,4). If b
Beute
Staub
"night," then i
Auge
5,ji
Nacht
4, and a
a4
Nacht.
i+-O
i+-O
i~-i+l
+-
bi
k +-ii
k -<-ki
(0) b i
+- a7,~
aj
+-
b 1.:
(b) a j <=> b k
<=> a h
i+-blb
i -<-0
k -<-0
k+-k+l
6
7
+-
k -<-ii
-<-
ak
ai
i : il;
h
+--
bk
+-
(b
= b)/i
a +-a k
(c) a; <=> bki
Set of correspondents in
Programs (a, d, e) and set
of arguments in Programs
(b, c).
b
j, k
Mutually inverse
permutation vectors.
Legend
Program 1.12
36
1.17
The language
Ordering vector
If x is a numeric vector and k is a j-origin permutation vector such that
the components of Y = k.L x are in ascending order, then k is said to order
x. The vector k can be determined by an ordering operation defined as
follows:
k +- 8j jx
implies that k is a j-origin permutation vector, and that if Y = k Jj x, then
either Yi < Yi+1 or Yi = Yi+1 and k i < k i +1. The resulting vector k is
unique and preserves the original relative order among equal components.
For example, if x = (7, 3, 5, 3), then ()ljX = (2,4, 3, 1).
The ordering operation is extended to arbitrary vectors by treating all
nonnumeric quantities as equal and as greater than any numeric quantity.
For example, if a = (7,0,3, ,0 5,3), then ()lja = (3,6,5, 1,2,4), and if
b is any vector with no numerical components, then ()jjb = li(v(b)).
Ordering of a vector a with respect to a vector b is achieved by ordering
the b-index of a. For example, if a = (e, a, s, t, 4,7, t, h), and b is the
alphabet, then m = b II a = (5, 1, 19,20,0,0,20,8) and ()ljm = (2, 1,8,
3, 4, 7, 5, 6).
The ordering operation is extended to matrices by the usual convention.
If K = ())/A, then each column of the matrixB = KJ.LAisinascending
order.
1.18
MAXIMIZATION
ur
v +- urx<=> v = u\(r(ujx)).
1.19
Inverse functions
37
components of x, and the positions at which the plane first touches them
are the positions of the unit components of v. For example, maximization
over the negative components of x is denoted by
v+---Cx
<
0)[ x
v +--V
+---
V [X <=> Vi
rrX<=> V
\'";
Jl +--- U [ x<=> Vi
n
+--- U [
Vi rXi,
=
=
V j [Xj,
Vi[x,
X<=> V =
j
u [X j
(d c h d h s h d c h c h d)
a6kq435k82j92
B=
then
c, d, h, s, 0, 0, 0, 0,
(
BloH= (
0, 0, 0, 0, 0)
2, 3, 4, 5, 6, 7, 8,9, 10, j, q, k, a
1, 0, 2, 1, 2, 3, 2, 1, 0, 2, 0, 2, 1)
12,4,11,10,2,1,3,11,6,0,9,7,
(4,13) 1_ (B i o H) = (25,4,37,23,28,40,29,24,6,26,9,33,13),
and
(e[((4, 13) ~ (B i O H)))/H = (s, 3)
is the highest ranking card in the hand.
1.19
INVERSE FUNCTIONS
38
The language
1.19
vex)
(2)
+-
1- x +- z; vex).
y
Y
+-
x+- 7278; y
u/b
+-
1.21
Subroutines
39
b ~ \ulb, u, a\.
Similarly,
ulb ~ ula
is equivalent to
b ~ Ib,
1.20
u, al.
LEVELS OF STRUCTURE
Vectors and matrices are arrays which exhibit one level and two levels of
structure, respectively. Although in certain fields, such as tensor analysis,
it is convenient to define more general arrays whose rank specifies the
number of levels of structure (i.e., zero for a scalar, one for a vector of
scalars, two for a vector of vectors (matrix), three for a vector of matrices,
etc.), the notation will here be lilnited to the two levels provided by the
matrix. * The present section will, however, indicate methods for ren10ving
this limitation.
The only essential particularization to two levels occurs in the provision
of single and double symbols (e.g., "I" and "II", "~" and "Jl") for row
and column operations, respectively, and in the use of superscripts and
subscripts for denoting rows and columns, respectively. In applications
requiring multiple levels, the former can be generalized by adjoining to the
single symbol an index which specifies the coordinate (e.g., "'II" and "/2'"
for row and for column compression, and, in general, "//'.) The latter can
be generalized by using a vector index subscript possessing one con1ponent
index for each coordinate.
The generalized notation can be made conlpatible with the present
notation for vectors and matrices by adopting the nam.e tensor and a
symbol class (such as capital italics) for the general array of arbitrary rank.
1.21
SUBROUTINES
40
The language
1.21
the angle between the vectors x and y, then Program l.13a uses the pro
gram "Cos" as a subroutine to determine r as the cosine of the angle
between the vectors p and q.
X+-P
Cos (p, q)
+-q
--1
r - Cos (p , q)
+- Z
Cos
r
+- Z
(a)
(b)
Program 1.13
(c)
1.22
FILES
Many devices used for the storage of information impose certain restric
tions upon its insertion or withdra\val. The items recorded on a magnetic
tape, for example, may be read from the tape much more quickly in the
order in which they appear physically on the tape than in some other
prescribed order.
Certain storage devices are also self-indexing in the sense that the item
selected in the next read from the device will be determined by the current
state or position of the device. The next itenl read from a magnetic tape,
for example, is determined by the position in which the tape was left by the
last preceding read operation.
To allow the convenient description of algorithlTIs constrained by the
characteristics of storage devices, the following notation will be adopted.
A file is a representation of a vector x arranged as follows:
The null elements denote the "unused" portion of the file not employed in
Files
1.22
41
+- 0(1),
42
1.22
The language
U ~
e(m)
<I> .1
<1>2
1
Output file.
Itern to be recorded.
1,
2
7T(<I>1 )
i +-
n{<I>l)
i+-i-l
u:e
Uk
~O
~ 1
m
i=
ml 1(k
+-
Legend
+ 1)
10
b,p
11
Uk ~(p
12
u:e
13
<1>1
14
<D 12
+-
+-<I>k
= A2)
+-
b, Al
+-
b, A 2
Program 1.14
item read. However, when the last file becomes exhausted, step 14 is executed
instead to record the last item, together with the final partition A2
Steps 1-6 initialize the parameters u and k and rewind all files. After the last
item is recorded by step 14, the file rewinds are repeated before the final termina
tion on step 7.
fh
I A2 .
~x+-o'-V~,
where the indicated branches depend on the value of the partItIon Pj+l
which terminates the read. Thus the left or the right branch is taken
according to whether Pj+I = Al or Pj+l = A2 Certain files (such as the
IBM 7090 tape files) permit only such "immediate" branching and do not
permit the partition symbol to be stored for use in later operations, as was
done in Program 1.14.
I n recording, the lowest level partition Al may be elided. Thus statement
13 of Program 1.14 may be written as
<D I 2
+-
b.
43
1.22
7TDI)
+--
7T( (I) J
+--
denotes the rewinding of the colunlll of Jiles <:1)/, i E llCUD)); and the
statement
44 The language
1.22
O-origin indexing
E(2 x 2)
7T(<D)
+-
U +-
(3)
m+-m-1
U +-U
k +- n
8
9
10
>
Control vector.
<
o
u1
u2
Required
merges.
<DU2
U
+-
o +-
<])
U2
<D Uu2
k+-k-l
u1
u1
+- U 1
u2
Program 1.15
i~
number of
Legend
Program for Example 1.4
n iten1s, alternating the input files through the negation of U o on step 7. When
the loop terminates, u 1 is negated to interchange the outputs, and the loop is
repeated unless u 1 = u 2 - Equality occurs and causes a branch to step 3 if and
only if all 2n items of the current phase have already been copied.
Step 3 decrements 111 and is followed by the negation of U on step 4. The con1
ponent u 2 must, of course, be negated to reverse direction, but the need to negate
U o and u 1 is not so evident. It arises because the copying order was prescribed for
the forward direction, beginning always with the operation
Not all computer files have the very general capabilities indicated by the
present notation. Some files, for example, can be read and recorded in the
forward direction only and, except for rewind, cannot be positioned
directly. Positioning to an arbitrary position k must then be performed by
a rewind and a succession of (k - 1) subsequent reads. In some files, re
cording can be performed in the forward direction only, and the positions
are defined only by the recorded data. Consequently, recording in posi
tion k makes unreliable the data in all subsequent positions, and recording
must always proceed through all successive positions until terminated.
Ordered trees
1.23
1.23
45
ORDERED TREES
Directed graphs
114
223
1311
n16
2221
n21
n22
22231
n25
Figure 1.16 A general triply rooted tree with ).(T) = 16, 'J(T)
= 5, ~(T) = (3, 7, 8, 5, 3), and {leT) = 26
veT)
(3, 3, 4, 3, 2),
46
1.23
The language
2, 3, ... , v(k),
then the vector p = kJn is called a path rector of the graph (n, U). The
dimension of a path vector is also called its length. Nodes k 1 and k v are
called the initial and final nodes, respectively; both are also called
tenninal nodes. If j is any infix of k, then q = jJ n is also a path. It is
called a subpath of p and is said to be contained in p. If v(q) < v(p), then
q is a proper subpath of p. If k 1 = k" and p = kJn is a path of a length
exceeding one, p is called a circuit. For example, if k = (6, 1,7,7,2, 6,
1, 5), then p = (n 6, n 1, n 7, n 7, n 2, nfl' n 1, n 5) is a path vector of the graph
of Fig. 1.17, which contains the proper subpaths (n 7, n 2, n 6), (n 1, n 7,
n 7, n 2, n 6, n 1), and (n 7, n 7), the last two of which are circuits. Node j
is said to be reachable from node i if there exists a path from node i to
node j.
Ordered trees
A graph (such as Fig. 1.16) which contains no circuits and which has
at most one branch entering each node is called a tree. Since each node
is entered by at most one branch, a path existing between any two nodes
in a tree is unique, and the length of path is also unique. Moreover,
if any two paths have the same final node, one is a subpath of the
other.
Since a tree contains no circuits, the length of path in a finite tree is
bounded. There therefore exist maximal paths which are proper subpaths
of no longer paths. The initial and final nodes of a maximal path are
called a root and leaf of the tree, respectively. A root is said to lie on the
first leeel of the tree, and, in general, a node which lies at the end of a path
of length j from a root, lies in the jth level of the tree.
1.23
47
Ordered trees
n2
n5
u=
0
0
0
0
0
0
n4
Figure 1.17
48
1.23
The language
is a nlini111U111.
Program 1.18. The index vector i specifies the path currently under test. Its
last conlponent is incremented repeatedly by step 7 until the loop 6-8 is terminated.
If the path T i agrees with the corresponding prefix of the argument x, ternlination
occurs through the branch to step 9, which tests for conlpletion before step 10
augnlcnts i by a final zero component. Step 5 then respecifies d as the degree of
the penultilnate node of the set of d paths next to be tested by the loop. Termina
tion by a branch from step 6 to step 2 occurs if all d possible paths are exhausted
without finding agreement on step 8. I n this event, retraction by one level occurs
on step 2, and d is again respecified. Jf 1'( i) = I, the paths to be searched conl
prise the roots of the tree and d nlust therefore be specified as the nU111ber of
roots. This is achieved by executing step 3 and skipping step 5. Retraction to a
vector i of dinlension zero occurs only jf all roots have been exhausted, and final
ternlination from step 4 indicates that the tree possesses no path equal to the
argunlent x.
1.23
Ordered trees
i
+-
e(2)
+-
wi/i
<
9
10
+i
Given tree.
be determined.
(5(;)1/i, T)
/; :
; +-
=I-
I-origin indexing
fJ.l(T)
v(i)
d
+-
49
+ wI
fJ.l(T)
Number of roots of T.
(5(i, T)
Degree of node i.
Legend
al'(i)/x
v(i) : vex)
i
+-
wI\i
Program 1.18
* In the I-origin indexing system used here it would be possible to use the nUI11eric
zero to represent the null. In O-origin indexing, however, zeros occur as con1ponents of
index vectors and must be distinguishable from the nulls used.
50
1.23
The language
I~
3
4
0
0
0
0
0
1
2
0
0
c
f
d
r
e
z
11
i
P
q
111
0
0
1
0
0
t
w
0
0
j
1
ll
]11
nIl
b
k
h
]'
n'
y
v
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
1
1
1
1
1
1
2
3
4
1
2
3
3
2
2
4
5
6
7
8
9
10
11
12
4
0
1
0
2
3
3
3
3
1
1
1
2
1
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
3
15
16
21
22
23
24
25
2
2
2
3
3
1
2
2
3
1
2
0
0
1
1
0
0
3
2
2
2
17
111
18
19
0
0
0
0
26
2
1
0
0
0
s
x
t
0
0
2
2
2
1
2
2
2
2
2
2
2
2
2
3
3
2
2
2
2
2
2
(a)
(b)
Table 1.19
P
q
1
2
3
20
1
f
d
r
e
i
13
14
0
0
0
0
0
0
b
g
c
z
11
k
h
2
2
3
3
1
2
1
2
3
1 4
1
2
3
1
:2
:2
:2
2
2
:2
3
1
3
1
:2
1
dimension /leT) X veT), which, together with the associated node vector,
completely describes the tree, If, for example, the node vector n is the
alphabet, the tree of Fig. 1.16 is described by the node vector n' and index
matrix I' of Table l.l9a or, alternatively, by n" and I" of Table 1.19b.
Because of the utility of the degree vector, it 'will be annexed to the array
of node vector and index matrix, as shown in Table 1.19a~ to form a full
list lnatrix of the tree. The degree vector and node vector together will be
called a list lnatrix. As remarked, the list Inatrix can~ in certain pernluta
tions, alone describe the tree.
Formally, the full list matrix M of a tree T is defined as follows: a2/ M
is an index matrix of the tree, M 1 is the associated degree vector, and M;!.
Ordered trees
1.23
51
is the associated node vector. Thus for each k E llCU(T)), M/;: = b(i, T),
and M/~ = (Ti).l'(i)' where i is the nonnull portion of -a,2/M\ that is, i =
((fi2/ Mk)
0)/fi 2/ Mk). The corresponding list matrix is a 2/ M.
Since a full list matrix provides a complete description of a tree regard
less of the order in which the nodes occur in the list, any column permu
tation MP (that is, any reordering among the rows) is also a full list matrix.
Two particular arrangements of the full list nlatrix are of prime interest
because each possesses the following properties: (1) the nodes are grouped
in useful ways, and (2) the list matrix (i.e., the degree vector and node
vector) alone describes the tree without reference to the associated index
matrix. They are called the full left list matrix and full r(r;lzt list matrix and
are denoted by [T and ]T, respectively. Table 1.19 shows the fuHleft and
full right lists of the tree of Fig. 1.16.
The left list index matrix I is left justified, * that is, the null elements are
appended at the right of each index. The rows Ij are arranged in increasing
order on their values as decimal (or rather (b(T) + 1)-ary) fractions with
the radix point at the left and the nulls replaced by zeros. More precisely,
the rows are arranged in increasing order on the function (1'(o))
(a to Ij), where a = (0, 1, 2, ... , ()(T)). t
The right list Inatrix is right justified and is ordered on the sanle function,
namely (v(a)) ~ (a Lo Ij). The rows are therefore ordered on their values
as integers, i.e., with the decimal point at the right. Fronl the exalnple of
Table I.I9b it is clear that the right list groups the nodes by levels, i.e.,
level j is represented by the infix (i J a l,)/ /(]T), where k = fJ-lT), and
i = + /aj-1/fJ-(T). In Table 1.19b, for exanlple, fJ-(T) = (3, 7, 8, 5, 3), and
if j = 3, then k = 8, i = 10, and level j is represented by rows i + 1 = II
to i + k = 18. The right list is therefore useful in executing processes
(such as the pth degree selection sort) \vhich require a scan of successive
levels of the tree.
The left list groups the nodes by subtrees, i.e., any node i is followed
inl111ediately by the remaining nodes of its subtree T i . Fornlally, if I =
cx 2/[T, and if i = (II,; :F o)/II,', then the tree T i is represented by the infix
((k - I) J a/I(Ti ))/ /[T. In Fig. 1.19a, for exa111ple, if k = 16, then i =
(2,2,2), {l(T;) = 7, and T i is represented by rows 16 to 22 of [T. The left
list is therefore useful in processes (such as the construction of a H uffnlan
code and the evaluation of a cOlnpound statenlent) which require a
treatnlent of successive subtrees.
The row index of a node in a right (left) list nlatrix is a graph index of
the node and will be called the right (left) list index.
-j(~,
52
The language
1.23
Well fornlation
A two-colulnn matrix which forms the right list of son1e tree is said to
be a It'ell fornled right list. Since the ordering of the nodes in a right list of
a given tree is unique, the right list of a given tree is unique. Conversely,
any well fonned right list specifies a unique tree according to the algorithm
of Progran1 1.20.
Identical relnarks apply to the left list, except that Progran1 1.20 is
replaced by PrograIn 1.21. Moreover, the necessary and sufficient
conditions for the well formation of a left list are identical with those for a
right list and are derived by virtually identical arguments. The case will
be stated for the right list only.
If R is a well fornled right list representing a tree T, then the dispersion
(i.e., the nUlnber of roots) vl(T) = v(R I ) - (+ IR I ) must be strictly
positive. Moreover, if S = CiJ II R is any suffix of R, then S is a right list of
the tree obtained by deleting from T the first j nodes of the original list.
For, such level-by-Ievel deletion always leaves a legitin1ate tree with the
degrees of the remaining nodes unchanged. Consequently, the nun1ber of
roots deternlined by every suffix of R l must also be strictly positive. In
other words, all components of the suffix dispersion rector s defined by
1.23
Ordered trees
53
s == (I
+ 0);-1 g.
1.23
The language
54
I-origin indexing
i+-O
2
j+-O
v+-o
+-
~{Rl)
TJ
+-
(I = 0)
+-
~-II,
>
+-
+ (> -
I)E
T.
i + 1
i :j
>
t Ii
11
12
d -(-R1i
13
d+-d-l
14
j +-j + 1
15
v -(- v +
16
Ii
+-
U,oEI
+-
Right list of T.
(+ IR])
i : peR)
10
Legend
<
WI
Program 1.20
(19-20) to deternline the index i of the last preceding node whose branches renlain
inconlpleted. Steps 22-23 then respecify v as the index vector of the node follow
ing node i in the path last traced, and step 21 decren1ents the conlponent L1i of
the degree vector. The branch fron1 step 19 to step 22 occurs at the con1pletion
of each rooted subtree. The test for well fonnation (step 12) is the sanlC as that
applied to the right list in Program 1.20, except that the notation for the relevant
paranleters differs. The concluding operations (6-9) include left justification on
step 7.
+--
U/T
Ordered trees
1.23
I-origin indexing
i~O
V~O
1 ~ ( + 1lJ.(U)
1 ~1
+--
10
~j
11
12
13
veL}) - (+IL 1 )
(1
C i +1
0)
+ (1)
11,
- I)E
U, E1
+1
~r + L/
~-
+ w}
14
15
C i +I -(- j
16
i -(-j
Left list of T.
/1(L)
~
55
17
18
19
i -(- i - I
22
k ~- cHI
23
V ~-
II.'
Fig. 1.16 with n as the alphabet, and U is the tree of Fig. 1.22a, then P
is the tree of Fig. 1.22b. The new indices are shown to the left of each node
of P. The set of nodes 221, 222, ... ,226, are all on the sanle level of P
although they have been shown with branches of different lengths to
permit easy identification with the nodes of the original tree T.
56
The language
1.23
111 f
131
21 k
2
b
U/T
(a)
(b)
Figure 1.22
alphabet)
The compress operation is best executed on the left list because of the
grouping by subtrees. Program 1.23 gives a suitable algorithlTI which also
serves as a formal definition of the compress operation.
Program 1.23. The vector u is specified as the node vector of the left list of the
controlling logical tree U and controls the subsequent process. Step 4 deternlines
j as the index of the first zero conlponent of u. Steps 6 and 7 then delete the corre
sponding nodes of u and of the left list of T, but only after step 5 has deternlined d
as the change in degree which this deletion will occasion to the root of the sIllallest
subtree containing the deleted node. Steps 9-1 I perfornl a back\\'ard scan of the
degree vector to deternline j as the index of the root of the subtree, and step 12
effects the requisite change in its degree. The exit on step 9 occurs only if the node
deleted is a root of the original tree, in which event no change is produced in the
degree of any other node.
+-
u/T.
1.23
Ordered trees
~ a 2 j([T)
j~(+j'l.ju)+1
~-- L1j -
-o(-ejju
I-origin indexing
([U)2
u
E
r~l
~j
Left list of T.
Index of first zero of u
(Steps 4-8). Index of root
of smallest subtree contain
ing deleted node (Step 12).
- 1
10
11
7
8
57
>
12
Legend
Program 1.23
*-
ulIT,
implies that node i of Z is the product of node i of X and node i of y for all
i. Similarly,
58
1.23
The language
implies that each level of V is the forward set selection of the corresponding
level of A, that is, j /V == a/j/A. Operations extending across paths are
denoted by single virgules and are defined in tern1S of subtrees. Thus
V~'l./U
implies that V is obtained fron1 the logical tree U by setting to zero all
nodes of any subtree rooted in a zero node, and
(/)/U
Homogeneous trees
If, for all j, every node on level j of a tree T is either of degree zero or of
degree 'V j ;l(T), then the tree T is said to be unij()rn7. If all leaves of a
59
Ordered trees
1.23
uniform tree T lie in the same level (necessarily the top), then the tree is
said to be hOIJ1ogeneous. The structure of a homogeneous tree is completely
characterized by its dispersion vector veT). All maxin1al paths in a homo
geneous tree are clearly of the same length, nan1ely veT) == v(v(T)). Figure
1.25 shows a homogeneous tree and its associated dispersion vector.
I----~O
a/U
~-_....>@
~I---->"'@
~I-----~""CD
~I----"~CD
w/u
(J/U
~I---_->~@
a/IV
w/IV
O-//V
~f----""'>@
--~1
~--->-CD
~I---->~CD
r/U
Figure 1.24
r//U
60
1.23
The language
A tree T for which veT) = 111 is called an I1z-waJ' tree, and a tree for
which vI(T) = 1 and (iI/v(T) = m is called a singular I1z-lray tree.
The jth component of the mOlnent vector of
a homogeneous tree is clearly equal to the prod
uct of the first j components of the dispersion
n
vector, that is, fL(T) = (0 + I) / veT). The dis
persion vector is, in turn, uniquely deternlined
by the moment vector. The total nunlber of
nodes is given by [leT) = + /fL(T), and it can also
be shown that fl(T) = Y J_ y, where y is the
dispersion vector in reverse order.
Tree compression of a honl0geneous tree H
(that is, lJ/H) does not generally produce a
g
homogeneous tree, and, in fact, any tree P of
arbitrary structure can be represented by a pair
of homogeneous trees U and H such that P =
U/H. On the other hand, both path and level
q
compression of homogeneous trees produce
homogeneous trees. Moreover, ifP = u/H, then
r
v(P) = u/v(H), and if P = u//H, then v(P) =
v(H) - (+ /u)a].
Since the structure of a homogeneous tree is
completely specified by its dispersion vector k,
h
the structure of the special logical trees can be
specified in the forms E(k), UE(k), and uE(k).
In a homogeneous tree, the right list or left
list index of a node can be detennined as an
explicit function of its index vector. Conversely,
the index vector i can be determined directly
from the corresponding left list index, to be
denoted by I(i), or from the right list index rei).
U
In developing the relations between indices it'
will
be convenient to use O-origin indexing
II(H) = (2,3,2)
M(H) = (2,6,12)
throughout.
Figure 1.25 Homogen
The right list index is given by
eous tree H and disper
rei) = f(i) + g(i),
sion and moment vectors
f(i) = + /aJ/(i) -1 /fL(T)
where
is the number of nodes in the first 1'(i) - 1 levels, and
g(i)
(a '(i)/v(T))
1-
(I, 0, 1) in the
Ordered trees
1.23
61
tree of Fig. 1.25, then fJ-(H) = (2, 6, 12), j(i) = +/(2, 6) = 8, and
g(i) = (2,3,2)
(1,0,1) = 7.
Since j(i) depends only on v(i), the index i may be detennined fron1 r by
first determining v(i) as the largest value for which j'(i) :s: r, and then
determining i such that
(cx'J(i)jv(l'))
_L i =
r - f(i).
In tracing a path through a tree, the kth node of the set reachable fron1
node i is the node j = i .2:) (k). It is therefore useful to express r(j) as a
function of rei). Clearly
f(j)
g(j)
= f(i) + (fJ-(T))I'(i)--l,
= g(i) X (v(T))IJ(i) + jl'-l.
f(i)
+ 1n + n1 2 + ... + 1111'(i)-::' =
m 1!(i)-1
(111e)
l- e(v(i) -
1)
111 -
r( j) =
111 X
r( i)
+ 1 + jl' - 1.
l'(T)
lei)
v(i) -
+ 2 (cxi/v(T)) l- (cxijz(i)).
j=l
For example, if i
lei)
v(i) -
(1,0,0) and
1 1.
lei)
v(i) - 1
+ (Wi
=
10.
w : z(i),
62
1.23
The language
REFERENCES
Birkhoff, G., and S. MacLane (I941), A Survey of Modern A (fjebra, Macmillan, New
York.
Burks, A. W., D. W. Warren, and J. B. Wright (1954), "An Analysis of a Logical
Machine Using Parenthesis-free Notation," Mathel11atical Tables and Other Aids to
COl1zputation, vol. VIII, pp. 53-57.
Dickson, L. E. (1939), New First Course in the Theory of Equations, Wiley, New York.
Garner, Harvey L. (1959), "The Residue Number System," IRE Transactions, vol. EC-8,
pp. 140-147.
Goldstine, H. H., and J. von Neumann (1947), "'Planning and Coding of Problems for
an Electronic Computing Instrument," Report on the MathelJlatical and Logical
Aspects ofan Electronic COlllpUtil{[[ InstrUl11ent, Part II, vol. 1, Institute for Advanced
Study, Princeton.
Iverson, K. E. (1954), "Machine Solutions of Linear Differential Equations," Doctoral
Thesis, Harvard University.
Jacobson, N. (1951), Lectures in Ahstract A~fjebra, vol. 1, Van Nostrand, New York.
Kunz, K. S. (1957), Nurnerical Analysis, McGraw-Hill, New York.
Margenau, H., and G. M. Murphy (1943), The Mathel11atics of Physics and Chel11istry,
Van Nostrand, New York.
Phister, M. (1958), Logical Des({n of D{[{ital C0l11puters, Wiley, New York.
Richards, R. K. (1955), Arithl11etic Operations in Digital Computers, Van Nostrand,
New York.
Riordan, J. (1958), An Introduction to C0l11hinatorial Analysis, Wiley, New York.
Rutishauscr, H. (1959), "Zur Matrizeninversion nach Gauss-Jordan," Zeitschrift fiir
A/~{e~vandte Mathenzatik und Physik, vol. X, pp. 281-291.
Wright, H. N. (1939), First Course in Theory of Numbers, Wiley, New York.
EXERCISES
Organize each of the programs according to the method of leading decisions.
Except where otherwise indicated, use I-origin indexing. The conventions of
Sec. S.I of the Summary of Notation will be used in the statement of each
of the exercises.
1.1 Let d = (a, 2,3,4,5,6,7,8,9, 10,j, q, k), S = (c, d, h, s), u = (1,0, 1,0,1),
v = (0, I, I, 1, 0), x = (16, 8, 4, 2, I), and y = (2, 3, 4, 5, 6). Determine
(a) the dimensions v(d), v(s), and vex).
(b) the vectors x + y, x - y, x x y, x -:- y, and u + v.
(c) the logical vectors u /\ v, u V v, (u =/-= v), and (u = v).
(d) the reductions + lx, x IY, /\ lu, and V Iv.
(e) the base two values of u and of v, that is, +/(x x u), and +/(x x v).
(f) the rotated vectors 2 t d, 4 i s, and iy.
(g) the unit vector 1(5) in a I-origin system, and 3(5) in a O-origin system.
(h) the infixes (a 5 (7) /\ w 5 (7)) and 2 t a 3 (7).
Exercises
1.2 Show that
(a) x /L l(n) = 11! (Include the case n
63
0.)
+--
(x > O)/x.
1.4
1.6 The ordered array of variables used to represent a variable x in S0111e coding
system 111ay be considered as a vector representation of ::r, denoted by p(~r). In the
8421 code for decimal digits, for exanlple, p(O) = (0,0,0,0), pel) = (0,0,0, 1),
and, in general, p(x) is defined by the relation + /[w x p(x)] = x, where w = (8,4,
2, 1). For each of the following coding systems, (see Richards, pp. 183-184 for
definitions), write a concise expression for p(::c):
(a) the excess-three code for decimal digits.
(b) any chosen two-out-of-five code.
(c) any chosen biquinary code.
(d) the semaphore code for the alphabet (see any good dictionary). Denote
each code by a two-component vector p(x) S; lO(8). Use a l:t', where
a = (a, b, c, ... , z).
1.7 Let X be a square sparse matrix represented by the logical nlatrix V =
(X
0) and either or both of the vectors r = V/X, and c = VIIX. Write pro
grams to determine the product Y = X ~- X, using the argunlents
(a) r, c, and U.
(b) rand V.
(c) c and U.
The language
64
1.8
Prove that
(a)
rrl
(b)
lla --:-
-l-.TJ.
bJ --:- cJ
la --:-
1.9 Let r = E/A, and c = EllA be the row list and colunln list, respectively, of
the nlatrix A, and let r ll , A/, and C k be corresponding elenlents of the three
representations of A.Deternline:
(a) h as a function of k, v(A), and fleA).
(b) k as a function of h, v(A), and fleA).
(c) the pernlutation vector h such that c = h r.
1.10
Show that
(a)
/u
(b) ;/ /u
=/u
/u
210 + /u (Use
210 +/u.
=/ii.
(c)
(d)
10 (U
induction.)
~- v).
(f) U c~\ V = U v V.
(g) (t Xu) !\ (v Xw) = (t
Aw)
/\ (v
7\
u).
(a) Show that +/x = +/(u/x) + +/(u/x). (Include the case u = 0.)
(b) What properties are required of an operator 0 that it satisfy the relation
established for + in part (a)?
1.12 Show that
(a) X x Y = (ii/X)
(iiIIY) + (u/X) ~ (uIIY).
1.11
(b) u/(X
(c) ull(X
(d) (u
Y) = X ;, (u/Y).
Y) = (uIIX) ~ Y.
v)/a = (u/v)/(u/a).
Use the result of Exercise 1.Il(b) to extend the results of Exercise I. 12(a-c)
to logical operators.
1.14 Write progranls to determine:
(a) the value of the polynomial x at the point a, that is, to evaluate (I/e) __ L x
for.ll = a. Use no nlore than vex) multiplications.
(b) the derivative of the polynomial x, that is, the vector z such that
1.13
(IJe) ~ Z
=-
dy
((I/e)
lJ(X).
(ae) J_ Z = b.
q and remainder r obtained in dividing the polynonlial n by
(I, -a).
d
(f) the value of - ((ye)
dy
_L n)
(g) an approxinlate real root of the equation (ye) 1_ x = 0, using parts (e) and
(f) and the Newton-Raphson formula [Kunz (1957)].
Exercises
1.15
Write
(a)
(b)
65
11
1.17 Write a progranl to deternline the nloduli of all roots of the polynonlial x,
using the Graeffe method [Kunz (1957)]. Assunle that operations for the logar
ithm and exponential functions are available as subroutines.
1.18 List all the I-origin perlllutation vectors of dinlension four which are self
lnverse.
1.19 Using I-origin indexing, write progranls to derive
(a) the pernlutation k which is inverse to the pernlutation j.
(b) a pernlutation j which transfornls a given logical vector u to a prefix vector.
1.20 A square logical lllatrix U such that +/U = +// U = is sonletinlCs called
a per/11utation nlatrix, since prenlultiplication of a nUlnerical vector x deterlllines
a pernlutation of x. Write programs to deternline
(a) the permutation matrix U corresponding to the I-origin pernlutation vector
k, that is, deternline U such that U
x = k 1 x.
(b) the pernlutation k corresponding to a given pernlutation 11latrix U.
(c) the pernlutation V which is inverse to the pernlutation U.
1.21 Let p be the vector representation of a pernlutation and let c be the
standard representation in ternlS of disjoint cycles, including all cycles of one
[Jacobson (1951), p. 34.] Each cycle of c is enclosed in square brackets, each
half-bracket being considered as a component of c. For exanlple, if c = (L I, 3,
5,], L 2,4,], L 6,]), then p = (3,4,5,2, 1,6), v(c) = 12, and v(P) = 6, and, in
general, v( c) = v(P) + 2k where k is the nunlber of disjoint cycles in p. The
usual elision of cycles of one would give c = (L 1, 3, 5, ], L 2,4, ]), but this deter
Dlines a unique correspondent p only if the dimension of p is otherwise specified,
and inclusion of all cycles of one will therefore be aSSUDled. If each infix of
numerical cOlllponents in c is preceded by a left bracket and followed by a right
bracket, and if c determines a legitimate pernlutation vector p, then c is said to be
well./()rnlcd.
(a) Write a progranl to deternline p as a function of a well fornled pernlutation
c. Include determination of the dimension of p.
(b) Modify the program of part (a) to incorporate checks on the well fornlation
of c. If c is ill formed, the vector p is to be defined as the literal "ill
formed."
(c) Modify part (b) to process a sequence of vectors cl, c 2 , ,each pair being
separated by a single null element, and the end of the sequence being
indicated by a pair of successive null elenlents, i.e., to process z =
C,.
c1
(0)
c2
(0,0). Include checks on the well fornlation
of each pernlutation.
(d) Write a progranl to deternline the parity [Jacobson (1951), p. 36] of a
pernlutation vector p.
66
1.22
The language
Write detailed progranls for the following processes:
JI
(b) y -(~- nl
x
(c) V +- u r x
(i) nl-(--bl o a
(j) M -(- B ~o a
(k) u -(- b(l
(d) V-(ur X
(e) v -(- 'l..lu
(f) V-(wjjU
(g) v -( alb
(h) V -(- TjjB
c -(- b n a
(nl) c -(-- b L\, a
(n) c -(- b u a
(0) C -(- a (:) b
(I)
1.23 (a) Copy onto file (1)1 2 successive groups of itenls fronl the row of flies (1)1
in cyclic order, onlitting any exhausted files. The end of each group is
denlarked by a partition A2 , and the end of each file by a partition Aa .
(b) A file which is always recorded in the forward direction and read in the
backward direction functions as a stack. Using flle (1)2 2 as a stack,
nlodify the progranl of part (a) so as to reverse (in the output tile (1\2)
the order of the itenls within each group.
1.24 The acconlpanying node vector n and connection nlatrix C together specify
a directed graph (C/ = 1 indicates a branch fronl node i to node j) which is, in
fact, a tree.
n = (a, h, C, d, c, ,f, g)
C=
0
0
1.25
1.26 (a) Give an exalnple of a well fonned right list which denl0nstrates that a
prefix of a right list is not, in general, well fornled.
(b) Show clearly where the argunlent used in establishing the well fornla
tion of any suffix of a well fornled list breaks down when applied to a
prefix.
Trace Progranls 1.20 and 1.21 for the tree of Exercise 1.24.
1.30
Y, where
y=
v(H).
68
The language
colunlns independently, i.e., there are no carries. (The sunlS must
also lie within the specified range.)
(c) Discuss the choice of moduli for extending the range of the representa
tion.
(d) Show that the algorithm derived in part (b) is valid for all positive and
negative integers in the range -a12 :::;: n < al2 for a = 2 x 3 x 5 x 7.
(e) Derive an algorithm for obtaining -n fronl n.
(f) Derive an algorithm for multiplication.
(g) The sign of the number (i.e., its relation to zero) is not displayed
directly by this representation. Convince yourself that its deternli
nation is nontrivial.
1.36 Let x, y, and z be the positional representations of the nunlbers .r, .'I, and z
respectively. Using the floor and residue operations, write progranls to deter
mine z as a function of x andy, where z = J~ + y and the representation in use is
(a) base b.
(b) mixed base b.
(c) the +, -,0 base three system (of Exercise 1.34).
(d) the residue nunlber system (of Exercise 1.35).
1.37 Write programs for the multiplication z = x
Exercise 1.36.
X y
1.38 Write programs to convert in each direction between the following pairs of
number systems:
(a) base b l and base b 2
(b) base b l and base b 2
(c) base three and the +. -, 0 base three of Exercise 1.34.
(d) residue and base b (Exercise 1.35).
1.39
Exercises
69
ei
(b) The sequence of operations which reduce the ith colunln of A to is callec
the ith step of the process, and the ith diagonal elenlent at the beginning of
the ith step is called the ith pivot elelnent. Modify the progranl of part (a)
so that each step is preceded by a colunln pernlutation which yields the
largest (in absolute value) pivot element possible. This nlodification tends
to reduce the accunlulation of round-off errors.
(c) In the Jordan elinlination of part (a), it is unnecessary to store the identity
matrix explicitly, and, since the ith colunln is first affected at the ith step,
only one new colunln need be brought in at each step. Moreover, the ith
colunln of A may be discarded after its reduction to e i on the ith step, and
it is therefore necessary to store only a square nlatrix at all ti!nes. Show
that by shifting all columns to the left and by nloving the rows upward
cyclically, a very unifornl process results, with the pivot elenlent in the
leading position at every step [Iverson (1954) or Rutishauser (1959)].
Write a progranl for the process.
(d) Modify part (c) to allow the choice of pivot elenlents as in part (b). The
effects of the pernlutation on the not explicitly recorded identity cannot be
indicated directly, but the performance of the sanle set of pernlutations in
reverse order upon the rows of the resulting inverse produces the sanle
result. Verify this and prograrTI the process.
1.41 (a) Show that a group [Jacobson (1951)] can be represented by a square
matrix M such that each row and each colunln is a pernlutation vector.
(b) Show that M i = M; = II for sonle i.
(c) What are the necessary and sufficient conditions that the group repre
sented by M be Abelian?
(d) Write a program to deternline all cyclic SUbgroups of a group repre
sented by M.
1.42 If U is a logical nlatrix whose rows are each nonzero, nlutually disjoint, and
collectively exhaustive (that is, (+/U
e) = e, and +//U = e), then U defines
an 111-way partition of n, where 111 = li(U), and n = v(U). The partition is nlore
commonly represented by the vector p = +/U [Riordan (1958), p. 107]. Clearly
+ /p = n. Write a program to generate
(a) all partitions U of a given integer n.
(b) all distinct partitions of n, where U and V are considered equivalent if
p = +/U is a permutation of q = +/V.
1.43 Let x be a .'pace vector (i.e., of dinlension three), and let R(x) be the square
nlatrix l j (e !\ x). Sho\v that
(a) +/R(x x y) = (x x y) X e
(x
y) = x x y
(c) (+ / R ( x x y x (w x z) = (x ~- y) x (w ~- z)
(d) (x ~- y) x (x x y) = (x x y) x (x x y) + 2(lx
(b)
e;
x jy)
~ (lx
x jy).
1.44 Let x . y = (j x x ly) - (lx x jy) be the vector product of x and y for
vectors of dinlension three. Show that
(a) this agrees with the usual definition [Margenau and Murphy (1943)].
(b) x' y = -(y' x)
70
The language
1.45
Let [x]
\/ (x
t
t (y . z).
o.
x +y
= [ ] x [
x y]
be the cosine of
chapter
MICROPROGRAMMING
72
2.1
Microprogranlrning
2.1
INSTRUCTION PREPARATION
2 15 x 36
3 x 15
I ndex accumulators
Sequence vector
s (instruction counter)
15
Command vector
36
Upper accumulator
Lower accumulator (Quotient register)
II
o.
f { 1:
2:
norn1al
skip channel trap
skip trap and fetch phase
o.
no indexing
1: normal indexing (15 bit)
restricted indexing (9 bit)
I ndexing class
kO(c)
{ 2:
k 1(
fo:
Table 2.1
C)
no indirect addressing
ll: indirect addressing
r
p( z)
38
36
2.1
Instruction preparation
73
Each instruction is a full word selected from M, and the seq uence in
which instructions are selected is controlled by a control register called the
instruction counter or sequence register. This register represents a logical
vector s of dimension 15 whose base two value determines the word i to be
selected in the next instruction phase. The quantity*Ls is increnlented
after each instruction fetch and therefore selects instruction words in
natural ascending sequence. The value of s may, however, be respecified
by the execution of certain branch instructions.
+-
Program 2.2
M ls
+--
J_a).
J(( I8 t
3
0. ) /
c)
I) ).
* Since nurnber bases other than two will be used but rarely in the present chapter,
the elided form -.L x will be used instead of (2e) _~ x.
74
2.1
M icroprogranll11ing
two value of the vector obtained by oring together the selected rows of [.
The oring of the index accumulators permits simple circuits for their
selection. It is, however, of questionable value to the programnler, and
the 7090 index registers are normally used individually.
Indirect addressing
It is often convenient (as in the execution of a pernlutation) for a
programmer to specify a data address indirectly, i.e., to specify the address
of the word containing the desired data address. Such indirect addressing
could proceed through several levels, but in the 7090 it is limited to one.
C 12 /\ C 13
wI8jc -(_ w I8 jM Jw 15 jc
Program 2.3
I ndirect addressing
+---
Vj(W15jM~Vj(w15jC)).
If, for exalnple, v = a 7 , and the format is otherwise as in the 7090, then
columns 21-27 of registers 0 to (2 7 - 1) provide the base addresses for
2.1
successive blocks of 2 8 registers each.
relocation.
Instruction preparation
75
* 7090 instructions will be referred to by the mnemonic codes used in the IBM Alan[{a!
(1960).
76
Microprogramming
2.1
Instruction execution
2.2
>
.l:
1
: 0
eE /\ T
.i
. 5
(15
+ jaj
+-
/\ j(eE /\ T)
lO-+2j -<-- W
c -<-
(1.3)j M
15(36)\s
10 --j2j ~-
Mll+2j
-<-M~s
+ _ s)
]1
f'
~O
12
-<-
13
kO(e) : 1
14
15
Jw 9 je
16
a : 0
1R
(/
i = (1 8
(eE /\ T)j
J.s -<-2151 (I
10
77
-<--
k 1( e) /\ e 12 /\ e 13
>
I (J_w15 je
-<- 29 (J w 9 jc 1
L(i
X I))
J (i ::: w 9 jl)
t (1.3) Ic
Program 2.4
2.2
INSTRUCTION EXECUTION
The execution phase begins with the "decoding" of the operation part
of the command c to select the appropriate microprogram to be executed.
78
A;ficroprogramn1ing
2.2
Except for the format of the operation code* (which in the comn10n case
occupies the prefix a 12/ c) the details of the decoding are, however, of no
interest to the programmer, and attention will be confined to the execution
microprogran1s. These may be grouped into a small number of falnilies;
for the 7090 they are load and store, branch, logical, arithnletic, shift,
concert, and input-output.
Certain of the arguments and results of the computer instructions are
represented by three central data registers to be denoted by I, u, and d.
The registers u and I serve as accumulators in the addition and other
arithmetic operations, and, since u and I jointly represent double precision
numbers (i.e., carries are in some operations propagated between the high
order end of I and the low order end of u), they will be called the upper and
lower accumulator, respectively. Since I receives the multiplier in a
multiplication and the quotient in division, it is called (in the 7090 manual)
the Multiplier-Quotient or MQ register, and the letter Q occurs in the
mnemonic code for instructions affecting it.
Signed numeric quantities are represented in base two with the sign in the
first component, i.e., register i represents the quantity y = (1 - 2 MOi) x
(~al/Mi). The lower accumulator I is, like each memory register, of
dimension 36, and the sign of a numeric quantity is represented by 10 ,
The upper accumulator is of dimension 38 and represents the number
(1 - 2u o) x (~a.l/U). The two extra components u 1 and u 2 are called
orerfioH' positions and are excluded from normal transfers of data fron1 u
to the memory. The component u 2 (called the p-bit) is, however, included
instead of the sign bit U o in certain logical instructions. The component
u 1 (called the q-bit) is made accessible only by certain shift operations.
The register d (distributor) serves only as intermediary in transfers
between main memory and the central data registers u and I and is not
accessible to the programmer.
Instruction execution
2.2
11
Load Q
11
Store Q
11
LDQ
I *- M.
STQ
M.; w 15 jc
SLQ
jc
-0(
15
I
a 18 jl
--+
jc +-- ( ~ a,2)/U
--+
a18jM' w
15
15
jc
+-
Store
11
STO
M-
Store zero
11
STZ
Store address
11
STA
W15/M.:.w15jc +-- W 15 /U
Store decrement
]I
STD
(3 ~ ( 15)/Ml.w 15 jC
Store prefix
II
STP
a 3 /M
Store tag
JI
STT
Store instruction
location counter
11
STL
W 15 /M! w
11
SLW
Program 2.5
79
~ w 15 jc +--
.w
15
jc +--
15
-0(
(5 ~ ( 15)/u
(2 ~ ( 3)/u
15
jc
-0(
(20 ~ ( 3)/u
jc +-- S
w 15 jc -(- (j2/ U
normal numeric part of u (that is, all but the overflow bits), whereas SLW
(store logical word) stores the p-bit instead of the sign.
The instructions which load and store the index accumulators (ProgralTI
2.6) are of four types, as indicated by the leading letter of each of the
mnemonic codes, L for load index from memory, S for store index in
memory, A for load index from the address of the command register~ and
P for place the index in the upper accumulator or the upper accumulator
in the index. The portion of nlenl0ry, command register~ or upper
accumulator involved in each of the ten instructions which specify the
index is shown in steps 1-10. The last fi ve of these differ from the corre
sponding nlembers of the first five only by complenlentation on 215~ as
shown in step 11. Since the subtraction occurring in indexing (step 14 of
Program 2.4) is reduced modulo 21.\ the effect of complenlentation is to
add rather than subtract the quantity used to load the index aCCUlTIU
lator.
Step 12 shows that the index accumulators specified are selected by the
three-bit tag vector i == (18 1a. 3 )jc and that each receives the same specifying
quantity. Since the tag vector is used to select the index registers to be
specified, it cannot also be used to specify indexing of the instruction
itself, and, consequently, none of the load and store index instructions are
indexable. Neither do they permit indirect addressing.
80
2.2
M icroprogral1l111 ing
00
LXA
00
LXO
2
15
00
AXT
+- W
00
PAX
+-
00
POX
Load complement of
address in index
00
LAC
Load complen1ent of
decrement in index
00
LOC
Address to index
complemented
00
AXC
00
PAC
Place decrement in
index complemented
00
POC
00
00
00
w 15 1u
(5 ~ a 15)lu
X +-
i III
00
_L x
/c
+- 215
+-
10
I ( - _l
x)
e( + Ii) ;, x
SXA
SXO
(3 ~ a 15 )IM ~_w15/C
PXO
u -(-tl -(-
w1f>/c --
w 15 (38)\(i
(5
12
i XI
W151M,
PXA
11
--
J3
i \ I
X 1)
~ a 15 (38))\(i
14
15
I)
]6
(i = (18 ~ a 3 )lc)
Program 2.6
The last four steps show the storing of the index accun1ulators. The
quantity stored is the or function of the accumulators selected by the tag
(18 1 a:3)jc.
Branch instructions
The basic branch instructions are of two main types, the transfer
z.Jenoted by a leading Tin the mnenlonic code) and the skip. The behavior
of the skip instructions is shown in steps 1-10 of Progranl 2.7, and is
typified by the PST (p-bit test) of steps 1 and 10. If the p-bit of the upper
2.2
81
Instruction execution
p-bit test
10 PBT
10 LBT
s -(-- U 37
11 ZET
S +-
Storage nonzero
test
11 NZT
S -(-
E: \~:c M _Lw 15 jc
Compare accum
ulator with storage
11 CAS
6c
2
M _~w15jc
4
5
6
Logical compare
accumulator with
storage
11 LAS
~-
_Ls
+-
+ (d
l(s + J_S)
0)
(d
2
1ii
0)
<}
10
Execute
It XEC
c +-1\"11- w 15 jc
11
f~-
12
00 STR
wF)jM+-s
.-is -(-
13
14
Leave
mode
trapping
10 LTM
t -(- 0
----+
15
Enter
mode
trapping
10 ETM
~-
--+
16
11 TTR
+-wl.'jc
Trap transfer
Console
reset
clear
or
Program 2.7
(1, f,
[(, I, h)
--+ 17
+-
~~18
82
2.2
Microprogranlnling
(~(i
00 TXH
00 TXL
b -(-- ( ~ (i
XI)
XI)
Transfer on index
00 TIX
b ..;- (~(i
XI)
+-
Y -(- _L(i
XI)
J_ (3
t o.};)jc)
t o. )jC)
-i (3
~(3
- .l(3
15
o. 1 ;)jc)
t o. ;)jc
index
XI) ~ ~ (3 t o. ;)jc)
.If -(- I (i XI) + ~ (3 t o. ;)jc
_L ilII -(.- (2 :Jly)( + ji)
J. il II -(- (2151( - _Ls( + ji)
b -(- (~(i
00 TNX
00 TXI
=1=
00 TSX
Transfer
Halt and transfer
II TRA)
]1 HTR
h -(-- 1
Transfer on zero
11 TZE
h +-(a. 1 ju)
LE
11
Transfer on nonzero
]1 TNZ
h ~- (a.Iju)
'!;:
12
10
13
Transfer on plus
11 TPL
Transfer on minus
11 TMI
14
15
Transfer on overflow
11 TOY
Transfer on no over
flow
11 TNO
(b, u) -(-
Transfer on Q plus
11 TQP
Transfer on Quotient
overflow
11 TQO
Transfer on low Q
11 TLQ
(ii,
17
b -(- b V I ~
-=1=
=1=
18
0.
1\ (u ~
19
20
t: ]
21
b : 0
22
S -(-W 15 jc
23
w 15 jMO -(- s
24
b : 0
25
-is +-
Program 2.8
16
0)
26
o. jc : p(HTR)
27
r -(- 0
28
r : 0
29
12
2.2
Instruction execution
83
Logical instructions
The logical operations (Progranl 2.9) concern the logical part of ll,
which differs from the numeric part by including the p-bit rather than the
sign, and hence comprises a,2/U. The first instruction of the family (ORS)
produces the logical or of the word selected fronl storage with the vector
a2/u and returns the result to the sanle location in storage. The instruction
ANS (and to storage) is similar. In the ORA (or to accumulator) the
15
result u is of dimension 38, and the second operand (that is, M w /C) is
expanded to this dimension by inserting two leading zeros before oring
it with u. The instruction ANA is similar. It is easily verified that ORA
leaves the extra bits unchanged and that ANA resets them. The ERA
(exclusive or to accumulator) is anomalous in that it resets the extra bits.
The ACL (add and carry logical) is normally used only in certain parity
check algorithms. It adds the selected word to the logical part of u,
treating both as 36-bit positive base two numbers, again adds any resulting
84
2.2
M icroprogral11111ing
15
w 15 /C
(a 2ju) V M
Or to storage
11
ORS
M_Lw
Or to accumulator
II
ORA
+-
And to storage
II
ANS
L w15(C +-
And to accumulator
11
ANA
+-
Exclusive or to accumulator
11
ERA
+-
(u
* (a2
a2ju
+-
+-
Cilju
/C
+-
u V (a2 \MI
10
COM
Cilju
Clear magnitude
10
CLM
a1ju +-0
Change sign
10
CHS
o +- U o
10
SSP
o +- 0
10
SSM
o +- 1
11
SLW
M_i_ w15 / C +-
11
CAL
1 ACL
+-
/C)
(a2 ju) 1\ M
15
w15/C
/C))
a 2ju
a 2\M_Lw 15 /c
_L(a2ju)
J_M_Lw
Program 2.9
15
\Mlw
Complement magnitude
+-
+ (y
15
(c
236)
Logical operations
overflow to the low order end, and places the result (which will not exceed
1) in the logical part of u. The behavior of the remaining logical
instructions is evident from Program 2.9. As shown by the class functions
k O and k\ five of them do not permit indirect addressing. *
2~~(j
Arithmetic instructions
The description of arithmetic instructions will be illustrated by the family
of fixed pointt add instructions shown in Program 2. 10. The CLA (clear
and add) transfers the selected memory register to u, resetting the two
* Since each of these five instructions involves the accumulator only, the normal
address portion W 15 Ie does not represent an address, and its last three components are
used in representing the operation code itself. The possibility of indirect addressing
would suggest to the programmer the nonexistent possibility of specifying an arbitrary
indirect address in w 15 je.
t The 7090 incorporates three arithmetic functions: addition, multiplication, and
division, each of which nlay be performed in either a fixed (radix) point or floating point
nlode.
Instruction execution
2.2
Clear and
add
11
CLA
u +- (
f (i2)\M Jw 15 /c
Clear and
subtract
11
CLS
f ( 2)\(al
+-- (
15
:f
M _~w15/C)
85
----+
Add
11
ADD
d +- M--
Subtract
11
SUB
d +- (a l ~~ M
Add
magnitude
11
ADM
d *- (il 1\ M:
Subtract
magnitude
11
SBM
Round
11
RND
/c
3
w
15
15
/C)
/c
9
~al/u +-2 37
II
U
1(lzl)
*- U V x :j=
u 2) 1\ (U o = do))
o +- (z < 0) V (u o 1\ (z = 0))
Program 2.10
10
11
12
Add instructions
overflow positions. The CLS (clear and subtract) differs only in that the
sign is reversed in transfer.
The instructions ADD, SUB, ADM, and SBM each transfer the
selected word to d with an appropriate sign, add it to the nun1ber repre
sented by u (including the overflow positions), and place the sum reduced
modulo 237 in u. The sign of a zero result is (as indicated by step 12) the
sign of the number originally contained in u.
'The overflow indicator u is set only by a carry (but not a borrow) [ron1
u 3 to u 2 . This indicator controls, and is reset by, certain branch in
structions.
The RND (round) instruction is used to round up the n1agnitude of the
number represented jointly by the upper and lower accun1ulator by one
unit in the high order position of the lower accumulator. As shown in
Program 2.10, the content of the upper accumulator only is actually
affected.
Shift instructions
In describing computer instructions, the term left shift of a vector x by r
places refers either to the left rotation x +- r i x or to the left rotation
86
2.2
Microprogramming
combined with a reset to zero of the last r "vacated positions," that is,
x
+-
(r
x) 1\
wr
Both types of shift occur in the 7090 and concern various portions of the
entire accumulator u EB 1, as shown in Program 2.11. The portion affected
is determined by the mask vector m.
+-
X(mj(u
V (a r
mj(u EB I)
+-
(r
t (m/(u 8)
Accumulator left
shift
10 ALS
+-
(il(38)
(f)
(36)
10 LLS
+-
(il(38)
~E\
(il(36)
10
LGL
+--
Accumulator right
shift
10 ARS
~-
(il(38)
10 LRS
~-
(il(38) c) (il(36)
10
+-
LGR
m/(u 8) I)
+-
10 RQL
I+-rt l
Exchange accumu
lator and MQ
00
( ~ a2)/u ~-~ 1
(
(i2)/U
-0(-
I))) 1\ wl'
(36)
Rotate MQ
XCA
I))
(r
Exchange logical
accumulator and MQ 00- XCL
_lw 8 jc
Program 2.11
Shift instructions
The first three instructions are left shifts. Each sets the accumulator
overflow indicator if any nonzero bits are lost, i.e., if any of the first r
positions of the affected portion are nonzero. The next three are analogous
right shifts, which do not, however, set the overflow indicator. In the
Instruction execution
2.2
87
"long" shifts LLS and LRS, one sign position specifies the other, although
the sign positions are otherwise excluded from the shift by the mask m.
The LGR shifts all positions save the sign of u; RQL rotates MQ
without resetting any positions; and XCA, which "exchanges" the
accumulators, is effectively a rotation except that it resets the overflow
bits. The amount of shift r is in each case determined by the base two
value ofw 8 /c.
Convert instructions
Each convert instruction (Program2.12) selects a six-bit infix of one of the
accumulators, adds its base two value to a "base address" initially specified
by the address portion of the instruction, and selects the men10ry register
00
00
CAQ}
CRQ
3
d
+-
1+-6t 1
j +-j -
_L a. 6 II)
a.lOlc : p(CAQ)
a. 6 II
+-
_La.! lu
00
a. 6 Id
10
+- 2 37 /(
_~Cil/u
+ : d)
11
12
CVR
d
+-
13
<
j +-j 1
a
2 l5 j( lW 15 1d
+-
~w6Iu)
d +-Ma
Cil/u
6
+-
a. j"a lu
Program 2.12
14
15
16
(6
f (al/u)) /\
+-
Ci6
6
Convert instructions
17
18
88
Microprogralnlning
2.2
Input-output instructions
Because the data transmission rates of input-output equipment serving
a computer are n1uch lower than those of the computer proper, computer
systems are normally designed to permit concurrent operation of the
computer and one or more input-output units. The units are therefore
more or less autonomous.
In the 7090, the autonomy of input-output equipment is carried further
by providing eight data channels which transmit data to, and are controlled
by, the computer proper, and which in turn control and accept data from
the individual input-output units. The entire input-output process there
fore con1prises three levels of microprograms: a semiautonomous input
output unit controlled by a semiautonomous data channel controlled by
the cOlnputer proper.
Attention will be restricted to the magnetic tape input-output units of
the 7090. Each unit is available to one specific data channel i (for i =
o - 7), and a particular unit can be characterized as the file $/. The unit
is completely autonomous only in certain simple operations, such as
reH'ind, write end offile, backspace, and continue to end of record. Except
for these special operations, a given data channel can control only one of
its files at a time. The eight data channels may, however, operate con
currently under control of the computer proper.
Each channel i behaves as a subcomputer with its own sequence vector
Si, command vector Ci, data register Di, and other miscellaneous operands,
as shown in Table 2.13. The instructions of the subcomputer (listed in the
matrix K) are called channel commands and differ from the instructions of
the computer proper in both format and function.
Tape Units. Each tape unit behaves as a file (Sec. 1.22); each recorded
component is an alphanumeric character represented in a seven-bit odd
parity error-detecting code, the lowest level partition Ao is represented by
the intercharacter space on the tape, the second level partition Al (called
an end of record gap) is a longer blank space on tape.
Each record gap is immediately preceded by a parity check character
which is appended to the normal data of the record to permit an even
parity "longitudinal" parity check on each of the seven-bit positions of the
Dimension
Channel data registers
8 x 36
8 x 15
8 x 36
Channel trap
r Toi
~I
I
.
L T 2 'l
: End of file A2
:
Parity check
Channel command
8 x 3
8 x 3
Busy indicator
8 x 2
8
8
o : Normal
Functions
read-\vrite
Current character
(reload)
8
8
8 x 7
8 x 7
1 if character Xi is loaded
Interlock vector
Xi
8 x 36
8 x 2
Input-output indicator
c d
IOCD
TCH
Channel commands
r p
IORP
r t
IORT
c P IOCP
c t IOCT
s P
s t
Table 2.13
IOSP
lOST
Channel operands
89
90
2.2
M icroprogralnlning
Dinlension
Zl
PI
AI
B ~ 8 x
wi
F
RIJ
AO intercharacter gap
File partitions
A Al inter-record gap
Table 2.14
The tape unit parameters are listed in Table 2.14, and the operation of
tape unit (1)/ is described by Program 2.] 5. The unit idles at step 5 until its
busy indicator B/ is turned on by data channel i. After a starting delay of
about 650 microseconds reg uired to accelerate the tape and reach the
beginning of the record, one of four functions (listed under f in Table 2.13)
is perfornled as determined by the function indicator F/.
If F/ = 0, a normal read or write is perfornled under direct control of
the data channel as detailed in steps 18-37. If F/
0, one of the several
completely autononlOUS operations is initiated. If F/ is not zero and
W/ (write indicator) is unity, the autonOITIOUS function write end oj'file
is performed by steps 1-3, after which the busy indicator is turned off and
the unit returns to idle status. The end linlit indicator Lli is set by step 3
if the tape position exceeds a limit v set by a reflective marker attached to
the tape a short way before its extreme end.
If W/ = 0 and if F/ = ], 2, or 3, the unit backspaces to the next earlier
record gap, to the next earlier end of file position, or to position zero,
respectively. The last is called relt'ind. If, in backspacing, the tape becomes
<V/ ~A2' AO
<v j i
Lli ~ Lli
Bji
B/ : 0
starting delay
~ A2, Al
F/ : 0
Wji : 1
Rji
=
~
LOi ~ LOi
12
Z/,
=F
V (Fji:::j= 3)
pji : Ao
Fji :
R/ :
-d:::.
<D/
20
21
Pi ~P/
22
Xi
23
~p(Zji)
25
26
A2) x (R/ - 1)
Aji : 1
f-
Xi
<
29
30
p(Zji)
<D/
gi
yi
~ Z/, Al
~O
Aji :
Program 2.15
> v)
31
32
28
<v j i ~ Zji, AO
gi : 0
27
Xi ~ 1
em
N
N
24
pji : AO
~1<V/
Rji ~ (Zji
16
A/ : 0
p(Zji)
Rji : 0
>
17
P/
P/
11
15
19
~3
7T(<D ji) : 0
W/ : 1
Xi
10
14
18
Z/,
~O
13
V (7T(<v j i ) > v)
gi ~ gi V .11/
34
~
~
~.
35
33
;:::;:
36
37
~
~
~
s::
~.
;:::;:
'C
~
\0
N
T 2 i +- T 2 i V (r i J\ (kl
2 I,
==
t))
I k l : P
3 I I ~ r i J\ (k l
4 III
--
t) : 1
I (b i , A:) +- 0
B:i) :
I (B: FI W:
6 III
1
,
>
IJi : 0
: III
9 II~ri+-O
=
10 I I
I r i : 0
11 I I
I (Pi EB
12 I I
I (g i EB r i EB yi)
A: i EB Qi)
+-
+-
(A o' 1, 3, 0)
13 I ~ Ci +-M.lS i
rl.-LS
14
15
16
eft
<-
15
36
(k o =1= r) J\ ((3
10 +
a ;C i : p(TCH)
=F c) J\ (p i
a:15)jCi ~ e) : 1
.-LSi)
= AI) : 0
Xi : 0
40
I II
II 43
(=jXi) J\ Eli : 1
II 44
Q oi
Q oi
+-
+-
Si +- w 15 jCi
+-
~"'"':
a
CT.3
S
S
Vq
1-111 45
(Xi ~ p(A 2 ))
i
Q I V (Qoi
=
(Qoi - 1)
I
III 46
> 0)
AI) : 0
r-i II 48
III 47
III 49
~....:
:~
TOi
38
39
(Ql i = 1) J\ (p i
37
Pi +-A o
QI
Xi +-0
delay
35
Vi +- a:6 (36)
(k
I (b i V
5 II I
Di +-0
Eli J\ Q1 J\ (Qoi
0) : 1
~II
50
II
51
C,()')
18 I
C 18i
~ WI5/M~w15/Ci
wI5jCi
19
20
21
K-,-a. /C
Qi ~
T1i
22
(3 ~ ( 15 )jCi : 0
23
gi
24
gi : 1
VijDi
Di
Vi
25
(k o
yi
=I=
r)
~Mlw15/Ci
26
~wl5jCi ~
27
Vi
28
Xi
29
Xi ~O
215 1(1
l-w I5 jCi)
55
56
~O
Q oi
ill ::
0
~
aIjXi
~6 ~
II 59
Vi
*/
Vi : a 6
(3
a 6 (36)
a l5 )jCi : 0
~(3 ~
54
T1i V (V jyi)
a l5 )jCi
I Xi
(:l-jVijDi) E8 VijDi
M --,-w 15 /C i
31
I yi
~wl5jCi ~
32
~ Vi
+--
6.f Vi
33
V~
60
61
-1(3 ~ a l5 )jCi - 1
C 19i : 0
30
34
53
(3,0)
(V j yi) 1\ E 1 i
Wi:
52
Pi : AO
em
~
N
Di
215 1(1
~wI5/Ci)
62
63
64
I"":l
65
;::=
~
""":
s;:::
~.
~
~
~
I"":l
s;:::
~.
: a6
;::=
-~(3 ~
a l5 )jCi
~ l-(3 ~ ( 15 )jCi -
I
~
Program 2.16
Channel i
94
2.2
Microprogramming
20 WEF
k +-4
20 BSR
k +-1
20 BSF
20 REW
4
i
+-
bi
Ii
+-
Wi +-
Program 2.17
(-l(9
w 4 )jc)
k - 3 (k
(k
- 1
= 4)
= 4)
8
9
2.2
Instruction execution
95
Step 6 also makes the selected unit busy (B/ == 1), and hence starts it in
operation.
The normal read-write functions of the tape unit are described by steps
18-37. They are initiated by a branch from step 7 in the event that the
function indicator is zero. Over-all control by the channel is exercised
primarily through the association indicator A/, which is equal to unity if
unit j is logically associated with channel i, that is, if data are pennitted to
flow between them. If writing is in progress (Wji == 1) and A/ beconles
zero, the unit stops; if reading is in progress, the channel is freed ilnmedi
ately but the tape continues to a record gap.
Step 20 performs the read from tape, and if A / == 1, the partition read
is transferred to Pi' the seven-bit representation of the character read is
transferred to Xi (both for use by the channel), and the channel-unit
interlock Xi is set to unity to initiate appropriate disposition of the
character by the channel. If P/ is not a record gap reading continues, the
intercharacter delay (not shown) permitting time for the channel to
dispose of the character before the next is actually read. If P/ is a record
gap, the corresponding delay elapses before A/ is tested. If A/ == 0,
the branch to step 4 stops the unit. The tape stops only at a record
gap although transmission of data may be discontinued earlier by step
21.
The writing process begins at step 37 and nlay be discontinued before
any writing occurs (although the current record gap will be lengthened by
a few inches of blank tape). The main writing is perfornled by the loop
28-32, employing the channel interlock Xi. Step 31 sets the tape end lilllit
indicator. The loop terminates (step 32) when the HTite record gap
indicator gi is set to unity by the channel. Steps 33-36 then write the
longitudinal parity check character Yi supplied by the channel, together
with the inter-record gap partition AI. The write loop is then re-entered
unless A/ == O.
Channel operation. Operation of a channel is initiated either by one of the
special functions (WEF, BSR, BSF, REW) already described, or by a
WRS (write select), or an RDS (read select). The loading of the channel
command Ci required to control the two latter functions is, however,
controlled by a subsequent RCH (reset load channel), which transfers to
Si the address in memory of the desired channel conlnland.
The WRS (Program 2.18) selects the channel i specified by a portion of
its address, waits until the channel is free, sets its tape unit index t i as
specified by another portion of the address, sets the write indicator Wi to
unity and the function indicator ii to zero, and, finally, sets b i to start the
channel. The fetch mode indicator j' is also set to one so as to skip the
\0
0'\
5
e)
20 WRS}
20 RDS ~
i
bi
-L(9
t ( 4)jc
e)
- 1
8
i ~ -Lw jc
Wi
~ (a jc ~ p (WRS
3
Ii ~O
.f~
LCH
~ -L(1 ~
+ Co
ri
10
ri
/\
bi
11
bi
Ci
~O
bi
11
12
~ 113
14
i +- -L(1 t all)jc - (8e) ~ (5, 4, 0) + Co I
h +-1
11
RCH
h +- h V
bi
o --+
Si
bi
Channel i, 9
~ w 15 jc
ri+-l
Program 2.18
J.s
I 15
16
I 17
h---J 18
~
19
em
N
2.2
Instruction execution
97
channel trap on the next instruction fetch. This prevents a trap frolll
intervening between the WRS and the following instruction (which is
nornlally an RCH). The RDS differs only in the setting of Wi on step 4.
If the channel is not busy (i.e., not selected), the RCH instruction
(Program 2.18) selects the channel specif1ed by a portion of the operation
code, sets the input-output indicator h, and copies the instruction address
to the channel sequence vector Si. If the channel is busy, the RCH
instruction sets the selected channel to its step 9, whereupon" the channel
waits on the interlock at step 10. Meanwhile, step 18 of the RCH sets
Si and step 19 sets the interlock 1'"i so that the channel Inay proceed.
Steps 13 and 14 of the channel operation load the channel conllnand
register Ci and increment the channel seq uence register Si. Ifthe comnland
is a TCH (Transfer in Channel), step 16 causes a branch to a new seq uence
of commands. If not, the ll'ord count, represented by (3 1 a.L/Ci, is
tested. Ifit is zero and if the current command is either an IOSP or IOCP,
the branch to step 13 immediately fetches the next COlnn1and in seq uence.
Otherwise, indirect addressing of the conlInand occurs (step 19) unless
C{K is zero.
Step 20 specifies k according to the class of the command being executed.
The cOlnnlands are listed in the nlatrix K of Table 2.13.
The first cOlnponent KOi assumes the value c, r, or s according as the
COl1lnland having code i is terminated by a word count test, a record gap,
or by either (signal). The second component K 1 i assunles the value d, p,
or t according as the channel discontinues operation, proceeds to the next
cOlnmand in sequence (as determined by SI), or transfers to an LCH
(Load Channel) instruction which may be awaiting execution by the
computer proper. Execution of the LCH (Progranl 2.18) is delayed at
step 1I and branches to step 18 (to respecify Si in the nlanner of the RCH)
only if the channel reaches step 3.
Channel operation continues on the right-hand segn1ent (steps 35-65) if
the operation is a read (w i == 0), and on the left (steps 22-34) if it is a
uTite. In the latter case, a zero word count causes in1nlediate ternlination
of the current command.
The norn1al tern1ination of a command in either read or write n10de
occasions a branch to step 1, where the tests for continuation begin. Step
1 sets the Channel Conllnand Trap indicator T./ if the current conlInand is
of the transfer type and an LCH (Load Channel) is not awaiting execution
in the con1puter proper. If the con1nland is of the proceed type, step 2
branches to step 13, where the next comn1and in sequence is fetched. If the
comnland is of the transfer type and an LCH is waiting (1'"i == 1), step 3
branches to step 9 to reset parameters and permit the channel to be reloaded.
1Il all other circulllstances step 4 is executed to disassociate the unit fro III the
98
M icroprografJun ing
2.2
channel and to return the channel to idle status. In read status, certain
abnornlal events-the occurrence of a parity error, or an end of file
partition-return the channel to idle status ilnmediately, regardless of the
type of command being executed.
The write operation (steps 22-34) is relatively simple. If the word
count in (3 1 0. 15 )/ Ci is zero, steps 23-24 ternlinate the current conlnland
but first initiate the writing of an end of record gap* if the comlnand is of
the "record" type (e.g., an IORP). If the word count is not zero, step 25
transfers to the channel data register Di the memory word selected by the
address portion of the command. The loop 28-33 transfers to the tape
unit successive six-bit infixes of Di and maintains the longitudinal parity
check Yi (originally reset on step 12). When all six have been transferred,
the branch to step 34 decrements the word count and, unless it beconles
zero, repeats the entire process from step 25.
The read operation (steps 35-65) begins by resetting D i to zero and the
infix selector Vi to a G Step 37 ternlinates the current conlnland if it is of
the count or signal type and the word count is zero. Steps 38-39 tenl1inate
the command if it is of the record or signal type and if the last file partition
read is a record gap. The partition indicator Pi is reset to Ao by step 39.
Thus a record gap present when termination is caused by a zero count is
still present on the first execution of the succeeding conlmand, whereas a
gap which itself causes termination is not present on the succeeding
command.
Steps 40-43 show the data interlock, the deternlination of the longi
tudinal parity check, and the setting of the parity error trap T 1 i in the
event of a parity error in the character. If the corresponding channel trap
is enabled, step 44 causes immediate ternlination in the event of a parity
error. Steps 45-48 detect an end of file configuration (using a counter,
Qoi in a manner similar to that used in Program 2.15), set the indicator
Q/ if a partition character A2 appears at the beginning of a word, and
cause termination (from step 49) \vith the end of file trap Toi set if an end
of file configuration occurs. If the character A2 occurring at the beginning
of a word is not part of an end of file configuration, step 50 sets the tape
error trap TIl, and step 51 causes termination if the corresponding channel
trap is enabled.
Steps 53-56 are executed only if Pi is a record gap. They reset the
counters Qi controlling the end of fIle test, test and reset the longitudinal
parity vector yi, and may cause termination in the event of an error. Step
57 causes the character transfer of step 58 to be ski pped if the character is
* Since the partition Al is represented by a gap, the writing of one gap inlnlcdiately
following anothcr, with no intervcning data, has the effect (whcn subsequently rcad) of a
single rccord gap.
Instruction execution
2.2
~s
Input-output test
10 lOT
*-
215 1(1
_Ls)
h : 0
h
*-
*-
10 ETT
Transfer on channel
in operation
11 TeO
k *-1
i
~(1 ~
b *-(b i
"*-
t :
b : 0
MO
w I5 (36)\s
b : 0
Program 2.19
99
100
Microprogramn1ing
2.2
a potential end of file. Steps 62-65 decrement the word count and transfer
completed words to successive memory locations unless Cfn is zero. Step
61 suspends these operations when the word count reaches zero. Since
step 56 is followed by step 61, the occurrence of a record gap occasions the
(potential) transfer of a word to memory even though it is incomplete.
Because of the reset of Di on step 35, the incompleted part of the word is
zero.
Auxiliary channel instructions. Program 2.19 shows those branch instruc
tions which are controlled by indicators associated with the data channels.
Each indicator tested is also reset. The last four instructions shown are
subject to the trap mode.
11 SCH
i ~ 2 _1 (9 ~ a.:~) j C
bi
+ Co
e(36)
y~Ci
(3
a.,15)jy ~ Si
(Y18' Y20) ~ 0
M .lw 15 /C +-- y
11 ENB
y ~ MLw 15 /c
Eo
~w8jy
E 1 ~ (10 ~ a 8)jy
E2
~w8jy
-+
E~E
10 RCT
Program 2.20
2.3
101
y:o
~y
t (x 1\
+-
(x ::/= z)
Program 2.21
z)
102
M icroprogranll11 ing
2.3
Address
decoder
r: E (36) , - - - - - r
Adder
Figure 2.22
Data paths
c~d.
~ M~_a.
Exercises
103
pS : ,
where p
35
Il- (36)1
REFERENCES
FalkofT, A., (1962) '"Algorithms for Parallel-Search Menlories," l.A.C.M. (to appear).
IBM Reference Manual, 7090 Data Processil{f{ Systeln, (1960), Form # A-22-6528,
International Business Machines Corporation.
Phister, M., (1958), Logical Design of D{fJital Conzputers, Wiley, New York.
EXERCISES
2.1 Write 7090 progranls for each of the following operations:
(a) M8 +-- M8 V M9
(b) M8
+-
M8
Li
2.2
= (x
1\ u) V (y 1\ u)]
(or) and negation are nluch easier to produce than conjunction (and). Linliting
.. {y -(- w1jp
(11)
l p
-11p
-(~W
Microprogranllning
104
= (mIM)
I~ (mix).
chapter
REPRESENTATION OF
VARIABLES
3.1
106
Representation oj'l"ariahles
3.1
range of values is the set of physical states achievable by each device, and
its index is the address of the device. Each component of 1t Inay corre
spond to a computer register, an individual character position in a register,
or an individual binary digit within a character, depending on the degree of
resolution appropriate to the allocation problem considered. The O-origin
indexing normally used for cOlnputer addresses will be used for the physical
vector, but I-origin indexing will, throughout this chapter, normally be
enlployed for all other structured operands.
An index of the physical vector will be called an address and will itself
be represented in the (perhaps mixed) radix appropriate to the given com
puter. The Univac, for example, employs base ten addressing for the
registers, and (because of the use of ]2-character words) a radix of twelve
for finer resolution. The address of the fourth character of register 675
nlight therefore be written as 675.3. In computers which have two or
nlore independent addressing systems (e.g., the independent addressing
systems for main menlory and for auxiliary storage in the IBM 705),
superscripts may be used to identify the several physical vectors 1tJ
In general, the representation of a quantity x is a vector (to be denoted
by p(x)) whose components are chosen from the physical vector 1t. Thus
p(x) == kJ1t, where k is a mapping vector associated with x. The dimension
of the representation (that is, v(p(x))) is called the dimension oj'::c in 1t. If,
for example, p(x) == (1t lO ' 1tn, 1t17 , 1t IH ), then k == (10, 9, 17, 18), and the
dilnension of x in 1t is four. If p(x) is an infix of1t, then the representation
of x is said to be solid. A solid representation can be characterized by two
parameters, its dimension d and its leading address f, that is, the index in 1t
of its first component. Then p(::c) == (j'1 a d )/1t.
rex)
==
17
19
27
23
32
C()')
~
x3
x4
X2
Xl
1t 22
Representand
X5
I 1t 23 I 1t 24
Physical vector
(a) Representation of a vector x
r 11
r 21
r 22
r 12
r 13
')
r 14
r 24
r 25
r 15
Representand
~
1t 40
1t 41
1t 42
1t 43
1t 44
1t 45
1t 46
1t 47
1t 48
1t 49
1t 50
1t 51
1t 52
1t 53
1t 54
1t 55
1t 56
1t 57
1t 58
fi
59
Physical
vector
~
~
~
~
I 0
rex) with I
= 34
Actual
value
~
~.
~
~
~
""':
:::::
+ 4i + 2).
Figure 3.1
':J
~
~
Xl
I
X2
1
Xl
2
X2
2
~
~
t::i
~
c::;-
Figure 3.2
l-'
.....,J
108
Representation of l'ariahles
3.2
Linear representations
The representation of a structured operand is said to be lincar if each
component is represented by an infix of the form (/1 a d )/1t, where I is a
linear function of the indices of the component. For exalTIple, the
representation of the matrix X indicated by Fig. 3.2 is linear, with d == 2
and I == - 11 + 5i + 8).
A linear representation is solid and can clearly be characterized by a
small number of paran1eters-the dilTIension d of each component and the
coefficients in the linear expression /. The representation of a vector x is
linear if and only if r 2 (x) == de and the difference () == r/(x) - r~ lex) is
constant for i == 2, 3, ... , vex).
If I == P + qi + 'i is the function defining a linear representation of a
matrix X and if a is the leading address of a given element, then the leading
address of the succeeding element in the row (or column) is sin1ply a + r
(or a + q). Freq uently, the succession must be cyclic, and the resulting
sum must be reduced modulo veX) x r (or p(X) x q). The inherent
convenience of linear representations is further enhanced by index registers,
which provide efficient incrementation and comparison of addresses.
Linear representation of a structured operand req uires that all COlTI
ponents be of the san1e dimension in 1t. This common din1ension n1ay,
however, be achieved by appending null elements to the shorter C0I11
ponents. The convenience of the linear representation n1ust then be
weighed against the waste occasioned by the null elen1ents. Moreover, if
several vectors or matrices are to be represented and if each is of unspecifIed
total dimension in 1t, it n1ay be in1possible to allot to each an infix suffi
ciently large to permit linear representation. Consequently, a linear
representation is not always practicable.
3.2
109
Nonlinear representations
Since the use of the grid matrix imposes only the condition of solidity
for each component, it permits an allocation which is sufficiently general
for most purposes. The grid matrix serves in two distinct capacities: (1)
as a useful conceptual device for describing an allocation even when the
actual allocation is implicit in the program, and (2) as a paranleter
which enters directly into an algorithm and explicitly specifies the allo
cation.
If the grid matrix is used in a program as an explicit specification of the
allocation, then the grid matrix must itself be represented by the physical
vector. There remains, therefore, the problem of choosing a suitable
allocation for the grid matrix itself; a linear allocation is illustrated by
Fig.3.lb.
If the grid matrix rex) itself employs a linear representation, its use
offers advantages over the direct use of a linear representation of x only if
the total dimension of r in 7t is much less than the total dimension of x in
7t when linear representations are employed for both. This is frequently
the case, since each element of a grid matrix belongs to the index set of 7t
(that is, to lO(V(7t))), and the dimension of each element in 7t is therefore
both uniform and relatively small. Program 3.3 shows the use of the grid
matrix rex) and the encoding matrix C in determining the kth conlponent
of the vector x.
Program 3.3. A linear representation is assumed for rex), with elenlent r/(x)
represented by the infix ((p + qi + ~i) 1 aJJ)!Tt. Moreover, each eleI11ent of rex)
is assunled to be represented in a base b nunlber systenl. Step 1 detennines the
leading address of the representation of r lk(X). Step 2 specifies.1' as the base b
value of this representation, i.e., as the leading address of p(x k ). Steps 3 and 4
specify d as the dimension of x k in Tt, and step 5 therefore specifies z as the
representation of x k'
Steps 7-9 perfornl the decoding of z = p(x k ) to obtain z as the actual value of
xl." Since this process is normally perforI11ed by hUI11an or I11echanical I11eanS
(e.g., a printer) outside the purview of the programmer, it is here expressed directly
in terms of the encoding matrix C rather than in tenns of its representation. The
left-pointing exit on step 7 is followed only if z does not occur as an entry in the
encoding matrix.
The fornl chosen for the grid matrix is one of several possible. The two
columns could, for example, represent the leading and final addresses of
the corresponding representations or the dimensions and final addresses.
The present choice of leading address / and dimension d is, however, the
nlost convenient for use in conjunction with the notation adopted for
infixes; the logical vector (/ 1 ad) selects the appropriate infix.
3.2
Representation of variables
110
I
2
+-
+ qk + r x
p, q, r
.f +- b.l.((l t aY)jrt)
l+-l+r
+-
+- ( [
h ..;- /leC)
h+-h-l
z : ljCk
+-
b.l.((l
~
t ag)jrt)
ad)/rt
liCk
lJ
of rex).
.1'
+1
d
Dimension of p(x k ) in rt.
=I
Z
p(x k ).
ponents of x.
-------+
Legend
p(x k ) and z
Chained representations *
rex)
1 aY)/7t
by p(z) and by
3.2
respecifying
111
rex) as follows:
rex) =
17
19
70
27
23
32
rex)
rex)
P(Yl)
P(Y2)
=
=
(1t 17 , 1t 18 , 1t 19 , 1t 20 , 1t 21 , 1t22 , 1t 23 )
(1t 68 , 1t69 , 1t 70 , 1t 71 , 1t 72 )
(6, 8, 0, 7, 3, 6, 5),
(2, 6, 0, 5, 7),
and
112
Representation of variables
3.2
O-origin indexing for
vex)
11 (h +
1)
+--
----+
h : k
Dimension in 1t of elements of
the grid matrix.
bl-C(f + g) + a. )!1t
fJ
Z +- ( /
p(x k )
+--
+ a. d )/1t
+--
-a 2
(J
/z
only
h"r
+--
1t
-----+
Legend
Program 3.4
3.2
113
x +- v/x
executed on a forward-chained representation of x. The unused segments
representing the components of ii/x are returned to a backward-chained
stack or pool of available cOlnponents. A linear representation can usually
be used for logical control vectors such as v; in any case the problellls
involved in their representation are relatively trivial and will be subordi
nated by expressing each operation directly in ternlS of the logical vectors
and not in terms of the physical components representing them.
Program 3.5. In the major loop (6-23), k deternlines the index of the current
component VI,', and i andj determine the leading addresses of p(x /,) and p(x/; !1),
respectively. These three parameters are cycled through successive values by
steps 7, 8, and 12 and are initialized by steps 2,5, and 12. lf VI,: = 0, the infix
p(x/;) is returned to the pool by steps 21, 22, 23, and 6 so as to construct a back
ward chain.
The paranleter.r specifies the leading address of p(x 1 ) unless l'(X) = 0, in which
case J: is null. Step 1 ternlinates the process if ll(X) = 0, and otherwise step 4
respecifies.r as the null elenlent. If V = 0, this null value of.r renlains ~ if not, the
first nonzero component of v causes a branch to step 14. Since T = 0, step 15 is
executed to respecify :c as the leading address of p( (vi X)I). Step 16 then specifies 11,
the leading address of the last conlpleted conlponent of vlx. Step 15 is never
again executed.
Components of vjx other than the first nlust each be chained (in a forward
chain) to the preceding one. Hence the leading address i of a newly added conl
ponent nlust be inserted in the last preceding conlponent (whose leading address
is h). This is normally done by steps 18, 19, and 6 ~ step 20 respecifies h. If, how
ever, the component X k - 1 were also included, it would appear as the last conl
pleted component of vlx and would already be chained to the new C0111pOnent XI,'.
This situation is recognized by step 17 and occasions a branch to step 16. Step 16
then respecifies h and repeats the loop without executing steps 18, 19, and 6.
The process ternlinates when the cycle through the chained representation of X
is conlpleted, that is, when i returns to the original value of .r, preserved as t by
step 3. Step 10 is then executed, ternlinating the process directly if r(vlx) = 0.
114
3.2
Representation of variables
Otherwise, step 11 is executed to close the chain of v j x, that is, to insert f , the
leading address of p((vjX)l)' in the representation of the last con1ponent of vjx.
O-origin indexing for rt only
~c
i+-x
t+-x
+-
:.c =
~(;
k +-1
bl((r
k+-k+l
a 9 )jrt)
+- S
Index of v.
Leading address of p(x,J.
#
;
~)
11
b L((h
12
13
VI.:
14
+-
b _L((i
vjx.
+-
16
+-
i -
17
Vk - 1
18
r+-h
19
+-
20
+-
21
+-
22
s +-p
+-
Dimension in rt of ele
ments of grid matrices.
Base of representation of
elements of grid matrices.
a 9 )jrt)
15
23
a 9 )jrt)
+-
Logical vector.
9
10
i +-j
Legend
3.2
115
component. This notion is fonnalized in the chain list nlatrix of Sec. 3.4.
The same scheme can also be employed to produce an efficient combined
representation of two or more vectors which share certain COInnlon
components. If, for example, x j = Z!" , and chained representations are
used for both x and z, then x may be represented in standard form except
that component x j incorporates a secondary address, which is the leading
address of Zk+l. Moreover Z has a standard representation except that
Zk-I is chained to Xj' with an indicator to show that the secondary address
of the succeeding conlponent is to be used. Deletion of any vector
conlponent in such a shared systenl must occasion only the corresponding
change in the address chain of the vector, the actual representation of the
conlponent being deleted only when no associated address renlains.
Partitions
If the set a is the range of the cOlllponents of the physical vector 1t, and
if SOIne element, say aI' is reserved as a partition sYlnhol and is excluded
from use in the normal representation of quantities, it can be inserted to
denlark the end (or beginning) of an infix of 1t. If the vector Y is repre
sented by a single infix of 1t such that the beginning of component Yj+l
follows imnlediately after the terminal partition of Yj' then the structure of
Y is completely represented by the partitions, and Y is called a partitioned
representation. A partitioned representation can be used for more cOlnplex
operands, such as matrices, if a set of two or nlore distinct partition
symbols are provided, one for each level of structure. The distinct
partition symbols can, of course, be represented by multiple occurrences of
a single symbol a l rather than by distinct Inenlbers of a.
A partitioned representation is sinlilar to a double-chained representa
tion without end-around chaining in the following particular: beginning
from component Yi, the component Yj can be reached only by scanning
all intervening components between i and j in increasing or decreasing
order according as i < j or i > j. The fIle notation introduced in Sec.
t .22 clearly provides the operations appropriate to a partitioned repre
sentation of a vector, with conventions which suppress all inessential
references to the partitions themselves.
The use of a partition to demark the end of an infix is particularly
convenient when the infix must be processed conlponent by conlponent
for other reasons, as in the use of nlagnetic tape or other serial storage.
The partition also appears to be more economical than the grid lnatrix,
which it replaces. This apparent economy is, however, somewhat illusory,
since the reservation of a special partition symbol reduces the infornlation
content of each nonpartition component by the factor log2 (v(a) - 1) -:
log2 v(a), where a is the range of the conlponents of 1t.
116
Representation of variables
3.2
+--
v(x)
11 (h +
.l +-- b ~ (c'f t
h :k
40
-(-.l + g
4b
nJ
a1
4c
j +--j
4d
d +--j -.l
Z
p(x k) -(-
only
u1
Partition symbol.
(f t ad)jn
+--
h,.l
aJJ)jn)
=F
1t
1)
representation of x exclusive of
the terminal partition symbol.
aU jz
d
Dimension of z in n.
Legend
Pools
Components of the physical vector 7t in use for the representation of one
quantity must not be allocated to the representation of sonle other quantity.
The construction of a chained representation therefore poses one problem
not encountered in its use, namely, the specification and observation of
restrictions on the availability of components of 7t. The restrictions can
3.2
117
118
Representation of l'ariahles
3.2
therefore relatively slow. The use of marked and chained pools nlay also
be cOITIbined-all returned conlponents go to a marked pool which is left
undisturbed until the chained pool is exhausted, at which time the entire
nlarked pool is organized into a chained pool.
Summary
3.3
Representation oj'rnatrices
119
3.3
REPRESENTATION OF MATRICES
+ j,
+ /-1j.
h = vi
k = i
Consequently,
= lh -:- vJ =
j = v 10 h = l k
i
and
/-1 10 k,
-:- /-1 J.
lh -:- vJ + v 10 h
+ lk -:- IlJ.
x (v 10 h) + lh -:- vJ.
h= v x
to yield
Similarly,
k = /-1
x (/-110 k)
The pernlutation h which carries the row list r into the colunln list C
(that is, C = hJor) can be obtained directly from the foregoing expression
for h as follows:
The expression for the kth component of h is identical with the expression
for h above. Hence, if C = hJor, then ck = rhk = 'Ii as required.
If the row list (or column list) is itself represented linearly, then the
address of any component A / is obtained as a linear function of the indices
i and j. If either a file or a chained representation is to be used for the list
vector, then the components are processed most efficiently in serial order,
and the use of column list or row list is dictated by the particular processes
to be effected.
120
3.3
Representation of L1ariahles
6
A
L==
7
5
f==
Program 3.7. Step 2 yields the index in L of the first elel11ent of the ith row of A.
Step 4 deternlines its COlUI11n index j, and step 6 deternlines the index of the
succeeding conlponent. The process ternlinates at step 3 when the scan of the
row is c0111pleted.
If L 1 is chosen as a row list, the vector L:3 reduces to the form L:/, == k + I
or L:/ == c. Its function can then be served instead by incrementation of
3.4
Representation of trees
I-origin indexing
Ai +-0
2
k +-li
Ii
+-
121
L 2k
L1
L 2k
L 3k
Aji
+-
L 1k
+-
Ll;
Legend
Program 3.7
tation of A
the index k and by the use of the logical vector u = (L 3 = O) for deter
mining the end of each row.
The construction of a column-chained representation is analogous to
that of a row-chained representation, and the two representations can be
combined in a single matrix L which gives both row and colunln chaining
employing but a single representation (that is, L 1 ) of the nonzero elelnents
of A.
3.4
REPRESENTATION OF TREES*
122
Representation
(~r
3.4
variahles
tree~ both the right list and the left list are awkward to use for path tracing.
This function is better served by the chain list matrix, to be defIned as a
formalization of the chaining schenle suggested in Sec. 3.2.
,x, V~y,z).
l~epresel1tation
3.4
p
2
+-
123
I-origin indexing
( O)
i+-O
i : {l(Z)
scan.
subtree.
m +-0
r+-O
i : {l(Z)
i+-i+1
m+-m+l
(1 trees
+-
10
r : 1
11
+-
+1
Pj = p:(T j ).
- Zli
Legend
<
p E8 (m)
Program 3.9
(4) ~
Xi
= a i'
124
3.4
RejJresentation of variables
0.380
(0)
(1 000)
(1001)
(101)
(1 1 0)
(111)
Figure 3.10
In so-called fixed length coding the vectors Xi have a conlmon dinlension d, and
the decoding of a nlessage m (consisting of the catenation of vectors Xi) involves
the selection of successive infixes of dinlension d. If the probability distribution
of the characters Q I occurring in messages is not unifornl, more compact encoding
may be achieved by using variable length codes and assigning the shorter codes to
the more frequent characters. Decoding of a nlessage in variable length coding
can be perfornled only if the boundaries between the successive Xl are indicated in
some way.
The boundaries between characters in a message in variable length code nlay
be demarked by special partition symbols (which is inefficient) or by using a
prefix code in which no legitimate code point Xi is the prefix of any other legitinlate
code point, including itself. The index vectors of the leaves of any tree possess
this property; conversely, any set of prefix codes can be arrayed as the leaves of
sonle tree. Hence if each character of the set to be encoded is assigned as the leaf
of a conl11l0n tree, and if each character is encoded by the associated index vector,
a so-called prefix code is attained. Figure 3.10 furnishes an exanlple of a binary
code (i.e., the branching ratios do not exceed two) constructed in this nlanner.
O-origin indexing is used. The discussion will be limited to binary trees.
] f ii is the freq uency of the ith character and 1i is the length of the assigned code
(i.e., the length of path to the root), then the nl0st efficient code is attained by
minimizing the scalar producti x 1. This nlay be achieved by the following con
struction, shown to be optimal by Huffman (1952). First, the characters to be
encoded are all considered as roots, and the two roots of lowest frequency are
rooted to an auxiliary node (shown as a null elenlent in Fig. 3.10), which is then
assigned their combined frequency. The process is repeated until only two roots
relnain. The tree of Fig. 3.10 is optilnal with respect to the frequencies shown to
the left of the leaves. The appropriate conlbined frequencies are shown to the left
of each of the nonleaves.
Programs 3.11 and 3.12 show the construction of the tree T representing a
3.4
Representation of trees
T
125
~c
fJ.l(T) : 2
(8/I)ST
+-
+-
(8/I)Sf
-a 2//T\\
1--+
z+-c
+-
I-origin indexing
e(v(z))
v(f) : 2
+-
+-
e(O)
+-
(Olf)i
+-
x CD (((p
+-
8
9
3.4
RejJresentation of variables
126
:::;
t ex
I)
i : v(f)
z
+-
(0) ffi x
11
+-
(O/f)Sp
12
+-
(1
13
+-
(Olf )Sf
14- f
+- (
+ (p
~- ex 2 ))
CD
-a 2 1f
tree.
fi
tree of z.
Partition vector Pi is
subtree of z.
with subtrees in
ascending order on
frequency.
exPi)lz)
+1
10
-a2 /p
Legend
d'
n'
-n
I
1
2
2
g
0
3
u
0
t
4
3
2
0
8
9
5
6
a
b
18
16
26
24
9
20
p
d" nil
- - -
3
a
4
b
7
2
2
9
g
c
11
4
0
z
n
1
15
0
0
10
11
0
0
I
f
d
0
2
y
s
e
i
0
3
2
0
2
0
3
22
0
10
17
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
127
Representation of trees
3.4
3
0
0
1
4
0
0
i
w
h
e
p
x
c
q
1
a
3
0
0
0
k
h
23
nl
0
0
0
p
q
0
0
14
19
6
2
14
25
t
a
16
2
0
0
n
g
u
1
2
0
3
n'
- -
19
d'
-
19
0
0
21
nl
20
1
17
15
21
0
23
12
26
7
18
16
0
0
24
8
0
0
0
0
0
0
0
4
0
,')
3
22
10
2
1
s
x
24
26
0
0
25
13
11
15
12
21
1
4
0
0
P
x
13
11
::;
::)
(a)
(b)
(c)
Table 3.13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
128
3.4
Representation oj'rariables
k +-1
}+-O
d +- v(PI )
.i
+ jP I
vCr)
j+-}+1
5
6
I-origin indexing
>
rj
i+-k+rj-l
Pj
+-
p 2 i
d +- pli
10
k +- p 3 i
PI
Degree vector of T.
P2
Node vector of T.
P3
Chaining vector of T.
Program 3.14
matrix P
The set of (j + 1)th level nodes of the subtree T i are collectively called
thejthfilial vector of node i, and the first member of the first filial vector of
node i is called the heir of node i. (For brevity, the first filial vector of a
node will also be called its filial vector.) If each node is chained only to its
successor in the filial vector containing it and to its heir, the resulting
representation is called a filial-heir chain list. Fornlally, the filial-heir
representation of a tree T is a matrix F of dimension Il(T) x 4 such that
F 2 is a node vector of T, F 1 is the associated degree vector, Fa is a .filial
chain such that F:/ == j if node F 2 i is the successor of node F./ in the
smallest filial set containing it and F:/ == ifnode F 2 i has no such successor,
and F 4 is an heir chain such that F 4 i == h if node F 2 /1 is the heir of node F/
and F 4 i == 0 if F 2 i is a leaf. The filial-heir chain list is illustrated in Table
3.13c.
0
REFERENCES
Blaauw, G. A., (1959), '"Indexing and Control-Word Techniques," IBM Journal o(
Research alld Developl11ellt, vol. 3, pp. 288-301.
Brooks, F. P., Jr., and K. E. Iverson, (1962), (in press) Autol1wtic Data Proces.\il{f{,
Wiley, New York.
Burks, A. W., D. W. Warren, and J. B. Wright, (1954), "'An Analysis of a Logical
Machine Using Parenthesis-free Notation," Mathel11atical Tahles alld Other Aids
to COll1putatioll, vol. VIII, pp. 53-57.
Exercises
129
EXERCISES
The symbols a and c will be used exclusively to denote lower case and capital
alphabets defined as follows:
a = (0, a, b, c,
, z, . , , , #, *, +).
c = (0, A, B, C,
, Z, . , , , #, *, +).
The expression 1t S; x will be used to specify the set x as the range of the conl
ponents of 1t.
3.1 For each of the following cases, specify a suitable encoding n1atrix and
fornlat vector and show the explicit value of the infix of 1t which (in a solid
representation) represents the given exanlple vector x:
(a) the decinlal digits d = LUCIO) in a ranked fixed-length code for 1t S; lO(2).
Exanlple: x = (6, 8, 9).
(b) the set a in a ranked fixed-length code for 1t S; lO(2).
(c) the set a u c u lO( 10) in a fixed-length code for 1t S;; lO( 10).
(d) the set a u c in a two-case code (with single-character shift) for 1t S;; (I.
(See Brooks and Iverson, 1962.)
Exanlple: x = (T, r, 0, y, " N, . , Y, .).
(e) the set a in a Huffman prefix code for 1t S; lO(2). Assunle the frequency
distribution given in Dewey (1923).
Example: x = (t, r, e, e).
3.2
For each of the cases of Exercise 3.1 write a progranl which decodes the
infix (i 1 a.J)/1t, that is, which produces the vector z represented by the infix. The
auxiliary physical vector 1t l S;; S may be employed to represent the first colun1n of
the encoding matrix, where s is the set encoded. Perfornl a partial trace of each
program for the example value used in Exercise 3.1.
Representation oj'rariahle.\'
130
3.3
3.4 (a) For each of the cases of Exercise 3.3, write a progran1 which selects
n10nth mIl'.
(b) Trace each progranl for the case k = 2.
(c) For case (d) of Exercise 3.3, write a progra111 \vhich selects 111 1,' by
forward chaining if k
l'(rn) -:- 2, and by backward chaining if
k . vern) -:- 2.
3.5 For each of the cases of Exercise 3.3, write a progran1 which "'prints out"
the set of 1110nths in a n1inin1un1 nun1ber of n-character lines, inserting a single
null between successive n10nths except where (i) further nulls n1ust be added to
prevent the continuation of a single word fron1 one line to the next, or (ii) no null
is needed between two successive \vords, the flrst of which is coternlinous with
the line. I n other words, produce a nlatrix Z of row di111ension n and of nlinin1unl
colulnn din1ension such that (Z
~E)/Z = (p(nl 1 )
p(rn 2)
p(nll~)'
and such that each ro\v Zi nlay be partitioned into one or n10re vectors of the
fornl p(rn/J
O , all but the last of \vhich nlust be of din1ension l{p(nl l.,)] + I.
3.6 Assunling a linear representation for each of the logical vectors involved,
and a forward-chained representation for each of the ren1aining operands, write
progranls for the following operations. Assunle in each case that the argunlents x
and y need not be retained, and aSSU111e the use of a backward-chained pool
where necessary.
(a) z ~
(b)
(c) z ~
(d) z ~
x, u, y
lx, u,y/
k
k
i x
1x
3.7 Repeat Exercise 3.6(a), using separate grid nlatrices for x, y, and z instead
of chained representations. Specify a suitable linear representation for each of
the grid n1atrices.
3.8 (a) If a chained representation is used for a vector x, then the selection of a
specitled con1ponent can be 111ade faster by providing a nUlnber of
alternative starting points for the required scan. State precisely the
quantities required in such a process and \\;Tite a progranl showing its
usc.
(b) If provision is nlade for starting the scan at any conlponent of x, the
chained representation nlay itself be sinlplified. Sho\v precisely what
Exercises
131
Let 1t S; lO(2), let the set a be encoded in a five-bit code such that (2E)
and let each conlponent of the vector x be an (uncapitalized) English
word. Using a-origin indexing throughout, specify a suitable partitioned repre
sentation in 1t for the vector x, and repeat Exercises 3.9(a) and 3.9(b), using it in
lieu of the files.
p(ll/) = i,
3.11 For each of the following pool organizations, write a progranl to convert
a given ll1arked pool into a backward-chained pool:
(a) dinlension-ordered.
(b) address-ordered.
3.12 For each of the following queue disciplines, write progranls which take
fronl and return to the pool an infix of length n. Use secondary linking and
relegate to a Inarked pool any infix which is too short for linking. In each case
choose the type of chaining best suited to the particular queue discipline.
(a) LI FO (last-in-first-out).
(b) FI FO (first-in-first-out).
(c) Dinlension ordered.
(d) Address-ordered (utilize the possibility of fusing adjacent infixes).
3.13 Give a conlplete specification of a schenle for representing a tree T by a
full chain list matrix which is not in right list order. Write a prograll1 (expressed
in ternlS of the physical vector 1t) which deternlines the path vector T i for a given
index vector i.
3.14 Give a conlplete speciflcation of a schenle allowing joint representation of
those conlponents shared by two or nl0re of a fanlily of vectors Xl, x'2, ... , Xii as
suggested in Sec. 3.2. Write progranls to (i) select conlponent x/, and (ii) delete
conlponent x/.
3.15 Let 1t ;; II U l(lO), and let xl, x 2 , . . . , x n be a fanlily of vectors whose
cOll1ponents belong to the set o:l/[a U l(lO)]. Let the average and the nlaxin1unl
dinlensions of the vectors xi be a and Ill, respectively. AssunlC that the chaining
index is represented in decinlaI, with each digit represented by one con1ponent
of1t. Deternline (as a function of 17! and n) the value of a below which a chained
representation provides nlore con1pact storage than a linear representation with
null fill.
132
I'
x to
Let U = (X
0) and r = UIX jointly represent the sparse l11atrix X.
(a) Write a program \vhich detern1ines (as a function of U and r) a suitable
row-chained and column-chained representation of X.
3.17
1
)/
3.22
(a)
(b)
(c)
(d)
CpP)
chapter
SEARCH TECHNIQUES
134
Search techniques
In
tu
1 0
th
1 0
G==
_ p(k)
0,5).
t'(k) == 1
p3(k)
has the range d == (1, 2), is not uniq ue, and req uires a subseq uent scan of
one or other of the equivalence classes e 1 == (tu, th), and e 2 == (m, w, f),
represented by (010, 100) and (00 L 0 II, Ill), respectively.
Although a strict ranking operation maps elenlent k; into the integer i,
any biunique mapping onto the index set ll(V(k)) will frequently serve as
well. For, if p is the permutation required to cOInplete the ranking process,
and if a subsequent permutation j is required (as in step 4 of Progranl
1.12a), the two permutations can be combined in the single pern1utation
q == jJp. Sinlilarly, the ranking of a set k may be considered as equivalent
to the ranking of any set obtained by pernluting k.
4.1
4.1
135
The two nlain methods of scan are called directed and controlled. A
directed scan is begun in one of twopossiblc directions fronl a given initial
point i~ either ascending (that is~ i~ i
I~ i
2~ ... ) or descending. The
ll
W
0'\
V:l
~
~
~.
Type of Scan
pre!
Initial
Position
Initial
Direction
Cvclic or
Noncyclic
Any
Any
1
Catenated
l(I'Ud+ l)--;-2J
Catenated
Catenated
Catenated
Catenated
Catenated
Cyclic
Cyclic
Noncyclic
Noncyclic
Noncyclic
Noncyclic
Noncyclic
Noncyclic
Noncyclic
Noncyclic
No.1
1
2
3
7
8
9
10
Table 4.1
o :S
b
b
1
b
2b
b
-h'2j4 + h
2h
_b'2 + 2h
-b'2j2
b)
b
-h'2j4
b
b 3 j4 - h 2 j2
-b 3 j4 + b
+b
< 1~
+h
-h'2j4
-h 2 + 2h
b 2 j2 + 1
-b'2
2b b 3 j4 - b 2 j2
-b 3 j4 + b
+h
+ 3b-1
+b
1~
-b'2
b'2j2 b 3 j4
+.5
- 3b'2jt+ 3b - 1
-b 3 j4 + b 2 - b + 1
h'
Aver
age
I
-h'2j4 + h
1
1
1
-h'2j2 + 2h - 1
b 3 j4 - 3h'2j2 + 3b -
-h 3 j4
+ h2
Maxi
mum
~
~
1~
1
1
Scan fraction of directed scans for unifonn distribution of argunlents (from Iverson, 1955)
em
~
'"'"'"
4.1
137
are sUllllllarized in Table 4.1. Certain of the results are also plotted in
Fig. 4.2.
Initial direclionfixed (fixed scan). The ascending direction will beassulllcd.
If the scan is rooted and cyclic, the root may, without loss of generality, be
assulned to be one. The expected scan length for a set is then given by
"(h)
e ==
2:
j=
f(kJ
i == f
+ II
1.0
...c
VI
D.. 0.5
0.5
1.0
1.5
2.0
Scan length b ~
Figure 4.2 Plot of cunlulative probabilities of Table 4.1 (Nul11bers refer to the
entries in Table 4.1)
138
4.1
Search techniques
e === 1 ~ I === 1
Since, in general,
where N === M
M===
+ M.
t 1
1 t M~- 1 === 1 t M
f,
2e ===
then
(1 ~.
N ;~ 1),
1 2
1 2
and
N===
v(k)1
(1p )
(1p )
* The length of the scan will be determined by the maximum rank (in k) occurring in
the set a. The expected value of the scan fraction is approximately equal to the expected
value of the maximum occurring in a sample of size n = l'(a) chosen from the continuous
interval from zero to one. This value is known for various distributions [e.g., Cramer
(I 951) p. 370]; for a uniform distribution it is n -:- (n + 1).
4.1
139
* Approximating functions may, however, be used for estinlating the index and the
probable best direction.
140
4.1
Search techniques
(v(k) + 1) -:- 2. A noncyclic scan starting toward the nearer end is clearly
less efficient than one starting toward the argument, but it may be useful
when the most direct route to the argument cannot be determined. The
expected scan fraction is shown in entry 7 of Table 4.1; its analysis will
illustrate the method used in constructing the entire table.
It is assumed that the number of elements v(k) is sufficiently large that
the scan fraction / may be considered as a continuous variable. Let
pr (/ ::::;: b) be the probability that scan fraction f does not exceed b, and let
the function be represented in three parts such that pr
b) == prj (j' s:: h)
in the ith half-unit interval in b. Let x be the normalized initial position of
a given scan. Then 0 ::::;: x ::::;: 1, and, since the scan always begins toward
the nearer terminal, the fraction of the set covered in a scan of length b is
the same for the starting point (1 - x) as for x. Using this symmetry,
attentioncan be restricted to valuesof x in the range 0 to ~~' For the function
pr1 ( [ ::::;: b), the value of b is also restricted to the range 0 to J.
Consider fixed values of b and x with h ::::;: J. If 0 ::::;: x ::::;: b/2, the fraction
of the file covered by a scan of length b is given by b - x, for the scan
begins at x, proceeds a distance x to the nearer terminal, and returns to
the point b - x. If b/2 ::::;: x ::::;: b, the fraction covered is clearly x, for the
scan will reach the nearer terminal but will not return past x. If h ::::;: x ::::;: t,
the scan does not reach the nearer terminal, and the fraction scanned is
therefore b. Since x is uniformly distributed, the function pr1 (j' :s: b) is
obtained by integration as follows:
c.r : : ;:
pr 1 (f ::::;: b)
==
[l
b/2
(b - x) dx
(1)
+ ~".
x dx
/1/2
l~ i
J == =-17 + b.
2
17 dx
The factor of two arises from the syn1n1etry in x and the restriction of .r
to the interval 0 :=:;: x ::::;: -!. Similarly,
pr 2 (j'::::;: b)
==
[l
b/2
1
+ l~ixdxJ== -17 +-,
2
(b - ::r)dx
')/2
-b 2
+ 3b
and
pr:3 (f ::::;: b)
2[lb-l
dx +l~i (b o
b-l
.1:) dxJ
~.
4
Entry 8 shows the behavior of the scan starting toward the farther
terminal. Although the distribution differs n1arkedly fronl that obtained
for starting toward the nearer terminal, it has the same expected value of -~'
As may be expected, the function obtained for a fixed scan (entry 4) is
the average of the functions obtained for cases 7 and 8 and is linear in h.
Case 7 (toward nearer terminal) yields the smallest maximum scan length
of the three.
4.1
141
and
F -
F -
== - (F - C)
== -(F - C)
:?:: 0
for b
1,
for b 2 1.
Controlled scan
The seq uence followed in a controlled scan.is comnl0nly detennined by
a conlparison which determines the relative ranking of any pair of elements
x and y in the set k. It will therefore be assumed that comparison of the
argument x == k h with the element k j determines whether h < j, h == j, or
i~l
v(k)
j +-lCi
+ k)
-:-
2J
>
k +-j - 1
i +-j
Program 4.3
::=:> j. The subsequent scan may then be limited to one or other of the
two subsets a/-- 1 jk and aJjk. Themaxinluln dimension of the subset renlain
ing to be scanned is therefore minimized by choosing j == l( v(k) + I) -:- 2j.
If each subsequent element for comparison is chosen so as to (approxi
mately) halve the dimension of the set renlaining to be scanned, the
process is called binary search. Program 4.3 shows the details of binary
search ~ i and k are the indices of the tenninal elenlents of the renlaining
subset, and j is the index of the element selected for cOlnparison.
If v(k) == 2k , then anyone of 2J -- 1 different argunlents Inay be isolated on
the jth comparison, for j E ll(k), and the one remaining argunlent will be
located on the (k + 1)th cOlnparison. Hence for a unifornl distribution of
arguments, the expected number of c0I11parisons required in a binary
search is gi ven by
e,/2 /,) == (1 .2 + 2 . 2 1 + 3 . 22 + ... + k .2 /,'-1 + (k + 1)) -:- 2 /,'.
142
4.1
Search techniques
==
[(k - 1)27\'
+ k + 2]
--:- 27,;.
4.1
.i ~ l(p(M) + 1)
.i ~ M 2
.i M 3
+-
Program 4.4
143
2J
>
bee
2
cab
cat
dog
bee
cab
3
0
5M= egg 2 7
6
foe
had 6 8
hoe
nod
egg
foe
had
Figure 4.5
144
Search techniques
4.1
4.2
KEY TRANSFORMATIONS
Since a key transformation maps the set of keys k into a set of integers
(the set of derived keys d), any unique key transformation produces a
derived key which can be used to select the component of a mapping vector
directly and thus complete a ranking operation without the use of a
scan. If the transformation is not unique, it lnay still be used to partition
the original set k into v(d) subsets for scanning and so reduce the expected
scan time. Ideally a key transfornlation should be both simple and unique
and should produce a derived set d having a narrow spread; in practice,
compromises must be made.
Let k be the domain and d the range (in ascending order) of a key
transformation t(k i ) and let e J be the equivalence class in k which maps
into d j , that is, t(x) = d j for all x E eJ. The coalescence of t ill k is then
defined as the vector c such that c j = v(e J ), for j E ll(V(d)). Since the
equivalence classes are disjoint and collectively exhaust k, then +/C =
v(k). The spread of t ill k is defined as 1 + d" - d i . Thus if k is the set
(Sunday, Monday, ... , Saturday), and if t maps each day into the rank
(in the alphabet) of its leading letter, then d = (6, 13, 19, 20, 23), the
spread s = 18, c = (1,1,2,2,1), and +/c = v(k) = 7.
The key transformation is biunique if and only if C = . Moreover, if
the transformation t is biunique, the ranking operation (i.e., the deternlina
tion of the index of the argument in k) can be completed by a nlapping
vector whose components are selected by the index j = t(kJ - d l + 1,
and whose dimension is equal to the spread of t in k. The key transfornla
tion of the preceding example is biunique when restricted to the set x =
(Sunday, Monday, Tuesday), the set of derived keys is (13, 19, 20), and
the mapping vector m = (2, 0, 0, 0, 0, 0, 1, 3) of dimension eight serves
to cOlnplete the mapping if its cOlnponents are selected by the index
j = t(x;) - 12.
A key transformation is called j-or/gin if d l = j. Since the origin can be
changed by subtraction of a constant, attention will be restricted to
I-origin transformations. The spread of a I-origin transformation is
clearly d".
4.2
Key
tran.~/()r}}latiol1s
145
o
ment of directed scan, the base h value of
the representation of the elements of the
domain k can be used. The spread of such
a transformation may, however, be im- 0
practicably large. Ie for example, x were
some small subset of the set of all ten
letter sequences, (e.g., all Ineaningful ten
letter words), then s would be 2610, and
the required dimension of the associated
mapping vector would be impracticably
large.
o
In general, if each element of k is of
dimension h in 1t and if the (used) range
of each element of 1t is the set lO(h), then the
Inapping vector required is of dimension
b h The use of the base b va~ue of the rep
resentation in selecting the cornponent of
the mapping vector is equivalent to select
ing a path through a uniform h-way tree as
illustrated (using O-origin indexing) in Fig.
4.6, for h == 3 and h == 3. The branch to
the jth level is selected according to the jth
o
component of the representation.
Sequentiallevel-b/-level selection in the
tree is less convenient than the direct use
of the base b value, except that the former
2
frequently allows the full tree to be greatly
contracted. If, for example, the tree of Fig.
4.6 is used for the set k == (200, 0 I 0, 120,
2
001,022,202) (as indicated by the numeric
leaves whose values are the O-origin ranks
in k), then the full tree can be contracted
to the nonhomogeneous tree of Fig. 4.7. Figure 4.6 Uniforl11 tree and
The contraction is defined formally as 111apping vector for the set k =
follows: if the subtree rooted in a given (200,010, 120, 001, 022, 202)
node contains no significant leaves, the
subtree is replaced by a single null leaf~ if the subtree contains exactly
one significant leaf, the subtree is replaced by that leaf. The contracted
tree can then be represented by a chain list Inatrix or, since all nodes save
the leaves are null, by a leaf list Inatrix M. For the exanlple of Fig. 4.6,
146
4.2
Search techniques
3
3
0
1
2
3
4
5
6
7
8
9
10
11
0
1
6 0
3 1
1 1
4 1
9 0
0
0
0 1
0
5 1
2
M=
2
4
5
10
0 0
9
10
5
7
11
2
8
* See,
Key transjorl11atioflS
4.2
O-origin indexing
j+- -1
j +-j
+-
147
+1
vex)
+-
+-
MOi
Mi
1
Argument.
Current node.
Current index of argument.
j
k
+ xl'
T-
M/i
M o
1 <=> h is a leaf.
+-
l( (be)
p(.r)) -:- d
1.
148
4.2
Search techniques
1) -:-- 2 = (c j
I) -:-- 2,
[(c
+ e) ~ cJ =
2(+/c)
[1 + C~ CJ -:-- 2.
C
~ e
For a fixed dimension of the derived set d (and hence of c), and for a
necessarily fixed value of +/C = v(k), the value of I is clearly minimized
if the coalescence vector c is uniform, i.e., if the components of c are all
equal. Hence the expected scan length is minimized by a key transforma
tion whose equivalence classes are of equal dimension.
A given key transformation is frequently employed to rank a variety of
subsets of its domain k rather than k itself. For example, if k is the set of
English words in a given dictionary, then one of the subsets to be ranked
may be the set of distinct words in a particular sample of English text. If
a particular subset of k is specified, then the coalescence of the key trans
formation in the specified subset x can be determined, and the transforma
tion can be chosen accordingly. More generally (as in the case of samples
of English text), the active domain x may be only partially specified. The
transformation should then be chosen so that its coalescence is nearly
uniform for the expected active domains. If, for example, k is the set of
all five-letter sequences, and if each active domain is the set of five-letter
sequences beginning with a specified letter, then the key transformation
used should depend only on the last four letters. If the set of derived keys
produced by a key transformation has a spread s and a random uniform
distribution within that spread, then the expected length of a scan (of the
equivalence classes) can be shown * to be 1 + v(k) -:-- 2s.
Key tran,sjonnations
4.2
149
Fl i
0,
i d.
All remaining elements of the sets (i.e., aI/e') are represented in arbitrary
order in a two-column ~~overftow" matrix V.
The scan procedure is given by the Program of Fig. 4.9a. If the given
argument x is not equal to F~(r\ then the overflow matrix V is scanned in
ascending order. The left-pointing exit indicates that x k.
For a uniform distribution, the expected scan length is clearly given by
I = 1
+ (Cu( V) +
where (l( V) = v(k) - v(d). The expected scan length is therefore large
unless the average dimension of the equivalence classes (that is, lICk) -:- v(d))
is close to unity. For a known nonuniform distribution, the expected scan
can be reduced by placing the most freq uent element of each eq uivalence
class in F and ordering the elements in V according to their freq uency.
(b) Orerfiow with chaining. The two-column matrices F and V used in
method (a) can each be augmented by a third column chaining vector
which chains each equivalence class. Thus F~k is the row index in V of
element e/" if it exists, and is otherwise null. Similarly~ if V/I = e)i, then
V 3 h is the row index in V of e,~ :-1 if it exists, and is otherwise null. The
program is given in Fig. 4.9h. The expected scan length for a uniform
distribution can, as shown earlier, be expressed in terms of the coalescence
vector c as follows:
(c) Single table lrith chaining. In the overflow methods [(a) and (b)],
certain rows of the matrix F go unused, and a saving in storage can be
Friday, Saturday)
t(k i ) = 1
+ (610 n i ), where
1
2
3
4
5
F=
Friday
Sunday
Tuesday
~I
Wednesday
Zi
1
2
3
t(k i ),
V=
j +-
"*
x : Fli
4 J
j +- F 2 i
Vj
;+-0
e,..;,
i : {leV)
i
x
Overflow
F=
6
1 1
3 2
0
Wednesday
2
3
Friday
Sunday
Tuesday
I Thursday
Monday
Saturday
-4
; +- lex)
Ox:
:I
F1i
j +- F 2 i
5
7
1
2
3
4
5
6
7
T=
Friday
Sunday
Tuesday
Monday
Thursday
Wednesday
Saturday
6 0
1 4
3 5
2 7
5
4
7 :
; +- Fai
+-
~
~
~
~.
+1
: VIi
.#
~
V)
j +- V 2 i
(a)
1
2
3
4
5
Ul
Monday
Thursday
Saturday
Data of examples
t(x)
:J
i +- lex)
x: T 1'
; +- Tai
j +- T 2 i
x : VIi
j +- V 2i
(c)
em
".
em
~
1
2
3
4
5
6
7
T=
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
1 2
2 7
3
i+-l(x)
1
2
i+-m i
3
4
5
5
6
x .
m = (6, 1, 3,
c,
0,
4)
+-
(d)
1
2
3
5
4
7
T 3i
+-
leX)
Tli
Tli
Tli
j+---TZi
T=
Friday
Sunday
Monday
Tuesday
Thursday
Wednesday
Saturday
+---
/l(T)
h(i + 1)
Tli +-.r
I~
TZi
+---k
+---
i}
T 2i
(e)
\~
s::;
::::;
Figure 4.9
Progran1s and exan1ples for n1ethods of scanning equivalence classes defined by a I-origin key transforn1ation t
~
~.
-go
S5
....
til
152
4.2
Search techniques
where s
ll
fl(F).
Let u be a logical vector such that U/l 1(fl(F)) = d. Then ii/IF constitutes
the unused and u//F the used rows of F. Let v be a vector of dimension
f1( T) obtained by appending a zero suffix to u. The first two columns of
T are then defined as follows:
4.2
Key transformations
153
* The open addressing system appears to have been first used by A. L. Samuel, G. M.
Amdahl, and E. Boehm in constructing address tables for an assembly program.
154
4.2
Search techniques
Bucket files. In certain files the locations divide naturally into blocks or
buckets of n successive locations each, such that the entire contents of any
bucket can be scanned in virtually the same time required to scan anyone
location in the bucket. Such a file is called a bucket file (Peterson, 1957).
In a magnetic disc file, for example, each track forms a bucket. Each of the
foregoing methods of scanning equivalence classes can be adapted to suit
the characteristics of a bucket file. The equivalence classes can be
grouped in buckets, with chaining provided only from bucket to bucket.
Clustering. * The active argument sets of interest may be relatively small
subsets of the complete set k. Moreover, their elements commonly share
some characteristic so that a key transformation which gives uniform
coalescence and uniform spacing of the derived keys with respect to k
may yield highly nonuniform coalescence or nonuniform spacing, or both,
with respect to a given active domain x. This effect is called' clustering. If,
for example, each element of k is represented by a vector of decimal digits
of dimension ten, then the key transformation
t(x)
yields a mapping onto the range lO(l03) which has both uniform coalescence
and uniform spacing. On the active domain x, whose elements are all
represented by vectors p(x) such that a 3 jp(x) = (2,4, 7), however, all
elements "cluster" in the single derived key 247.
The deleterious effects of such correlations among elements of the
active domain can be reduced by employing key transformations which
depend on all components of the representation and do so in a manner
which shows no systematic relationship to the structure of the representa
tion. The mid-square method, for example, consists in squaring the given
key and extracting the middle digits of the resulting product. A commonly
used transformation is the taking of residues modulo some number m
such that m ~ vex) and is either prime or contains few factors.
4.3
Multiple keys
4.3
155
MULTIPLE KEYS*
If in some mapping operation the access to both the key set and the set
of correspondents is serial (or partially serial), considerable advantage can
be gained by replacing the vector T 2 of ranks by the suitably reordered set
of correspondents, that is, T/ becomes the correspondent of the key T/.
For, the ranking operation on the argument k j which gives access to the
element T 1 i = k j also gives immediate access to the correspondent T 2 i in
the same row Ti. This is equivalent to eliminating the permutation
operation (through reordering of the set of correspondents) and coalescing
the ranking and selection phases so that together they require a single
access to the (partially) serial memory.
For a single functional correspondence, the coalescing of the ranking
and selection phases can (by a suitable ordering of T) be accomplished by
the single-table process (Fig. 4.9c) without introducing the mapping
vector m of process (d). Frequently, however, a number of related func
tional correspondences must be provided between pairs of a family of
vectors OJ so ordered that 0/' corresponds to 0/ for all i, j, and k. In an
accounting system, for example, 0 1 , O2 , 0 3 , and 0 4 might be, respectively,
the vector of account numbers, names, addresses, and balances in a given
ledger. Those vectors which may occur as arguments in a mapping process
are called key vectors ~ those which never occur as arguments are called
satellite rectors.
may be reordered (and augmented by a suitable chaining vector) so as
to permit the use of the program of Fig. 4.9c for some selected key set Oi.
However, for any other key set OJ' the order will, in general, be unsuitable.
The program of Fig. 4.9d may, however, be used together with an appro
priate mapping vector m j and chaining vector qj. For the sake of uni
formity and the advantage of allowing an arbitrary ordering for 0, the
distinguished key set Oi may also be provided with a mapping vector m i
and treated like the rest.
The generalized binary search of Program 4.4 can be applied to the case
of multiple keys by providing a pair of chaining vectors (M2 and M 3 ) for
each key. The open addressing system is clearly unsuited to Inultiple keys.
REFERENCES
Burks, A. W., D. W. Warren, and J. B. Wright, (1954) ""An Analysis of a Logical
Machine Using Parenthesis-free Notation," Mathenzatical Tahles and Other Aids
to COlnputation, vol. VIII, pp. 53-57.
Cramer, Harald, (1951), Mathenzatical Methods o.lStatistics, Princeton University Press.
* See Johnson
(1961).
156
Search techniques
Johnson, L. R., (1961), "An Indirect Chaining Method for Addressing on Secondary
Keys," Conurlunicatiofls of the Association for ConlputiJ~!j MachinelT, vol. 4, No.5,
pp. 218-222.
Lanlb, S. M. and W. H. Jacobsen, Jr., (1961), "A High-Speed Large Capacity Dictionary
System," Mechanical Translation, vol. 6, pp. 76-107.
Lukasiewicz, Jan, (1951), Aristotle's Syllogistic fronl the Standpoint of Modern FOrlnal
Logic, Clarendon Press, Oxford, England, p. 78.
Peterson, W. W., (1957), ""Addressing for Randonl-Access Storage," IBM Journal of
Research and Developrnent, vol. I, pp. 130-146.
Schay, G., Jr., and W. G. Spruth, (1961) ""Analysis of a File Addressing Method,"
Technical Menlorandum 17-051, Advanced Systenls DevelopnlentDivision, IBM
Corporation, New York.
EXERCISES
4.1 Give a formal proof of the fact that the binary search of Program 4.3 will
not work properly if steps 5 and 6 are replaced by the statenlents k +- j and i +- j,
respecti vely.
4.2 (a) The argument k i in the set of keys k = (kI , k 2 , , kl') occurs with the
relative unnormalized frequency i. For the case v(k) = 10, design the
nlatrix M which will minimize the expected scan length when applying
Program 4.4.
(b) Show how additional keys may be incorporated in the system of part (a)
without revising the entire matrix M. Discuss the effects on the expected
scan length.
4.3
o1 6 8
435 o ASHooooooo
76 o ELMoooooooo
435 o LAURELoooo
435 o LAURELoooo
118 o LINDENoooo
61 oMAPLEooooo 0
736 o LINDENoooo
76oELMooooooo 0
Exercises
157
the resulting nlatrix M and the specific progranl used for selecting the row
Mi deternlined by an argument a E Xl.
(c) Specify simple key transfornlations on each of the sets k'!. and k 3 which
yield derived sets of dimension not less than three when applied to the
active donlains x'!. and x 3 , respectively.
(d) Augnlent the nlatrix M of part (b) by a pernlutation vector and a chaining
vector suited to each of the key transfornlations of part (c).
(e) Write a program which selects, as a function of a and j, the row of M
corresponding to the argunlent a E x j , for j = I, 2, or 3.
4.4 Let t i = f(k i), where f is a key transfornlation such that t S; LI ( t'(k)). The
vector t takes on n ft distinct values (where n = l'(k)), which are assunled to be
equiprobable. For n = 2, the cases are (I, I), (I, 2), (2, I), and (2, 2), with
expected scan lengths 1, -}, I, and }.
(a) Show that the over-all expected scan length is 1.25 for n = 2.
(b) Calculate the expected scan lengths for n = 3 and for n = 4.
(c) Generalize the result of part (b) to show that the expected scan length
rapidly approaches 1.5. [See Johnson (1961) for an alternative derivation.]
4.5 Design an open addressing system for the ledger L of Exercise 4.3 and the
key transformation of part (a).
4.6 Program and discuss the extension of binary search to Ill-way search.
4.7 Let I i be the time required to scan over the ith elenlent of a vector x which
is represented in a chained (or other serially-scanned) representation, and let Ii
be the frequency of occurrence of the argunlent Xi. Discuss the role of the
"standardized frequency" s = I -:- I in deternlining the optinlUI11 ordering of the
vector x.
4.8 The ne{[{hbors problenl requires that the near neighbors of an object in
n-dimensional space be found. The technique used depends on the dinlensional
ity and the particular criteria of adjacency.
(a) The position of a vehicle on a turnpike is represented by the distance in
nliles of the vehicle from the south end, and Pi is the coordinate of the ith
patrol car. Write programs to:
(i) identify the patrol car nearest an accident at position a,
(ii) identify the two cars nearest to each other.
(b) A three-column nlatrix V specifies the locations and radio call-signs of a
fleet of nlerchant vessels on a flat lake, where VIi is the call-sign of the ith
vessel, V 2 i is its distance in miles fronl the meridian tangent to the lake on
the west, V 3 i is its distance in miles fronl the perpendicular tangent to the
lake on the south. Write a progranl to deternline the call-sign of the neigh
bor nearest to a distressed vessel whose call-sign c is given.
(c) The matrix of part (b) is used to specify call-signs and locations at til11e f
of a fleet of b0l11bers over a flat territory. When each b0l11b is released,
neighboring planes must be at a safe distance. Construct a progranl which
will find the call-signs of all pairs of planes within r nliles of each other at
time f.
(d) In a certain hydrodynamic calculation, the nl0tion of each elel11entary
158
Search techniques
volUlne of fluid is traced. The ith elementary volume is described by row Li
of a matrix: (4 t ( 3 ) 1L represents the three space coordinates (in a recti
linear system), and a7 1L represents the remaining parameters. At each
time step the parameters of volume i are redetermined by those of the four
elements nearest it. Write a program to determine a 4 1Li as the set of
indices of the four nearest neighbors of element i. Hint. Attach an explicit
index vector before sorting.
chapter
lVIETAPROGRAMS
160
5.1
Metaprograms
5.1
COMPOUND STATEMENTS
z +- (x
+ y)
+ (s
- t)H
161
CO/l1pound staten1ents
5.1
is compound in the operator set
-)
a+-x+y
a+-x+y
b+-axr
b+-axr
+-
s - t
+-
en
d+-1
z+-b+d
+-
s - t
i+-n
<
i+-i-1
z+-b+d
Program 5.1
Analysis in p
Analysis in q
(a)
(b)
+ y)
x r
+ (s
f)"
162
5.1
Mefaprogralns
Tree
(a)
2
2
/\
/\
/\
(/\, V, p, 1\, q, r, V,
/\
(d)
S, -,
((q /\ r) V p) /\ (s V 7)
Parenthesis form
Figure 5.2
Left list
matrix
(e)
(c)
t)
5.2
Lukasiewicz notation
163
5.2
LUKASIEWICZ NOTATION
First proposed by Lukasiewicz (1951) and first analyzed by Burks et al. (1954).
164
5.2
A1 etaprogranls
Phrase
Value
(V, 0, 0)
(V,O, 1)
(V, 1,0)
(V, 1,1)
(/\ , 0, 0)
(/\,0,1)
(/\,1,0)
(/\,1,1)
(-,0)
(-,1)
1
1
1
If sonle infix of z is a phrase, and if the infix is replaced by its val ue, then
the resulting vector y is called an2-reduction of z. If y is any Y-reduction
of z which cannot be further reduced, it is called a conlplete reduction of z
or, since it can be shown to be unique, the complete reduction of z. Com
plete reduction of z will be denoted by 2(z). A formula z is said to be
singular* if its complete reduction is a single literal, i.e., if l'(Y(z)) = 1 and
2(z) E 1. Thus q = (/\,1, V, 0,1) and r = (1) are singular, but s =
(/\ , 1, 1, 0) and t = (/\ ) are not.
For exanlple, complete reduction of the singular formula z = (/\ , ,1,
/\ , 0, I, V, 1, -, 1) may be performed as follows:
Zl
= (/\, V, 1, /\, 0, 1, v, 1, -, 1)
= (1\, V, 1, /\, 0, 1, v, 1, 0)
Z2
Z3
Z4
Z5
(/\,
V, 1, /\,0,1,1)
( /\, V,
1, 0, 1)
------
(/\,1,1)
* The term well fOr/ned used by Burks et al. (1954) and others is avoided here because
singularity implies not only that the formula represents a well formed tree but also that
the tree is singuldr.
Lukasiewicz notation
5.2
+-
+-
s+-O
+-
e(O)
+-
v(z)
+1
i+-i-l
(Zi) CD y
(5(y}) : 0
I-origin indexing
(v(y) = 1)
+-
+-
j :
bey})
Given formula.
Reduced suffix of z.
Index of
Dimension of phrase to be
reduced.
Singularity indicator.
+1
~v -- ~ ( a. j / y)
11
y +-(x) CB aj/y
in descending scan.
Legend
>
v(y)
10
165
Program 5.4
s === (I
~) ~ ( -
d)
* The suffix dispersion vector describes the dispersion (nunlber of roots) of all suffIxes
of
Z,
= ~'(aj /d) -
(+ /aJ)d).
166
5.3
Metaprogran1s
5.3
Two formulas are said to be equiL'alent if they have the same value for
each possible specification of their variables. If z is any formula whose
operators are all symmetric (i.e., whose operands commute), then any
reordering of the component singular formulas of z which leaves the span
of each operator unchanged leads to an equivalent formula. For example,
since the operators /\ and V are symmetric, the formulas
z = (/\, V, /\, V,
and
= (/\ ,p,
V,
}i', /\,
q, /\, r, V,
u, v, r, q, p)
}i', /\,
u, v)
(1\, V,
e,j,
V, 1\,
a, b,
1\, C, d)
5.3
(~l an YJ~f()rnlula
167
To establish the theorenl, let z be any singular fornlula, let r(z) be its
dispersion (that is, the number of roots), let s(z) be the Inaxinlunl suffix
dispersion of z, let d == b(Zl), and let
be the unique (cf. Program 3.9) partitioning of (iljz into its conlponent
singular formulas. Then yi
yi-tl
yi I,' -1 represents a k-tuply
rooted tree and r(y! E8 yi~l
1) == k. Moreover,
== max
[S(yl)
+d-
1,
S(y2
yff)J
== Inax [s(y])
d -
jJ
jJ.
j=l
==
Since the component formulas are in minimax fonn, the s(yJ) are individ
ually minimal, and the maximum over S(yi) - j is clearly mininlized by
arranging the s(yj) in ascending order. This concludes the proof.
To ensure that each component fornlula is itself optinlal, it suffices to
apply this reordering procedure in turn to the successive singular fonnulas
encountered in scanning the given formula from right to left, as shown in
Program 5.5.
Program 5.5. The vector y is the suffix al'!z pernluted to optinlal [orI11, p is its
partition vector* (that is, ((p; a j - 1 ) 1aPj)/y is thejth singular formula of y), and
g is its maximum suffix dispersion vector (that is, gj is the nlaxinlunl suffix dis
persion of thejth singular formula of y). The nlain control parameter i is decre
mented on step 11, and, if it is not zero, the degree d = ()(z i) of the next
component to be added to y is examined. If Z; is not an operator, the branch
to step 8 occurs with h = I. The component Zi is then a fornlula of length 1
and steps 8-10 add it to y and nlake the appropriate changes in p and g.
If Zi is an operator (of degree d), the loop 15-22 scans the vector g and reorders
the first d component formulas of y so that their nlaximunl suffix dispersions are
brought to ascending order. This is accol11plished by the sinlple, but not necessar
ily efficient, sorting process of conlparing successive pairs of adjacent conlponents
of g and interchanging the corresponding C0l11pOnent fornlulas of y (by rotation
* The conventions used for p are those established in the subtree partitioning of
Program 3.9.
168
5.3
M etaprogranls
I-origin indexing
s+-O
+-
E(O)
+-
(0)
+-
(0)
+-
v(z)
+1
+-
ad /g
+-
+-
(h) ED ad/g
+-
((p tad)
10
+-
(zJ ED y
;;j=
Partition vector of y;
P j is the dimension of
the jth singular form
ula of y.
gj
Degree of Zi'
Singularity indicator.
L1(d)
+ ((r1)/1)1
+ 1) 8) -ad/p
l+-i-l
12
+-
(v(p)
13
+-
O(Zi)
14
d : v(p)
15
+-
Legend
= 1)
>
h+-h+l
16
17
-ai/z.
11
Given formula.
>
18
gh
19
+-
(p
20
+-
\ti/y,
:::;
gh+l
21
gh~gh+l
22
Ph~Ph+l
Program 5.5
a h 1) ,}
U,
aPh +Ph+l
Ph t (u/y)\
to nlininlax fornl
5.4
169
+y
z)
+y
x z,
with the understanding that the entire expression need not be enclosed in
parentheses.
The problem posed by the use of such conventions can be segregated by
considering a cOfnplete parenthesis notation in which all inlplied paren
theses are included, i.e., in which each operator and its associated operands
are enclosed in parentheses. The analysis of a statelnent in parenthesis
notation can therefore be performed in two steps, a translation to conl
plete parenthesis notation according to the prescribed conventions, fol
lowed by the analysis of the resulting statement. The present discussion
will be limited to expressions in conlplete parenthesis form.
The conlplete parenthesis notation will be referred to as ;~-notation and
the terminology adopted for Y/-notation will be extended analogously.
Thus, z = ([, [, x, +, y, ], x, r,]) is a ;~-formula more conlnlonly
denoted by (x + y) X r. To avoid confusion with the nonnal use of
parentheses (e.g., in enclosing vectors), brackets will be Llsed (as in the
foregoing vector z) to represent the cfJ-notation.
170
5.4
M etaprogranls
7T(W) +-
I-origin indexing
A2
:c +- <!)1
:c
<1>3
Set of operators.
<1>1
<I)2+(x E p) +-
<1>2 +-1<1>3
Program 5.6
:c
Legend
The translation frolll &- to 2-notation can be performed with the aid
of one auxiliary file or stack vector. Program 5.6 shows a suitable process
which will correctly translate any singular formula, but which includes no
tests for singularity. It is noteworthy that all left parentheses are simply
ignored. A sinlilar process can, of course, be designed to use only the left
parentheses and to ignore all right parentheses. * Any translation which
tests for singularity clearly must use all parentheses. If the !f- and &
notations enlploy different sets of operator symbols (e.g., /\, V,
, and
x, +, r--;), the appropriate translation can easily be incorporated in the
progranl.
Program 5.6. The original staten1cnt is assun1ed to be recorded on a file <1>1'
with partitions Al following each syn1bol and with a null itenl and partition A2 at
* Oettinger
plete.
r(~ht,
and
COfll
5.4
171
the end. File <1>2 receives the resulting.!f-formula in reverse order, i.e., fronl right
to left. The stack file <1>3 receives each operator synlbol as it is read from <1>1 and
transfers thenl one at a time in reverse order (i.e., by a backward read) to <1>2 at
each occurrence of a right parenthesis. A trace of the progranl shows, for
example, that the :3J-formula ([, [, x, V, y, ], !\ ,[, - , z, ], ]) translates correctly
into the ~-formula (:r, y, V, z, - , 1\ ) reversed fronl normal order.
A partial test of singularity can be provided by testing each component
for compatibility with its predecessor, the ordered pair being declared
compatible if and only if it can occur in some singular formula. For
example, an operator may be followed by either a left parenthesis or a
variable, but not by a right parenthesis or another operator. These first
order compatibility constraints can be expressed, in terms of the following
classes: left parenthesis, unary operator, binary operator, variable or
literal, and right parenthesis. These classes will be denoted by [, u, b, l\ and
], or alternatively by 1, 2, 3, 4, and 5. The constraints are sumnlarized in
the nlatrix M of Program 5.7.
The test of singularity provided by the first-order constraints is not
complete, * but can be conlpleted by the following expedient.-j- The
auxiliary file which receives the operators (file <1)3 of Program 5.7) also
receives the left parentheses in their turn. The following tests are then
added:
1. Each operator is accepted and replaces the previous entry in the
auxiliary file if and only if the previous entry is a left parenthesis.
2. The transfer of one component from the auxiliary file to the output
file normally occasioned by the appearance of a right parenthesis is
accepted by the right parenthesis if and only if the component trans
ferred is an operator.
3. The possible exhaustion of the auxiliary file is tested each time it is
read.
The first test prevents the acceptance of two successive operators without
an intervening left parenthesis. At each application of the test, the corre
sponding left parenthesis is removed from the file. Since the auxiliary fIle
may now contain left parentheses as well as operators, the second test is
required to prevent their acceptance as operators. The complete testing
and translation process is described by Program 5.7.
Program 5.7. The current conlponent .r is read fronl the input file on step 8 and
its class k is deternlined before the repetition of the nlain loop at step 5. Step 5
* The tests provided in conlpilers have frequently been lirnited to essentially this type.
See, for example, Carr (1959).
t This procedure is due to Oettinger (1960).
172
5.4
M etaprogralns
I-origin indexing
7T{<1
s+-O
<1>3
j+-2
[1
Mi.
k . 0
u2
<1> 2+(k<4) +-
j+-k
+-
<1>1
+-
<1>3
10
+-
11
+-
12
+-
[ u b v ]
1 2 345
0, Al
13
Al
14
15
16
A
i=
+-
o(x)
x : ]
20
21
+1
P : [
18
]5
Al
P +-1<1>3
k +-4
b3
v4
17
19
1 101 0
10010
10010
00101
00101
First-order
compatibility
constraints.
= 1.
Mlci
j accepts k:,>Mki
<1>3
<1>2
Output in se -notation
(reversed order).
<1>1
Input in Y'-notation
(terminated by 0, AI)'
Set of operations.
b(X)
Degree of operator x.
Singularity indicator.
Legend
+-
+-1<1>3
x:p
5.5
173
on steps 15 and 16. The exits on steps 15 and 20 indicate nonsingularity due to
the exhaustion of the stack file. Step 9 provides a final test to ensure that the
stack file is exhausted when the input file beconles exhausted. Since the first
component of any singular fornlula must be either a variable, literal, or left
parenthesis, the initial setting ofj to 2 on step 4 provides the appropriate initial
conlpatibility condition.
Each of the translation programs considered produces the resulting
2-fornlula in reverse order. This is the order in which it is nlost easily
evaluated and, consequently, the order in which the synthesis of a corre
sponding function program is most easily performed. Synthesis nlay
therefore proceed concurrently with analysis. The analysis Inay, on the
other hand, be completed first, and the output file (1)2 rewound before
beginning the synthesis. The latter alternative allows the use of separate
metaprogranls for analysis and synthesis, and hence makes lesser denlands
for nletaprogram storage. It also allows the application of an intervening
transformation of the ,2-formula to some preferred equivalent fornl.
However, as shown by Program 5.4, the transfornlation to nlininlax I'ornl
also treats the Y-formula in reverse order. It can therefore be perforIned
concurrently with the translation from parenthesis notation.
174
Metaprograms
rr((I)
+-- E
s+--O
4
5
nl
A2
+--
Al
tll +--
m - (1 - (5(x))
;{'
(D
11
cI>2 +- ]
12
cI>2 +-- X
+--1<1>3
Al
15
+--
Input in Y-notation
(terminated by 0, A 2).
Output in :~-notation
(reversed order).
q)3
Set of operators.
Singularity indicator.
+- [
10
13
<1>2
:p
(})3 +-- X
14
(D!
X +-- (D!
I-origin indexing
5.5
Legend
Al
cD 1
s+--l
16
17
<D 2
18
19
(5(p)
+--
P
-=F
Program 5.8
REFERENCES
Burks, A. W., D. W. Warren, and J. B. Wright, (1954), "An Analysis of a Logical
Machine Using Parenthesis-free Notation," Mathematical Tables and Other Aids to
COll1putation, vol. VIII, pp. 53-57.
Carr, J. W., III, (1959), "Digital Computer Programming," Chapter 2 of Grabbe, Ramo,
and Wooldridge (Eds.), Handbook 0fAutonlation, Conlputation, and Control, vol. 2,
Wiley, New York.
Lukasiewicz, Jan, (1951), Aristotle's Syllogistic from the Standpoint of Modern Formal
Logic, Clarendon Press, Oxford, England, p. 78.
Oettinger, A. G., (1961), "Automatic Syntactic Analysis and the Pushdown Store,"
Proc. Twe((th SYfnpositlfn in Appl. Math., April 1960, published by American
Mathematical Society.
Exercises
175
EXERCISES
5.1 For each of the follo\ving logical functions, exhibit an equivalent (i) tree,
(ii) .5I'-fornlula, and (iii) Y-fornlula:
(a) ,l(~r, y, z) = :r /\ (y V z).
(b) g(w, x, y, z) = (w V (y
z /\ (x V (w = y.
(c) the function of part (b), limiting the operators elnployed to and, or, and nol.
], /\ , [, - ,
/\ ,[, - ,
I, ], ])
I, ], ])
the operation of
Progranl 5.4 for each of the cases z = a, Z = b, and z = c.
Program 5.5 for z = d.
Progranl 5.6 for (1\ containing q.
Program 5.7 for (}\ containing q and for q)l containing r.
Program 5.8 for (1\ containing d and for q\ containing e.
chapter
SORTING
Input
Output
Name of Process
Single
Single
Multiple
Multiple
Single
Multiple
Single
Multiple
Duplication
Classification
Merging (or Merge)
Revision
Table 6.1
6.1
177
6.1
Copy operations
Item
Positions
Figure 6.2
Output
Files
Copy operation
178
6.1
Sorting
<
r2 >r/
< r2'
6.1
179
rn --:-
* This method, comnlonly credited to Goldstine and von Neunlann (t (48), was
presented by J. W. Mauchly in July 1946 in the Moore School lectures (t94H).
~
~
00
I47, 92, I 38, 79, I 20, 59, 98, I 34, 36, 70, I 67, 96,I 24, I 15, 76,I 22, 43, 63 I
V)
~.
15,34,36,47,70,76,92
I 38, 43, 63 67, 79, 96' I15, 34, 36, 47, 70, 76, 92, I 22, 38, 43, 63, 67, 79, 96, I 20, 24, 59, 98 I
122,
20, 24, 59, 98
Figure 6.3
CD')
?'
~
6.1
181
Two-phase merge. The (m + 1) files used will be labeled <1>11, <1>21, ... , <l> m l ,
and <1\2, the last serving as initial input and as input during each classi
fication phase. Program 6.4 describes the entire merge.
Program 6.4. The merge phase is shown on the left and the classification phase
on the right. The heart of the former is the loop 7-17. Its operation is controlled
by the logical vectors v and z (of dimension nl), which specify the set of exhausted
files and the set of ineligible items, respectively. An eligible iten1 is one which has
been read to one of the nl item positions Pi, is not a dumn1y, (i.e., null), and
possesses a key which equals or exceeds r, the key of the item last recorded.
The merge phase terminates on step 7, when all files are exhausted. Step 8
initializes the vector z (ineligible item positions) to the value v (exhausted files),
and step 9 increments the output string count s. Each execution of the subloop
10-14 records on cD 1 2 the item Pj having the smallest key of all eligible items.
Steps 10-12 select and record the item Pi and preserve its key as the variable r.
Step 13 reads the next item fron1 file j. If this exhausts the file, the branch to
step 15 is followed. Step 15 adds j to the set of exhausted files and step 16 adds it
(since the new item Pi is a final dummy) to the set of ineligible items. Step 17
then repeats the subloop if any eligible items remain and otherwise re-enters the
major loop at step 7. If the files are all exhausted, step 7 branches to step 18 to
begin the classification. If not, the production of a new maxin1al string is begun
on step 8.
If step 13 does not exhaust the file, it is followed by the decision on step 14,
which repeats the subIoop if r does not exceed the new key, and otherwise adds}
to the set of ineligible items on step 16.
The necessary initialization is perforn1ed by steps 3-6. Step 3 rewinds all input
and output files. Steps 4 and 5 perform the initial read from each unexhausted
file to the corresponding item position and respecify v to indicate any file which
may be exhausted by the initial read itself. The vector v is itself specified external
to the process, so that the initial set of input files may be restricted at will. On
subsequent repetitions of the merge, all files are n1ade available by step 2.
The classification phase begins by terminating the output file with a dun1n1Y
item and final partition A2 , and rewinding it. The /11 input files are also rewound
to serve as output files in the subsequent Ill-way classification, and the process is
terminated by step 20 if the output string count is equal to one. Step 21 redefines s
as the maximum number of strings to be allotted to the output files in turn, and
step 22 reads the first item from the input file (I\~.
The output files are selected in ascending order by the index i. The variable j,
which counts the strings, is initialized on step 25 and decren1ented on step 30 each
time a break is indicated by the preceding comparison on step 29. When s strings
182
6.1
Sorting
eD 1
A2
+- O ,
eD 1 2
v+-O
17(<1))
vip, vjq
+-
+-
f
+-
+-
17(eD)
vl<D 1
v V (q = A2 )
rs -:- ml
21
22
i -(- 0
Z -(- v
~-
10
+-
((zlk(p))/Llh
11
r -(- k(pj)
13
<D 1
A2
Pj
+-
:S;
-F
k(pj)
15
vj
-(--
16
Zj
+-
17
23
+1
24
+-
+-
25
+-
k(p)
26
Pj
:S;
14
<D 1
+-
([)i l +-
(D/
+-
20
S +-
12
19
s -(-0
+1
18
+-
0, A2
+- (1)1 2
27
A2
k(p)
j -(-j - 1
28
29
30
>
I-origin indexing
-:I
Legend
(I> i]
(1)1 2
Item positions
File partitions
Exhausted files
Ineligible items
= 111.
String count.
j
Program 6.4
J)
6.1
183
have been recorded, the branch from step 30 to step 24 is followed to repeat the
process for the next output file.
The classification phase is terminated by the occurrence of the partition A2 on
step 28. Step 1 then records a dummy and a final partition on each output tile
(including any which may have received no items), and step 2 resets the vector v
to zero.
The merge phase with which Program 6.4 begins is essential, even though
the original data are contained in a single file, since it also serves to
determine the string count s needed in the subsequent classification. The
need for the string count can be avoided by using a classification process
which merely assigns successive strings to successive files in cyclic sequence.
This process does not satisfy the definition of a simple classification, and
it will be given the name string classification. String classification is
frequently more convenient to use than silTIple classification, particularly
in processes such as the single-phase merge to be described next. Two
successive strings assigned to a given file in string classification can coa
lesce to form a single string, but the probability of such an occurrence is
small, especially in later stages.
Single-phase merge. The two phases of the merge sort can be coalesced in
a single revision operation employing nl input and r1'1 output files. The
two rows of files (1)1 and <D 2 serve alternately as input and output on
successive stages.
Program 6.5. The Dlain subprocess (15-22) differs fronl the corresponding seg
ment (10-17) of Progranl 6.4 only in the control of file selection, the alternation
of input and output being controlled by the alternator G, which alternates between
1 and 2 (step 2) on successive stages. The classification is controlled by the variable
i, which selects the particular output file on step 17 and which is itself cycled
through the integers I to /11 by step 14. When all files are exhausted, the branch
to step 2 is followed, resetting the vector v to zero, ternlinating the output files,
and rewinding all files. The final output is contained in file <1\([.
Elimination ojjile rewind. Each of the sorting processes described req uires
a rewind of all files between successive stages. If the files enlployed are
capable of backward read, the processes can be ITIodified so as to elinlinate
the need for rewind. Since each file is alternately read and recorded in
successive stages, each will always be read in a fixed direction and recorded
in the other. Since the space needed for recording is not known in advance,
it is necessary to do all recording in the forward direction and therefore
to read in the backward direction. The changes required will be illustrated
by modifying the single-phase merge of Program 6.5.
Program 6.6. Since the alternate forward record and backward read effectively
reverse the order of all files on successive stages, alternate stages nlust assenlble
184
Sorting
6.1
(a, s)
+-
a+-2
V+-O
<1>a
7T(<1
(1, 0)
11 (a +
1)
I-origin indexing
A2E
+- E,
+-
<1>1
<1>2
P
q
File partitions
Exhausted files
s : 1
s+-O
vjp, vjq
v+-VV(q=A 2E)
10
i+-O
11
v :
12
+-
13
+-
+1
14
+-
11 (i +
15
+-
(zlk(p))j l l)l
16
+-
kePi)
vj<1>a
Z
= nz.
Ineligible items
.String counL
Legend
1)
<1>~-a +- Pj
17
18
+-
A2
Pi
<1>ja
+-
19
r : k(pj)
20
Vj
+-
21
Zj
+-
22
Z :
Program 6.5
>
=F
m-way single phase merge sort
(c, a)
7T(eD)
v+-O
c : 1
++-
(0, 1)
E
I-origin indexing
i=
eD l
Input to odd
stage
eD 2
Output of odd
stage
Item positions
Partitions
Exhausted files
Ineligible items
+-
185
6.1
s : a-I
9
10
= m.
String count.
11
12
Direction of read.
13
vip, vlq
14
15
i+-O
16
v :
17
Z +-
18
19
i+-ml l (i+l)
20
+-
21
+-
k(pj)
Legend
+1
eD~-a +- Pj
22
23
vi ceDa
v V (q = A2E)
+-
+-
+-
).,A 2
Pi
ceD ja
+-
24
(3 - 2a)r
25
V j +-
26
Zj +-
27
(3 - 2a)k(pj)
>
Program 6.6
=f:.
186
6.1
Sorting
terminal partition A2 or the permanent initial partition J.. The entire process is
ternlinated by equality of s and a-Ion step 8, which can occur only if s = 1
and a = 2. This pair of conditions ensures not only that the nunlber of strings is
unity but also that an odd number of stages has been executed, and hence that the
final output (on (1)1 2 ) is in ascending order.
Since the initial input file must normally be read forward, an exception is made
through the agency of the variable c. On the first pass only, c = 0, and the
reads on steps 13 and 23 are therefore forward. The forward read on the first
pass necessitates a subsequent rewind of the input files, which is provided by
step 6.
6.1
187
such that the output file has the form <Po, (PI' . . .
the b output files of the preceding classification.
, <Db-I'
where the
(Pi
are
Two-phase COlUn1l1 sort. Like the merge sort, the base b column sort may
either be two-phase (classification followed by simple merge and using
b + 1 files) or single-phase (using 2b files); the two nlethods are described
by Programs 6.7 and 6.8, respectively.
j +-q
1T(<D)
+-
j +-j - 1
(b(q)) l-d
<D~.3
<D 1 +-
1T(<D)
i+-O
+-
+-
+-
k(p); b
11
<1>00 +-
<DO
0
<1>1
Positional representation of
key (v(d) = q).
Base of representation.
A1
Al
<1>l
Stage = q - j.
i+-i+l
12
14
Al
O ,
10
13
<D oo
+-
+-
O-origin indexing
<
<
i : b
<D oo
+-
0, Al
Program 6.7
Program 6.7. Steps 1-7 constitute the classification and steps 8-14 the n1erge
phase. File <Do 0 is the single input to the classification and the single output of the
simple merge. The remaining b files are denoted by <D /, i E l O(b).
The component of d which controls the current classification (step 6) is selected
by j, which scans d from right to left. In the (implicit) specification of d on step 5,
b serves as an auxiliary variable (cf. Sec. 1.19). When the classification phase ends
with the exhaustion of <1>0 0 (step 4), the output files are terminated, all files are
rewound, and the simple merge is performed (steps 10-13) to re-collect on <D oo the
results of the preceding classification. This file is then terminated by step 14, and
the entire process is repeated from step 2 for the next lower value of j. The
dimension of d is specified (by compatibility with e(q) on step 5) as q, and q is,
of course, specified externally.
188
Sorting
6.1
Program 6.8. The alternator a again determines the roles of the two sets of files
(input or output) on successive stages, but because of the use of O-origin indexing,
it alternates between the values 0 and 1. The classification process (steps 7-11)
differs from that of Program 6.7 only in the control exercised by the alternator a,
and in the specification of a sequence of input files <1>oa, <1>l a, , <1>~_I instead of
the single file <1>0.
+-
a+-l
7T(<1
+-
O-origin indexing
j+-j-l
i+-O
+-
+-
<1>
+-
k(p); b
+-p
i+-i+l
10
11
Al
<1>i a
(bE(q)) ~d
ii
<
ii
dj
<1>0
<
12
<1>1
b.
Positional representation of
key (v(d) = q).
Base of representation.
= q - j.
Stage
Legend
i : b
<I>ii +- oE, AlE
Program 6.8
The program is deficient in two respects: it requires that the original input be
on a full set of b files, and it produces a final output on b files rather than one.
The first defect may be remedied by the use of an externally specified logical
vector v to designate the input files which are unused in the original stage. The
second may be remedied by a final simple merge following the qth stage. This
could be added as a separate program, but it can be effected more simply by
replacing q with q + 1 to ensure that the high order digit do is identically zero and
so restricts the final output to a single file.
* This
6.1
189
be assumed, without loss of generality, that k i < k 2 Since the keys are
distinct, there exists an integer r such that d ri < d r2 and that arid l =
a r ld 2 Thus r is the (O-origin) index of the highest order column in which
the keys differ.
In the (n - r)th pass, the items PI and P2 are therefore assigned to files
<D h a and <D i a such that h < i. Hence at the conclusion of the subsequent
merge, item PI precedes item P2. In each subsequent stage the two items
are always assigned to the same file (since d .,! = d s2, S < r), and the two
items are therefore always relatable with respect to these operations.
Since each stage is a copy operation, and therefore rank-preserving, the
relative ordering of all relatable items is preserved, and PI thus precedes P2
at the conclusion of the process. Thus for any pair of items PI and P2 with
keys k i and k 2, such that k i < k 2, item PI precedes P2 in the final arrange
ment.
Vector keys and categories. The column sort is actually based on the
components of the vector d and only indirectly on the numerical key it
represents. The process can therefore be generalized to any numerical
vector key y defined on each item a i . It can be further extended to an
arbitrary key vector b belonging to the prod uct set
c=
@ c i @ ...
CO
Cl/(b)
190
Sorting
6.1
some stage of the column sort on b, and the ordering defined by it is there
fore said to be contained in the ordering b. If the orderings dO, d 1, . . , d r 1
are all contained in b, they can all be achieved at some stage in the ordering
b, and the total number of passes required may be less than that required
to achieve the r different orders independently. For example, dO = (b 2 , bI)'
d 1 = (b o, b 2 , bI)' and d 2 = (b 2 , b I , b o' b 3 , b 4 ) are all contained in 1 =
(b o' b 2 , b I , b o' b 3 , b 4 ) and can be achieved jointly by sorting on the six
components of 1 rather than on the ten components of dO, d 1 , and d 2
The usefulness of this result is further extended [Ashenhurst (1953)] by
the following fact: if a given component recurs in an ordering vector, its
later occurrences may be ignored. For example, the second occurrence of
b o in the vector 1 (as 13) may be ignored, and 1 therefore contains the
ordering d 3 = (b o, b 2 , b I , b 3 , b 4 ) as well.
The propriety of suppressing later recurrences of a component of an
ordering vector is easily established. Let b be a given ordering vector and
let d = b m and c = b n be two related orderings. Moreover, let d be
obtainable fronl c by suppressing all later recurrences of components of b.
This implies that the mapping vector rn is obtained from the mapping
vector n by the same process, i.e., rn = (ajn)jn. If PI and P2 are two
items whose (distinct) keys c i and c 2 agree in all components up to but not
including the jth, then their relative order is determined by the component
c j = b n .. In the corresponding keys d 1 and d 2 it is clear that the first
compol{ent in which the items differ is again b n and that the same relative
order is therefore determined by d. Since a third ordering v = b p is also
equivalent to the ordering c = b n if P is also reducible to rn, the result
concerning eq uivalent orderings can be extended as follows: two orderings
y = zm and w = Zn are equivalent if (ajrn)jrn = (ajn)jn.
Choice oj'number base. In the merge process of Program 6.4, the value of
111 = n 1.
In the column sort, on the other hand, the number of files required is
determined directly by b, the base of the number system representing the
key. If the choice of b is otherwise arbitrary, it can be chosen as n - 1 for
any n > 2. However, explicit execution of the base conversion indicated
by the statement
(be) ~ d +- k(P)
is usually avoided by using the base in which the key is represented in the
original files. If a base conversion is required, it can be performed once on
the first stage and the resulting vector d incorporated with the item for use
on subsequent stages.
Base conversion may sometimes be inconvenient or impossible as, for
example, in the case of special purpose sorting equipment devoid of
6.1
191
arithmetic units. In this event the stage required for each digit (b-way
classification and subsequent merge) may be executed as a series of copy
operations each utilizing fewer than (b + I) files. If, for instance, the
digits are represented in a ranked binary n-bit code, a series of n two-way
classifications and two-way simple merges will effect the desired ordering
on one digit of the key. More generally, a group of p successive binary
digits can be treated at each pass, providing that 2 P + 1 does flot exceed
the number of files available.
Repeated block sort. If a set of items is classified on the high-order
column of an associated vector key, each of the resulting subvectors can be
separately ordered and then nlerged in a final sinlple merge. Thus each of
the subvectors forms an infix or block in the final arrangement. Such
block sorting can be used to distribute the labor among a number of
independent sorters.
Block sorting can also be repeated by further classifying each block on
the next lower-order column of the key. For a key vector of dimension q,
q repetitions of the block sort yield a conl plete classification, and ordering
can then be achieved by a subsequent sinlple merge. However, since the
number of blocks produced is (except for duplicate keys) equal to the
original number of items, the use of repeated block sorting is unattractive
unless simplified by special schemes for keeping record of and controlling
the numerous blocks. Two such schemes will be discussed. The radix
exchange sort (Sec. 6.4) is appropriate to random-access storage only: the
amphishaenic sort is appropriate to serial files.
* Presented by John Mauchly in the Moore School lectures (1948) and treated morc
fully by Ashenhurst (1953).
192
Sortin,')a
6.1
Table 6.9. This table describes the partial pass column sort for reordering on a
single column of the decimal key (thejth). The parenthetical expression follow
ing each file (1) i indicates that it contains all itenls whosejth key digit equals one
of the enclosed integers. A second pair of parentheses indicates a second set of
itenls in the file following, and grouped separately from, the first set. Thus the
original input file (})o is described by (1)0(0, 1, 2, 3, ... , 9) or by any pernlutation
of the decimal digits enclosed in a single pair of parentheses.
Output Files
Step
Input File
Remaining from previous steps
Pass
Fraction
<I>.~ :
(0,2,4,7)
(l, 5, 6)
0,8,9)
1.0
<j>~ :
<1>1: (0,2; 4, 7)
<I>.): (l, 5, 6)
<I);: (3,8,9)
(V o :
'
(2,7)
(4)
(0)
0.4
(5)
(1)(2)
(6)(7)
0.5
(j)o: (0)(1)(2)
(})1: (6)(7)
(3)(4)(5)
0.5
(j):!:
(9)
Copied
(J)3:
(3, 8, 9)(4)(5)
<1>1: (6)(7)(8)
<1>1:
<})o:
(1)2:
(0)(1)(2)(3)(4)(5)
(9)
(8)
(6)(7)(8)
0.3
(9)
0.1
(1)3 :
<1>0: (0)( I )(2)(3)(4)(5)(6)(7)(8)
<I):.!: (9)
(1)3 :
(1)1:
Total
Table 6.9
2.8
The first step copies each item whosejth key digit is (0, 2,4,7) to file <1\, itenls
(1, 5, 6) to file (1)2, and items (3, 8, 9) to file (T)~3. After each step, only the previous
input file and the next input file are rewound, in this case <I>o and <I>1. In step two,
itenls (2,7) are copied to (1)2, and therefore.follow the group (1, 5, 6), as indicated
by the separate parentheses. Sinlilarly, items (4) and (0) are copied to (1)3 and <Do,
respectively.
Step three is preceded by a rewind of (1)2 and (1\. Since items (I) and (2) occur
in separate groups in the new input file $2' they can be copied to <1)0 in separate
groups (I) (2) as indicated. Similar remarks apply to items (6) and (7) copied to
(}\. The three subsequent steps complete the required ordering, producing in the
original input file (1)0 the ordered array (0) (1) ... (9). The rightnl0st colunln
shows that fraction of the original file (assuming a unifornl distribution of the key
digits) copied on each pass. The total at the bottonl indicates that the expected
execution tinle is equivalent to 2.8 full passes.
The partial pass process of Table 6.9 is described more concisely by the
O-origin matrix M of Table 6.10. Element M/ specifies the file to which
6.1
Digit
Digit
0
0
Digit
1 2
Digit
Digit
1 3
Digit
Digit
Digit
1 2
Digit
1 0
Digit
1 2
Input
Table 6.10
193
1 2
items with key digit s are to be assigned in the rth step of the process, for
r E lO(6) and s E lO(10). The eleventh and last row of M specifies the input
files, i.e., M/l is the index of the input file in the rth step. An algorithlll
based upon the matrix M is described by Program 6.11.
Program 6.11. The subloop 14-18 perfornls the classifIcation according to the
element M/, using file i (specified by M/) on step 9) as input. When the file is
exhausted, the branch to step 6 increnlents r and repeats the process unless
r = v(M). Equality indicates conlpletion of the jth colullln and causes a branch
to step 4 to decrenlent j and reset r. The conlparison on j is deferred to line 13
so as to follow the ternlination and rewind of the new input file. The branch on
step 10 prevents the recording of a dunlnlY itenl on the original input file. The
previous input file is rewound by step 8.
Program 6.11 includes the two-phase column sort as a special case, for
if (b + 1) files <Do, <D 1 , , <Db are available, the nlatrix shown on p. 194
specifies a process essentially identical with that of Progranl 6.7. File (1)/1
corresponds to file <D oo, the first column of M deternlines the b-way
classification, and each of the b succeeding colunlns specifies the copying
of one file in the b-way simple nlerge onto file <1)/).
The method of partial passes is frequently used in the sorting of alpha
betic data. Variants include the 1-} pass-per-character nlethod of sorting
194
6.1
Sorting
0
1
h
b
I
M== .
j +-q
O-origin indexing
1+-0
7T(D)
j +-j - 1
+-
I' +- -
1'+-1'+1
I'
l{M)
7TD i )
1 +- M/)
-+-
Files (i
As in Table 6.10.
Positional representation of
Base of representation.
Column stage = q
I'
Legend
q - 1
10
j - r
11
<[); +-
C),
12
7T( <I);)
+-
13
14
15
(b(q))
~d +- kCp); b
16
+-
17
+-
18
<!)k +-
Al
<
0
+-
<D i
(1)
Al
dj
M/i
Program 6.11
III
files
-.i.
6.1
195
punched cards * and the proced ure described by McCracken et al. (1959),
p.312.
Anlphishaenic sort. The amphisbaenic sort (Nagler, 1959) is a particular
arrangement of the repeated block sort employing partial passes. For a
base b key it requires b + 1 files and proceeds as a sequence of classi
fications, with a simple merge of the last b subblocks produced occurring
immediately after each classification on the low-order colulnn. Each
classification allots digits to the available output files according to the rank
of the file index, e.g., if file $0 is the input, the digits 0, 1,2, ... , h - 1 are
allotted to files 1, 2, 3, ... , h, and if file (P:3 is the in put, they are allotted
to files 0, 1, 2, 4, 5, ... ,b. The files are recorded forward and (except for
the initial input) are read backward without intervening re\vind. The
subblocks are designated by the key digits on which they have been
classified, e.g., by 0, 1,2, ... , b - 1, 00,01,02, etc. The block chosen
for classification at each step is the one with the smallest designation
among those not yet n1erged, the designations being ranked according to
their values as decimal (h-ary) fractions. Thus block 213 precedes block
214, which precedes block 22.
Table 6.12 shows the steps of an amphisbaenic sort on a three-digit,
base three key using files <Po, <D 1, <D 2, and <1):3' with the initial and final data
on file <Do. The input files are designated by asterisks. Thus file (Do is the
input to step 1, and blocks 0, 1, 2, are classified to files (P t , <D:!, and (f):3 as
indicated. Step 2 classifies the smallest block (0) from file <PI to files <1)0' <D:!,
and <D 3 . Step 3 classifies blocks 000, 00 I, and 002 to files <D t , <])2' and (P:~.
The next step merges these blocks to file (1\), and the following step begins
classification of the next smallest block (01) on file <D:!. It is clear that if
the files are read backward, the next block to be classified is always
immediately available. The general process for a q-digit, base b key is
described by Program 6.13.
Program 6.13. O-origin indexing is used throughout. Each classification is con
trolled by the ""current" vector c (of dinlension b), whose conlponents are the
successive indices of the available output files. Thus c k is the index of the file to
which digit k is classified (steps 16-19). The current vector is deternlined by
step 10 so as to omit the index i of the current input file. The selection of the
block to be classified is determined by the vector h (of dimension q), the next
block to be classified on digitj being determined by the prefix a j +1 jh. Because the
classifications proceed for increasing values of j and the blocks just produced
appear last on the files, the selection can be determined by the last component of
the prefix alone, i.e., by h j This is done on step 7, where the index i of the input
'0
0'\
Step
<Do
<1>1
4 (merge)
000-002
00
<D"
(0,0,0)
1
2
000
1,01,001
2,02,002
(0,0,0)
s
c
(0,0,0)
(1,2,3)
(0,1,0)
(0,2,3)
2
(0, 1,0)
(1,2, 3)
1,01 *
2,02*
(0, 1,0)
I
I
Step
12
13 (merge)
14
15 (merge)
<D;
j
1,01
2,02
(0,0,0)
I
i
j
s
c
*
111
2,12,112
(1, 1,0)
1
2
(0, 2, 1)
(0,2,3)
*
2,12*
(l, 2,0)
2
1
121
122
2*
(1,2,0)
3
2
(0,2,3)
(0,1,2)
*
*
2
(2,0,0)
6 (merge)
8 (merge)
9 _ _1
000-002,010
OIl
I*
2,02,012
(0, 1,0)
2
2
(0,1,2)
(0,1,3)
000-012
16
17
18 (merge)
1-9
20 (merge)
000-122,20
21
22
*
(2,0,0)
3
1
(0,3,3)
(0, 1,2)
000-122*
21,200
22, 201
202
(2,0,0)
000-202
21*
22*
*
(2, 1,0)
3
1
000-202,210
*
22,21 I
212
(2, 1,0)
I
2
(0,3,1)
(0,2,3)
000-212
2,02*
(0,2,0)
1
1
00-012,020
021
1,022
2*
(0,2,0)
3
2
(0,1,3)
(0,1,2)
2
(0,3,0)
(l, 2,3)
000-022
1*
2
(1,0,0)
000-022, 10
11
III
~
g-.
~
2, 12*
(I, 1,0)
2
1
2
(0,2,0)
(l, 2, 3)
(merge)
000-102
11*
000-022*
11,100
101
2, 12, 102
(1,0,0)
2, 12
(1,0,0)
2
1
(0,2,3)
(0, 1,3)
22*
*
(2,2,0)
3
1
10
21
122 (merge)
000-212,220
221
*
222
(2,2,0)
2
2
(0,3,2)
(0, 1,3)
000-222
*
*
(0,0,0)
-I
I
Table 6.12
em
?'
~
O-origin indexing
dj
.f
<l>i
controls current
classification.
S j is index of input
file to classification on
digit).
Positional representa
tion of key.
=q
Legend
1T(<I +- e(b)
[+-0
h +- (q)
~l
[:0
20
[+-1
21
i+-O
1T(<I>O) +- 0
22
j+-O
P +-l<1>i
23
i +- (eijlO(b))h j
) : q - 1
24
j+-j+l
k +-(c o
Sj
+- (q)
+- i
c +- eijlO(b)
11
k +- (j
12
<l>Ck
+- 0, Al
13
<D Ck
+- 0, Ao
15
= q - 1) 1\ (co = 0)
<
Al
k : b
27
+-l<D Ck
28
k+-k+l
29
30
k : b
hj
Al
26
<1>0 +- P
<
)+-)-1
k+-k+l
<
25
0)
P +-1cI> Ck
10
14
+-
i +-
b 10 (h j
+ 1)
31
32
Sj
33
(bE(q)) ~ d +- k(p) ; b
<1>0 +- 0, Al
34
18
k +-d j
1T(<I>O) +- 0
35
19
<l>Ck
16
P +- f<l>i
17
+- P
Program 6.13
Amphisbaenic sort
197
198
Sortina
1-'"
6.1
to the preceding stage deternlines the vector .ijlO(h) of output indices, fronl which
the new input index is selected as the h}h conlponent. The succes~ive values of h,
i, j, S, and c listed in the example of Table 6.12 I11ay be helpful in tracing the
operation of the prograI1l.
When classification on the last digit is conlpleted, the last subblocks are nlerged
(steps 25-30) onto the output file (1)0. The variable j nlust then be decrenlented
and the component h j incremented I1lodulo b (steps 31-32). When h j conlpletes
a cycle (becomes zero), the corresponding subblocks are exhausted and j nlust be
decrenlented repeatedly until the corresponding h j does not beconle zero. The
nlain process through increasing values ofj is then repeated.
Although h j deternlines the input subblock for the classification on digit j, it
deternlines the index of the input file only indirectly (step 7) through the vector
of output files, itself determined by the input file i used in the classification on the
preceding digit. When j is increasing, the value of i is sinlply the value fronl the
preceding stage. However, when j is decrenlented (steps 31-32), it is necessary to
deternline the input i used in an earlier classification. A record of the value of i
corresponding to each classificationj is therefore kept (step 9) in the vector s, and
is used to redefine i on step 33.
Each file to be used as output (except possibly file (1)0) is first closed with a
partition (steps] 2-] 5) to demark the beginning of each of the subblocks to be
recorded. Since back\\-'ard read is to be used, two dunlnlY itenls are provided so
that the branch on Al coincides with the read of a dunlnlY itenl. An extra read
then disposes of the extra dunlnlY. Any partition recorded on the final output
file (1)0 before a fully classified subblock (when j = q - ]) would renlain in the
final output. Step]] prevents this by initializing the index k to ] ifj = q - ] and
the index of the first output file (that is, co) is zero. In a sinlilar manner, step 25
prevents the attenlpt to copy file (1)0 to itself during the nlerge phase (steps 25-30).
Step 28 reads the extra dumnly item recorded in the partitioning operation of
steps ]2-]5.
All files are read backward except the initial input in the first stage. This
behavior is controlled by the logical variable.r (steps] 6 and 20-2]). The branch
on step 20 fails the first tinle only, allowing/'to be respecified as 1 and rewinding
file <1>0. On subsequent stages, the branch to step 23 causes the read of the extra
dunlnlY partition.
Cascade sort. * The cascade sort is a partial pass merge sort, with each
stage proceeding as follows. The strings are initially distributed (unequally)
among In of the 111 + 1 available files; an m-way merge to the empty tile is
perfonned until sonle input is exhausted; an In - 1 way merge to the
newly emptied file is then performed from the relnaining inputs, and so on
to a final two-way merge. The effectiveness of the process depends on a
particular initial distribution of the input strings.
Table 6.14 illustrates the process for 190 strings distributed anlongfive
of six available files as shown in the first row. Succeeding rows show the
Due to Betz and Carter (1959). See also Gilstad (1960) and Carter (1962).
Eraluarion
6.2
(~l serial
sorting Incthods
Distribution of strings
Stage
0
1
IS
29
3
4
1
0
Table 6.14
41
12
3
1
0
(~ascade
50
14
4
55
15
5
I
I
199
nlerge sort
6.2
Three Inajor factors enter the eval uation of a serial sorting process:
the amount of program storage required~ the nun1ber of serial-access flies
used, and the execution time. The first two factors require little analysis~
and attention will be limited prin1arily to the third.
Because the execution tinle of a serial sorting process is nOrInally
determined almost cOITIpletely by the tilTIe required to transfer inforInation
to and from the serial files~ the execution time is assun1ed to be directly
proportional to the number of passes of the files required. Each phase
corresponds to a pass or (as in partial pass Inethods) to SOITIe fraction of a
pass, and the number of passes per stage is detern1ined by sun1n1ation over
the component phases.
The constant of proportionality relating actual execution tin1e and
number of passes depends on such factors as the average length of the
items, the reading and recording rate of the serial files~ and (in processes
* The jth column of the table refers not to a specific file but to that tIle which
ranks jth in nunlber of strings.
200
6.2
Sorting
requiring rewinding after each phase) the rewinding speed. Since these
factors are specific to particular eq uipn1ent and particular tasks, and since
the nature of the dependence is obvious, the present analysis is lin1ited to
consideration of the nun1ber of passes.
Consideration is also given to related orderings (cf. vector keys and
categories), which may, in the use of colurnn sorting, be achieved more
efficiently jointly than separately.
==
pogm sol,
==
(a
/11
is obtained as the
2 logm 2
2 log(2k-I)
logml s
logk
2 logs k
logs (2k -
2 10gIo k
I)
loglo (2k -
1)
log('(2k -
1)
* An odd number n would prejudice the result against the single-phase method, since
one file would necessarily be left idle.
6.2
17
201
f=
1010001100
d= 0000100000
b= 0101010011.
e(+/f)
+ e(+lb) +
e(+ld) = n
1.
202
6.2
Sorting
CfJ.
q2
==
10g'Jl g
Jog,)~ g
==
logy h2
logr, hI
==
10g'Jl h2
log'q hI
==
10g
b.).
b
1
qi
loglo h 2
q'2
loglo b i
The foregoing expressions are identical in form to those obtained for the
number of stages required in the merge sort, but with the range g replacing
the initial number of strings SO' and with b replacing m. Moreover, the
nunlber of files required depends on b in the same way that the corre
sponding merge processes depend on In. This holds for both the two
phase column sort (b
1 files) and the single-phase colunln sort (2b files).
The analysis concerning the optimal value of m therefore carries over
directly to the choice of the base b, the only additional consideration being
the possible need for base conversions on the key. The comparison
between two-phase and single-phase processes also applies directly to the
column sort, with the conclusion that the single-phase method is superior.
Of the methods discussed, the column sort is the only one which shows
significant advantages in the joint treatment of two or more related
orderings. If x == zp and y == Zq are two vector keys, and if wijp == aijq,
then the ordering defined by the key zr' for r == wijp will, when applied
to the set of items ordered on y, suffice to produce ordering on x. The
total number of columns sorted to achieve the two orderings jointly is then
red uced by i.
More generally, if wijp agrees with a selected subvector of the prefix
ajjq and if the remaining elements of the prefix occur inwijp (in any order),
then sorting on the columns corresponding to w1)p may again be elided.
More precisely, if there exist integers i and j, and a logical vector u such
that
w1)p
and
(wl)p)
== u/(a j /q),
;2
Ciij(ajjq)),
then the ordering x can be achieved by applying the ordering wijp to the
ordering y, and the total number of columns sorted is reduced by i. It is
assumed that neither p nor q contains any repeated components, for if
they do, each of the later occurrences nlay be suppressed.
6.2
203
Since the ordering on x can be performed before rather than after the
ordering on y, the roles of p and q may also be reversed, and the case
showing the larger reduction may be chosen. If three or Inore orderings
are prescribed~ the foregoing method may be applied to evaluate each of
the possible sequences of ordering.
!!.l
P:3
indicates the superior efficiency of the partial pass column sort for this case.
The four files can also be used for a single-phase column sort in a base
two number system, yielding the value P2 = log2 g for the number of
passes. Hence PI!P2 = 0.843, and the method of partial passes is again the
more efficient.
In the amphisbaenic sort on n items with a q-digit base b key, h + I flies
are required, and the total number of items handled in the classification
phases is nq. In the merge phases, however, each item is handled at most*
once, and the total number of passes is therefore less than (q + I). This
may be compared with the 2q passes required in a two-phase column sort
using the same number of files. Alternatively, conversion of the key to a
base l(h + 1) -:- 2 J representation could permit the use of a more efficient
single-phase merge requiring approximately q log(h, 1)/~ h passes.
The disadvantages of the amphisbaenic sort reside in the more complex
program required and in the need for frequent reversal of the direction of
the files, i.e., from forward record to backward read. The time lost in such
reversal may be considerable for certain files.
The power of the cascade sort is, as indicated by the example of Table 6.14,
somewhat greater than that of the corresponding merge sort. Its behavior
is most conveniently analyzed [in the manner developed by Carter (1962)]
in terms of the difference equation satisfied by the number of strings
occurring in successive states. The formulation of these equations is
indicated in Exercise 6.19. Carter provides asymptotic solutions for cases
of practical interest.
* If the final output file (I)., is among the set of output files in the classifIcation on the
low-order digit, the subblock assigned to it need not be recopied in the nlcrge phase.
204
Sorting
6.2
In addition to its greater complexity, the cascade sort suffers from the
need for a particular initial distribution of the strings, and from the
dispersal of the file rewinds (which can be performed concurrently by n10st
computers) throughout the process. Moreover, in the event of a computer
error, a rerun froln the last correct input files is much Inore difficult to
program than is a corresponding rerun for a straightforward merge.
6.3
Internal sorting normally enjoys a much higher basic execution rate than
does serial sorting, but for large volulne files the limited size of internal
storage nlay make serial sorting necessary. The anlount of serial sorting
may, however, be reduced by some use of internal sorting. For example, a
preliminary internal sort can produce maximal strings whose lengths are
limited only by the size of the internal store and thus reduce the number of
strings presented for subsequent serial merge sorting.
The present section is devoted to methods of reducing serial sorting by
the auxiliary use of internal sorting. For this discussion, the only knowl
edge assumed concerning the internal sorting process is its capacity to
order a specified number of items.
Two classes of processes arise, one for aiding merge sorting and one for
aiding colUInn sorting. The aid to Inerge sorting is the simpler, since it
consists merely in assembling long strings by internal sorting before
beginning the serial merge sort. A serial column sort, on the other hand,
may be aided by a final internal sort performed after the column sort.
If k = k(x) is a key vector associated with x, and if In is any positive
integer, then a serial column sort performed on the key vector
k l = lk -:- n1J
produces the vector XO CB Xl
x P , where the vector Xi contains all
items such that k/ = i. If the infix vectors Xi are then copied in turn from
the file, individually reordered on the key
k 2 = (nl)!ok
and recorded, the resulting file will be ordered on k. Table 6.15 shows an
exanlple for m = 4.
If internal storage allows the internal ordering of as ITIany as n iteIns,
then the reordering of the infixes Xi can be accoInplished by an internal
sort provided that m is so chosen that v(x ::::~ n for all i. If the original
keys are all distinct, In may be chosen equal to n.
]f the sort on k l is perfornled as a base b serial colunln sort, the number
of stages required is reduced by approximately 10gb m fronl the number
1
)
6.4
Original Order
x k kl k 2
Xl
1 3
x2 9 2 1
x3 2 0 2
x4 11 2 3
Xs
x6 4
x7 3
1 2
1 0
0 3
Ordered on k i
X
k kl k 2
x3 2 0
x7 3 0
Xs
7
6
x6
Xl
x2 9
x4 11
Table 6.15
2
3
1 3
1 2
1 0
2 1
2 3
Sets of Duplicates in k l
XO
I)
I
j
Xl
x2
205
Final Order
x k kl k 2
x3
x7
x6
Xs
0 2
0 3
1 0
6
7
1
J
x2 9
x.t 11
2
2
Xl
2
3
3
1
3
6.4
206
6.4
Sorting
sort into two separate phases, and attention will be limited to the single
phase processes. The two-phase processes can prove superior if efficient
block transfer of data is available in the execution of the program, but
their behavior should, in any event, be clear from the treatment of the
analogous single-phase processes.
Simple classification and merge
An internal single-phase merge analogous to the serial single-phase
merge of Program 6.5 can be based on the assignment of two matrices 1 X
and 2 X to correspond to the sets of input and output files. The rows Xi of
the matrices a X correspond to the files <D i a of the serial process, each item
being represented by a single matrix element. Items are read sequentially
from and to fields; for each input field Xi, an index r j indicates the
elenlent axr ) to be read next; for each output field (3- a )Xi, an index 5 i
indicates th~ element next to be specified. The items in each field occupy
the leading positions in the field, and the index of the first unoccupied
element in the input field a Xj is indicated by the parameter t j The process
is described by Program 6.16.
I(
I(
Program 6.16. As in Program 6.5, the vectors v and z specify exhausted fields
(files) and ineligible fields (positions), respectively. The paranleters a and tare
initially specified external to the process. At the beginning of each stage the
vector v (exhausted fields) is specified (step 3) according to the unit conlponents
of t. At each stage except the first, t is respecified (step 2) by the final value of s
from the previous stage. When only one string renlains, each conlponent of s,
save the first, will remain at its initial value of unity, and this condition is used to
terminate the process at step 1. The vector k represents the keys of the current
itenls in the 111 input fields and is initiaJ)y specified (step 7) by the keys of the
colunln vector aXI of initial items of the input fields. The renlainder of the
process is closely analogous to Progranl 6.5.
6.4
t-+-s
v -+- (t
s -+-
r -+-
a -+-21 l (a
I-origin indexing
aXkh
3-aX7/~
+ 1)
k(v/ a Xl)
v/k -+-
i-+-O
10
-+- v
11
i -+-
12
.i -+- ((zlk)/ll)l
13
r ~kJ
14
3-a Xi-+- a X
15
+-
rj
16
Si
-+-
Si
17
rj
19
20
>
21
22
lJl
11 (i + 1)
si
18
+1
+1
Vj
!i =
lJl.
v= n.
I tenl k of output
field h.
Index of current
input from field h.
Sh
tit
kit
v=
111.
Exhausted fields.
Ineligible fields.
.i
tj
Legend
kJ
-+- 1
Zj ~
-::j:.
rJ
rh
k J -+- k(a X r /)
r
207
Program 6.16
21J1
fields
current input indices, and the suffix wmjb defines the ternlinating
locations t.
The strings produced by the merge from the sets of 111axinlal strings in
x a can be transferred without classification to the single output field
X 3 - a If the vector b is redefined by the beginning locations in the output
field of successive sets of
n11 items, it can be used to define the input
fields in a subsequent merge from the field X:l-a. Progranl 6.17 shows a
convenient arrangement of the process.
rs' --:-
I-origin indexing
3
Input field.
4
Output field.
b i+ I
+-
Beginning of
subfield d in
output.
"
\v = n
f
}
v = 111
+-
aftljb
+-
wmjb
I ndex of current in
put for subfield d.
(V/lI)'jl
10
+-
kg
11
k(XruQ)
+-
12
Exhausted subfields.
Ineligible subfields.
s - 1
14
15
i.( 0
-0(
16
11 +-
17
18
h -(- s
19
(/1
i -(- i
20
bi
11
21
Z +-
-0(--
+ 1)
V= In
Legend
Program 6.17
Internal single-phase
merge using two fields
22
r
23
+-
kj
24
~j
25
rj
26
1I+-11+1
+-
27
28
>
vj
+-
31
Zj +-
32
30
rs -:- n11
13
+-
kd
+ 1
208
6.4
Internal sorting
rnethod~,'
209
Program 6.17. As in Progranl 6.16, the vector r determines the current set of
items being examined, and t determines the terminal value of r. The first II/
components of b initialize r (step 7), and the last 111 components initialize t
(step 8). The index u determines the component of the output vector X3~a, which
is next to be specified (step 24).
The remainder of the process differs fronl Progranl 6.16 primarily in the deter
Inination of b. The counter Iz allows i and b i to be respecified (steps 19-20) at
the end of each group of s strings. The last specified component of b is deter
mined separately by step 5. Step 6 redeternlines v for the next stage.
Since some of the initial values so' vo, and bO may be unknown, the
initialization of the process (steps 1-3) merits some attention. If So alone is
known, VO and bO may be chosen as follows: VO == (il; b I O = 1, b 20 = veX).
The effect is to perform the first merge from a single input area. Con
sequently, the first stage performs no rearrangement but does determine
the vectors v and b.
If So is unknown, S may be determined by a preliminary string count.
Alternatively, it may be set to any integer val ue y =2 So. The process
remains valid, but the required number of stages is increased by [Iogm
yl
pogm Sol
Since So cannot exceed the number of items, the initial value s = veX) is
always valid, and for an assumed random distribution it exceeds the
expected value by a factor of two only. If greater initial order is expected.
it may be desirable to modify Program 6.17 to allow a small initial choice
of s, accompanied by automatic respecification in the event that it proves
too small. The modification may be simply made by inserting a branch on
eq uality of i and m, following step 18. The branch would succeed only in
the event that the initial specification of s were too small and should lead
to a process for increasing (e.g., doubling) s and repeating the process.
The case m = 2 is of especial interest, partly because it leads to signi
ficant simplification in the storage allocation, and partly because the
advantages which large values of m enjoy in serial sorting largely disappear
in internal sorting. These advantages arise fronl the reduction in the
number of stages with increasing m, with a nearly constant time per stage
due to the fixed reading and recording time for the serial files. In internal
sorting, the time required for key comparisons and address calculations in
choosing the minimum key becomes relatively more inlportant and, since
the key comparison time is an increasing function (frequently linear) of nl.
the advantage may lie with small values of m.
The sinlplification of storage allocation arises in the following way. A
two-way string classification on n items may be used in conjunction \vith a
single output field with a total capacity of n items by assigning the odd
numbered strings from the beginning of the field in normal order and the
210
6.4
Sorting
S2
veX)
a+-2 II (a
S +-
r
xa
+-
+--00
>
> k( X r2 a))
+-
Sk
r : k(Xrja)
.i ~- 2 11 (j +
1)
13
+-21 1
1)
14
+-
15
x:3-a
+- X
16
r +-r
Qj
17
S +- S
Qi
(i
Output field.
Index of kth input sub
field, k E (1, 2).
11 (j + 1)
12
Input field.
rk
r2
r : k(Xria)
10
11
r1
X3-a
.i +- 1 + (k(Xr1a)
8
9
I-origin indexing
1)
k(Xria)
S i
ri
Program 6.18
Legend
even-numbered strings from the end of the field in reverse order. Thus if
sj is the jth string of 2k strings so classified, the output field would contain
the array
Sl
EB S3 EB S5 EB ... EB
S2k-l
-----------~
6.4
211
212
6.4
Sorting
1~
j+-q+l
2~
j+-j-l
s+-b
+-
+-
8~
(be(q
O-origin indexing
~
ii
~-
Xa
Input field.
Xii
Output field.
Sh
Index of output
subfield h.
bk
Beginning of out
put subfield k for
next stage,
e(b)
+-
-1
+1
veX)
1O
11
X Sh a
12
Sli -- Sit
~-
d
1))~
+-
k(xia); b
dj
Xa
l
+-
+1
13
~-
d j
14
~-
+ Cik+l
E lO
v=b
(b).
Positional re- }
presentation
v = q
of key.
+1
Base of representation.
j
i
Legend
Program 6.19
6.4
213
214
Sorting
6.4
column of the key is treated in turn, the exchange process being performed
independently on each of the disjoint infix vectors defined by the preceding
stage. O-origin indexing will be used throughout the discussion.
Primary control of the process is exercised by the vector b, whose
successive components specify the beginning index of successive subblocks
(infixes). In particular, bo = 0, and bl'~l = vex), and at the beginning of
the kth stage, v(b) = 21\'~1 + 1. The storage required for b is therefore
significant but may be reduced by either of two expedients. The vector b
may be replaced by a logical vector u such that U/lo = b. Determination
of the next component of b then requires a scan of the components of u.
The use of U is thus normally unattractive except in a computer equipped
for the efficient determination of the location of the leading nonzero
component of a logical vector. The second expedient leads to a more
complex but more practicable process. The straightforward use of b will
be treated first.
Program 6.20. Steps 10~21 perfornl the exchange on the subblock with indices
k in the interval b i :::; k ,,;: b if1 . The indices Yo and Y1 designate the pair last
exchanged, k is the index of the current item exanlined,.i is the current colunln
of the key, and a is an alternator which is zero during the forward scan of the zero
section and unity during the backward scan of the unit section. The alternator a
determines which of the indices Yo and Y 1 will initialize k (step 13), the direction
of the scan (step 14), the type of key digit (0 or 1) sought in the next itenl to be
exchanged (step 18), and which of the indices Yo and Y 1 is to be redefined by k
(step 19) when the search ternlinates through failure of the branch at step 18.
If a does not beconle zero from negation on step 20, the process is repeated fronl
step 13 with a = 1, producing a backward search for a unit digit in the key. If a
beconles zero, both the forward and backward scans have been conlpleted, and
the required item exchange is perfornled on step 21. The final exit fronl the entire
loop 13~21 occurs when k = Y ii , that is, when k = Yo on a backward scan or
k = Y 1 on a forward scan. In either event, the final value of k is the beginning
index of the new subblock defined by the exchange, and it is used inlnlediately to
specify C I: on step 16. The vector c is eventually meshed with b (step 6) to re
specify b as (b o, co, b 1 , c 1 , . . . ). The initial specification of b on step 1 ensures
that the first subblock treated is the entire vector x.
6.4
b
(0, vex))
+-
j+-O
j +-j
j : q
+-
(2e) 10 LO(2 J
+-
\b, v, c\
i--i+l
bi
+-
O-origin indexing
11
r1
a -- 0
13
+-
r a
14
~-
k - 2a
15
k : r(l
16
ci
17
(2e(q l-d
18
d j : a
21
v(b) =
b i+ 1
+-
20
Beginning index
block i,
+-
+-
+-
+-
k(x k )
of sub
+ 2j
ei
~esh vector
(0, 1, 0, 1, ... , 0),
l{V) = 2)+1 + 1.
Base 2 representation of
key
(ll(d) = q).
Current column of d.
12
ra
Vector to be ordered.
bi
vex)
r o -- b i -
=F
+ 1)
-1
10
19
215
Legend
ii
x To --) x
r1
Program 6.20
2"(1)
6.4
216
Sorting
+-
e(q
+-
vex)
+ 1)
j+-O
j+-j-l
Po
j+-j-l
Pq-j : 0
+-
+-
O-origin indexing
Vector to be ordered.
Partition vector determin
ing beginning of subblocks
PI
<
(v(p) = q
d
+ 1).
Pq_j
Current column of d.
Alternator for
zeros or ones.
Pq_j
j : q - 1
+-
+1
10
j +-j
11
r o +- Po - 1
12
Pq_j
+-
13
rl
14
a +-0
15
k +-r a
16
17
k : r{i
18
(2e(q))l-d
19
dj : a
20
ra
21
22
x ro
+-
+-
scan
of
Legend
k - 2a
+-
+-
+1
+-
k(x,,)
ii
x r1
Program 6.21
~{p)
= J{d) + 1
prefix removal phase) to Pw-I and resetting P/(j to zero. Incidentally, this
procedure ensures that P It and Pv always occur as PI and P2 In practice,
these two components need not be reset if the scan for Pw is begun with P3'
Program 6.21. The reader nlay find it helpful to trace the progranl (i.e., record
successive values of all paralneters in tabular fornl) for a sinlple case of a few keys
6.4
217
of snlall dinlension. The exchange phase (15-22) is identical with that of Prograrl1
C i is onlitted. If j ,- q - I at the conclusion
of the exchange, j is incremented (step 10), r o is reset to Po - 1, and the ne\\'
partition k specifies both P(l-J and r 1 . If) = q - I, the prefix renl0val is executed
by steps 4-8. Step 4 respecifies Po, and the scan of steps 5-6 (which begins with
P3) locates a nonzero component PQ-J which is advanced to P'l~ (J; 1) (indirectly by
steps 7, 10, and 12) and is reset to zero by step 8. Steps 0- I provide the initial
specification of Po and (via step 12) of Prj'
6.20 except that the specification of
Stage
2
Stage
3
Stage
4
Final
Itenls
6
II
9
8
6
11
9
4
4
8
6
1I
9
3
4
I- 6
8
9
x5
x6
Original
Keys
Stage
Xl
x:!
x3
x4
x5
x6
Original
I Itenls
3
4
Table 6.22
11
4
6
x~
8
9
11
x4
x:3
Xl
I
I
Program 6.23. The detailed behavior of the bubble sort process described by
this progranl should be clear from the foregoing discussion. It may, however, be
renlarked that at most I' = }I(x) - I stages are executed, even though the final
order is achieved only at the rth stage.
218
6.4
Sorting
i
~-
0
0
t+-O
i+-i+1
j+-j-1
+-
Vector to be ordered.
Stage number.
Termination indicator.
Xj~
+-
Legend
k(x j +1 )
k(x j )
vex)
10
I-origin indexing
x j +1
1
Program 6.23
Bubble sort
6.4
219
I-origin indexing
3
s +- a 1(v(x)) V w 1(v(x))
Vector to be ordered.
(a,j) +-(-1,1)
String indicator
(v(s) = vex)).
Scan index.
a +- -a
Alternator ( 1).
j +--j
+a
(a #- 1)
Program 6.24
+ (a =
Legend
l}v(x)
Odd-ecen transposition sort. Like the bubble sort, the transposition sort
has unity storage ratio and involves the comparison and possible trans
position of adjacent items. Each stage consists of two phases or half~stages.
In the first half-stage, each item with an odd index (except the last if it is
odd) is compared with its successor; in the second, each item with an odd
index (except the first) is compared with its predecessor. Table 6.25
provides an example.
Original
I tenlS
Original
Keys
Xl
8
6
11
9
3
4
x2
x3
x4
Xs
x6
Table 6.25
Stage
Stage
1
6
8
9
11
3
4
6
8
9
3
11
4
6
8
3
9
4
11
6
3
8
4
9
11
Stage
3
3
6
4
8
9
11
3
4
6
8
9
11
Stage
4
3
4
6
8
9
11
Final
Items
Xs
x6
x~
Xl
x4
x3
SortinO"
220
6.4
/)
Program 6.26. The subloop 6-10 perfornls the first or the second half-stage of
the transposition sort according as the alternator a is 0 or 1. Final ternlination
occurs on step 3 as soon as one half-stage is conlpleted without a transposition
occurring, except that a mininlunl of two half-stages nlust be executed. The
nlininlunl of two half-stages is assured by the initialization of t on step 1.
1~
t ..(- 2
a +-1
I-origin indexing
+-
t - 1
+-
ii
j +-a
j+-j+2
>
k(x j _ l )
x j - I +--)0
Vector to be ordered.
Termination indicator.
Scan index.
vex)
10
<
+-
k(x j )
Legend
Xj
Program 6.26
* This result may be combined with the fact (established in Sec. 6.5) that the nunlbcr
of transpositions required is finite to establish convergence of the transposition sort.
For, if the set is not ordered, each half-stage must effect at least one transposition.
221
6.4
Ranking sort. If one new iteITI is added to a vector of itenls already ordered
on a given key, the resulting vector can be ordered by ranking the ne\V
iteITI, i.e., by comparing it with the iteITIS of the original vector in succession
until the appropriate rank of the added item is deternlined. Moreover. 11
repetitions of this process, which draw the new iteITIS fronl a given vector
of n itenls, will order the entire vector. Table 6.27 shows an exaITIple in
Stage
Stage
Itenls
Keys
Set
Xl
8
6
11
6
8
6
8
11
Stage I Stage
Stage
3
~I~
---
x~
x3
X,l
Xs
x6
9
3
4
I
Table 6.27
6
8
Final
Itcnls
---
xi)
x(}
6
R
11
6
8
11
x.I
11
x: 3
x~
Xl
Ranking by insertion. Since each stage of the ranking sort ranks one ne\V'
item in an already ranked set, the determination of its position can be
accomplished by a binary search. This sharply reduces the required
number of comparisons. However, once the new position is deternlined.
each of the succeeding items in the ranked set must be moved down one
place to make way for the new item to be inserted. This ITIethod is par
ticularly good where (due either to suitable facilities in the COITIputer or to
the use of a chained representation for the vector of items x) such block
transfer is easy to perform.
222
6.4
Sorting
i-+-i+l
I-origin indexing
vex)
Xi
Z -+-
j -+-j - 1
k(z)
x j +l
-+-
x j +l
-+- Z
-+-
Vector to be ordered.
Scan index.
k(x j )
Legend
xj
Program 6.28
-+-
Ranking sort
1
ai(v(x)) 1\ aj(v(x))
ujx
i : vex)
-+-
+-- ~
I-origin indexing
(ujx)
X
ujx
Vector to be ordered.
Seglnent to be rotated
to insert (ujX)II'
lndex of item to be
ranked.
k(x i ) : k(x j )
k(x i) : k(Xl)
10
-+-
11
-+-
13
j -+-l(p
12
<
Lower partition in
binary search.
Upper partition in
binary search.
ai(v(x)
-+-
+ q)
-:-
2J
Legend
k(x i ) : k(x j )
14
j : p
15
p-+-j
Program 6.29
Ranking by insertion
6.4
223
Program 6.29. The binary search is perfornled by the loop II-IS, which so
determines j that the new itenl x i is to be inserted after x j Since the floor opera
tion is used on step 12, j will eventually reach the value p, and step 14 therefore
ternlinates the loop in a finite nunlber of steps. Step 3 perfonns the required
insertion by a right rotation of the infix of x bounded by x j and Xi' The cases
where Xi lies outside the previously ranked set are treated by the con1parisons on
steps 7 and 9. Incidentally, step 7 takes full advantage of any initial order in the
itenls, e.g., if the set is initially ordered, steps 8-15 are never executed.
Repeated selection sort. The process of scanning all items of a vector for
the smallest key and transferring the selected item to a separate output
area (in a serial or random access file) will be called selection. Repeated
selection on the successive remaining (unselected) items will serve to
transfer the items in the order determined by the specified key. This
method of ordering is called a (first-degree) selection sort.
If the given vector of n items is divided into m subvectors of at n10st
items each, then a selection from each subvector will produce a
vector of m items, thejth of which is the smallest of the jth subvector. A
selection performed on the m items of the resulting vector will then select
the smallest item of the entire original set. I f the selected item canlC
from the kth subvector, it is then replaced by a further selection on the
remaining items of the kth subvector. Repetition of the process n tilnes
serves to order the items. Because selection is performed on two levels,
the process is called second-degree selection.
In general, the smallest (first-level) item may be selected from a set of v?
second-Ieeel items, each of which is selected as the smallest of V: 3 third-Ieeel
itenlS. The process can clearly be extended to any desired number of levels.
If p levels of selection are used, the process is termed pth-degree selection or
repeated selection. It may be represented as a singular homogeneous tree
T of height p + I, as illustrated by Fig. 6.30.
Figure 6.30 shows the initial filling of the lower levels in a third-degree
selection sort performed on the sixteen items at the top of the tree T, with
veT) == (1,2,2,4). The keys are indicated in parentheses. The positions
of the third level are the nodes (I, I, I), (I, I, 2), (I, 2, I), and (I, 2, 2).
They are first filled by items x3 (6), x6(2), xn( I), and X 14 (4), respectively, each
selected as the smallest among the second-level nodes of the corresponding
subtrees TO,I,U' T O ,1.2)' T O ,2,1)' and T O ,2,2)' respectively. The first position
of level two is then filled by x 6 (2), selected as the smallest among the second
level nodes in its subtree, and so forth. Figure 6.3 I shows the continuation
of the process through the selection of the first two output iten1s.
If e is some value which exceeds the absolute value of all keys, then the
selection process may be made more uniform by assuming either that the
entire top level of the tree is occupied by the items to be sorted or that
rn -:- ml
224
6.4
Sorting
Level
Level
2
Level
Level
xl(9)
x3(6)
~::)
x4(16)
x6(2)
~, xs(3)
~:::
x7(7)
x8(l3)
~lt
~ X12(5)
~XlO(ll)
Xll (8)
xg(l)
~X13(l5)
~~M+
X14(4)
xls(12)
X16(lO)
Figure 6.30
(1,2,2,4)
~Xl(9)
x2(14)
x3(6)
x3(6)
x4(16)
x6(2), xs(3)
~X5(3)
x6(2)
xs(3), x7(7)
x7(7)
xs(13)
xg(1), x6(2)
~X9(1)
X12(5)
xlQ(ll)
Xu (8)
X12(5)
Xg(l), X14(4)
Figure 6.31
6.4
225
unoccupied positions are filled with items having the key value e, and by
replacing each item selected from the top level by an item with a similar
key value. Termination of the process may then be determined by the
appearance of such a key value at the output. Moreover, the initial filling
may be simplified by filling all lower levels with dummy items having key
values of (-e). These may be recognized and discarded at the output.
The normal process will remove all the dummy items first, leaving all
levels in the state which would be produced by a special initial fill.
Program 6.32. The top level of the tree T initially contains the items to be
sorted (completed if necessary by dummy items having the key value of e), and
the remaining levels contain items with the key value (-e). The index vector s
scans the second-level nodes of the subtree T w1/s (steps 14-18) to determine the
index m of the node having the minimum key z. If z
e, step 10 replaces the
root of the subtree by the selected node value and step 11 respecifies s to begin
the scan of the subtree rooted in m. If z = e, then all second-level nodes contain
dummy items with "infinite keys," and step 9 branches to step 1 to replace the
root of the subtree by a dummy item as well. The branch from step 12 occurs
when the scan of the top level has been completed; it also results in the insertion
of a dummy item.
Since each complete scan (over all levels) begins with s = (1, 1) (steps 3, 11, 15),
the resulting minimum item is brought to the root of the tree. Step 2 specifies ::
as its key, and steps 4 and 7 determine its disposal. If z = e, all legitimate itenls
have been flushed fronl the tree, and the branch to step 5 terminates the output
file, rewinds it, and ends the process. If z = -e, the item is a dummy initial fill
and is discarded by skipping the recording of the output file on step 8.
= b
r(w1/s)
+ 1 + s"
(also developed in Sec. 1.23) can be used. Program 6.33 shows the repeated
selection sort of Program 6.32 executed on the right node list vector r of a
b-way rooted tree.
Program 6.33. The initial conditions are as assumed for Progranl 6.32, and the
steps of the two programs correspond very closely. The simple index modifica
tion required from stage to stage is shown in step 11.
226
Sorting
6.4
kT(;ilJS)I)
z
z : e
<1>21
7T(<1>l)
z : -e
<1>2 1
z : e
10
+-
I-origin indexing
(1)
=i
+-
+-
Tl, Al
+-
Scan index.
Index of minimum in
Minimum key.
cD 2l
Output file.
(T m )1
e2jT'Wl/s'
m CD (0)
11
12
v(s) : veT)
13
+-
14
Sv
15
S +-- S
16
z : kT s )l)
17
18
+--
+- o ,A 2
(T wl/ m )1
+-
k(Tl)
+-
+-
>
Legend
vll(s)(T)
+ WI
~
kT s )l)
+-S
Program 6.32
6.4
227
k(r p ) +- e
2
z +- k(r 1 )
m +-1
z : e
<1>2 1 +- 0, A2
I-origin indexing
7T(eD l) +- 1
Scan index.
q)l +- r 1
171
z : e
-e
10
r p +- r m
lOa
p +- 171
11
s +- b x (nl -
12
s : vCr)
13
z +- e
13a
} +-0
14
} : b
15
}+-}+1
15a
s +-s + 1
16
z : rs
17
z +- k(rs)
18
m +-s
z Mininlum key.
eD 21 Output file.
1) + 1
~
(to be replaced).
Program 6.33 Repeated selection sort of Progranl 6.32 executed on the right
list node v~ctor r of a unifornl rooted h-way tree
6.4
228
Sorting
P3
(T'W 1/s)1
Z +-
I-origin indexing
5
6
>
PI
+-
+-
cD I
I
k(Tl)
(1)
+-
z . -e
Scan index.
Minimum key.
9
10
(Tw1/m)1
11
S +-
12
v(s) : v(T)
14
z+-e
16
>
(T m)l
m ffi (0)
13
17
+-
<J)I
+-
+- S
+ WI
>
cD 21
Output file.
Legend
w : k((Ts)l)
18
z : k((Ts)l)
19
20
21
z : e
22
w : -e
23
+-
k((Ts)l)
+-
+-
-e
Program 6.34
6.4
229
the original group. If not, the item must be allowed to retain its position
but must be excluded from consideration in the sorting process. In general,
sorting with replacement allows the production of longer output strings
than would be otherwise possible with the same internal storage capacity.
The expected increase is discussed in Sec. 6.5. Since the process terminates
with the original positions completely occupied by ineligible items, the
production of a further string can be begun simply by declaring all itenls
eligible.
.
230
6.4
Sorting
k(w)
+--
P5
PI
+--
vex)
+--
-e
z : k(w)
7
8
9
i=
+--
+--
e
I-origin indexing
+I
<1>11
+--
vex)
+1
w~xJ
10
11
i+--i-l
12
k(w) : k(x i )
13
W~Xi
14
k(w) : e
15
<1>2
16
+--
+-
+--
Vector to be ordered.
j
i
Current item.
Scan index.
j+--j-I
j
<D 1
Input file.
cD 21
Output file.
k(w)
Program 6.35
the item with the smallest key among those scanned and (unless k( w) = e) is then
recorded in the output file and used to define z, the key of the last recorded item.
The main loop is then repeated from step 5, where w is respecified by reading
an item from the input file. If the new item is eligible, the branch from step 6 to
step lOis followed; if not, the parameter j (denoting the index of the first in
eligible item xi) is decremented and w is interchanged with the last eligible item xi
before continuing to step 10. Since step 10 initializes i to the value j, the sub
sequent scan is limited to eligible items.
Ifj becomes zero on step 7, the entire set of items including w is ineligible.
Step 8 then restores j so as to make all items eligible and hence to start a new
string.
The branch from step 5 and the subsequent redefinition of step 5 on step 2
serve to introduce "infinite" keys after the input file is exhausted. The immediate
redefinition of j and z (steps 3 and 4) to make all items eligible may appear
redundant. It may be verified that this procedure (1) does not increase the number
of strings produced, and (2) avoids the potential error of omitting the last string.
6.5
231
~).
p = (7,5,3,6,2,4, I).
and
the
the
the
the
scan length
number of stages required
number of transpositions required
storage ratio.
232
6.5
Sorting
y( n
+ 1) = (n + 1) y( n) + n! 2
k =0
= (n
l)y(n)
+ (~)(t1 + 1)!.
The function
y ()
n =
n!(n2- n)
4
yeO)
yen)
n!
(n 2
11)
n)/2 and
6.5
233
A pair of items whose relative order differs from the final arrangement
will be called a disordered pair. Thus in the set (2, 4, 3, 1), the disordered
pairs are (2, 1), (4,3), (4, 1), and (3, 1). To establish order it is clearly
necessary that each disordered pair be transposed. The sequential
transposition of disordered pairs of adjacent items is also sufficient to
produce ordering. Any transposition method which transposes only
disordered pairs therefore achieves order with a minimunl number of trans
positions and hence with an expected number of (n 2 - n)/4. The ranking
sort, bubble sort, and interchange sort all fall into this category. The
sequence in which the transpositions occur will, however, normally vary
for different methods. Thus the sequence of arrangements realized in
reordering the set (2, 4, 3, 1) is (2, 4, 1, 3), (2, 1, 4, 3), (I, 2, 4, 3), and
(I, 2, 3, 4) for the bubble sort, and (2, 3, 4, 1), (2, 3, I, 4), (2, 1, 3, 4), and
(1,2,3,4) for the ranking sort.
Bubble sort
In the bubble sort, both the number of stages and the scan length depend
on the initial order. The minimum and maximum number of stages
required are one and (n - 1), respectively. The minimum and maXimUl11
scan lengths are nand (n 2
n - 2)/2, respectively.
The expected number of stages required for a randonl initial order is
determined * as follows. If, at any stage, all itenls are ordered except for
one which occupies a position below (later in the seq uence than) its proper
position, then one further stage will complete the ordering. On the other
hand, each item which appears above its terminal position at a given stage
will be ITIoved down by exactly one position in the next stage. Conse
quently, the number of stages required will be determined by d, the
maximum upward displacement from its final position of any item in
the original array. More precisely, if x is the given vector of items, y the
corresponding vector of ordered items, p is a permutation such that
y = xp ' and d = II - p, then d = ((e["d)/d)I.
If the maximum upward displacement is d, then (assuming that all
keys are distinct and that the final order is consequently unique) the last
item in the final order (i.e., Y 71) can initially occupy anyone of the (d + I)
components of the suffix W d +1/X. Similarly, y ii-I may initially occupy any
one of the remaining (d + 1) positions of the suffix w d t-2/ X, and so on for
each of the (n - d) items of the suffix wn-d/y. The number of possible
initial arrangements of the items ofwn-d/y is therefore (d + 1)(n-d). Since
the d leading items (i.e., ad/y) can occupy anyone of the d remaining posi
tions without restriction, the number of possible initial arrangements with a
234
6.5
Sorting
c(n)
II
0.798
0.853
0.877
0.893
0.904
0.918
0.927
0.934
5
10
IS
20
30
40
50
Table 6.36
pr(r
s: d
1)(n-d) d!
.
n!
Similarly,
pr(r
(d
s: d)
d(n-d+l\d - 1)!
- 1) =
n!
and hence
pr(r
d)
pr(r
(d
s: d)
- pr(r
+ l)(n-d) d!
d - 1)
- d(n-d+l)(d -
I)!
n!
The expected value of r is given by
n-l
er
n-l
~ d
x pr(r = d) =
d=O
d x pr(r
d)
d=1
l(ni
d(d + l)(n-(l) d! n!
l
nil d X d(n-d+H(d -
d=1
er
where
zen)
I)!).
(/=1
= t+
I) brings
n - zen),
1
= -
n!
sn-s s !.
s= 1
It is shown in the appendix to this chapter that zen) approaches the value
V 7rn/2
for large n, and Table 6.36 gives coefficients c(n) for the approxi
mation
zen)
= c(n)"/7rn/2.
6.5
235
Since one extra stage is needed to determine that the ordering has been
completed, the expected number of stages is given by
e(J = n
1 - ,zen).
Since the scan length in the jth stage of the bubble sort is known to be
n - j + ], a similar analysis can be used to determine the expected total
scan length es' The result is
es =
n2
n - 2
+ (n +
or approximately,
es
.
Ir ')
11 -
--
l)z(n
I) -
nz(n),
37T11
AI
.~
Ranking sort
k+2.)
(I r
r=2
- 1=
k2
5k
+2
'
/12
+ 7/1
4
4 _
7;=1
!.
k
But
n I l
= y + loge n + -
I 1.'=1
approximately, * where y
e=
* See,
n2
+
4
211
711
- --.)
1211
+ -1-2 ,
1211
236
6.5
Sorting
correct to two decimal places for all n > 1. The maximum and minimum
scan lengths are (n 2 + n - 2)/2 and 2(n - 1), respectively.
The ranking sort takes advantage of initial order and the minimum scan
length of 2(n - 1) is achieved for an initially ordered set of items. Ranking
by insertion with binary search, as described by Program 6.29, requires
approximately 2 + [log2 jl comparisons on the jth stage. Hence if n = 21.:,
the number of comparisons required is given by
=
~
(2
(2
+ k)2
k)21.: - (2
k
21.:
+ 22 + 23 + ... +
= (k + 1)21.:.
In general, then,
e . n(log2 n
21.'-1)
+ 1).
6.5
237
s = mp . m logm n.
The resulting expression for the total number of items scanned (nm logm 11)
is similar in form to the corresponding result for the m-way merge sort.
The indicated optimum choice of m is Napier's number e.
The optimum integral value of m is three, and its efficiency differs from
the theoretical optimum by less than 1 %. The value 111 = 2 simplifies the
required program and increases the expected amount of scan by only about
5 %. This case (m = 2) is referred to as a tournament sort. Larger values of
m may prove advantageous where the groups of items to be scanned are
contained in a serial store whose scan time is not significantly reduced by
reducing m.
Since p itelTI transfers are required per item selected, a more realistic cost
function for determining the optimum value of m may be given by the
function
c = (m + a)p = (m + a) logm n,
where a is the ratio of the time required for an item transfer to the time
required for the scan of a single key. As remarked in Sec. 6.2, the optimum
value of m is obtained as a solution of the equation
loge m
a
+ -.
In
+ m + m + ... + 111J) =
In -
mn
m - l'
since n
m P
This ratio also represents the increase in execution time entailed in the
initialization of the lower level positions. If sorting with replacement is
used, initialization is required for the first string only.
The ratio rem) changes significantly for the first few values; thus
r(2)
2.00;
r(3)
1.50;
r(4)
1.33.
If the expected scan time sCm) is taken as a second criterion, then (since
5(2) = 5(4) > 5(3)), the value m = 2 will be eclipsed by both 3 and 4.
N
W
QO
Stages
Item Transfers or
Transpositions
Scan Length
Sorting Method
Expected
Max.
Min.
Expected
b)
Bubblet
logm n
+I-
zen)
In + 1 -
zen)
Interchanget
IOgm(i)
n -1
Ranking
n-l
n-l
n-]
])~
== \
n - 2
--2--
In -]
I n~ In~
IOJm(~)
n2 -
n - 2
--2--
n2
+ (n + 1)2(n + 1) -
n.z(n)
+ (n + ])z(n + ]) -
lI:(n)
+ 7n
- - 4 - - 1.6 -logl'n-
n(log2 n
+ 2)
Min.
nq
nq
n2
Expected
IOglfl(~)
nq
+n- 2
.)
n- - n
--2-
.)
n- - n
n
2n
4
+n-
2 I 2n _ 2
2
n(log2 n
Min.
Max.
n'2 -
n log mn
nq
nq
n- -
-2
n2 -
n'2- n
+ 2) I
2n -
n- - n
1
nmp = nm logm n
I S~
-- ---
n logm n
nq
n2 -
11
Max.
Storage
Ratio
nmp
nmp
np
n'n:n I
0
np
I~
m-l
TTfl/2
Table 6.37
CO')
Q"\
U.
Appendix
239
fen) = s
ct,
APPENDIX TO CHAPTER 6
The following derivation of the limit of the function
z( n)
= -1
n!
L. s! sri
_,
.'i
s=l
L(n)
in
g(s
1) ds,
240
Sorting
s!
n!
+ 1)n-Sg(s) ds,
J(no (s-s-
and since g(s) is monotone increasing with a large positive derivative for
large values of s, only the upper end of the integral is significant. It can
therefore be shown that
lim V(n) = lim L(n).
n-+oo
n-+oo
Consequently,
lim L(n) = lim zen).
n-+oo
n-+oo
, L()'
n ===
I1m
n-+oo
Setting t
in
n
- (n + ~)
e
n s n + 1(,
/~ e
ds.
1 - s/n yields
!~r: L(n) =
enn-tn+!-i)
= n
Ll
= n
Ll
Ll
nn+!-i(l -
t)n+!-ie-nerll n
dt
(1- t)"+Herddt,
ent+tn+!-il]Og, n-tl
dt.
"
e-t/2-(n+~)(t~/2+t 13+ , .. )
dt.
n-+ 00
For n large, only small values of t will be significant, and all terms in the
exponent may be dropped except -en + 1/2)t 2 /2. Similarly, the upper
limit of integration may be extended to infinity. Hence,
lim L(n)
1
00
n-+oo
e-(n+~)t !2dt
n(7T/(2n
l))~i
. (7Tn/2)~.
REFERENCES
Ashenhurst, R. L., (1953), '"Sorting and Arranging," Theory of Switching, Report No.
BL-7, Harvard Computation Laboratory, Section I.
Betz, B, K., and W. C. Carter, (1959) '"New Methods of Merge Sorting," 14th A.C.M.
Conference, Cambridge, Mass.
Exercises
241
EXERCISES
6.1 A given file contains a set of 15 items Xl' .. , X I5 with associated decinlal
keys 68, 9,60,14,60,73,79,15,67,5,9,41,57,9,41. For each of the serial files
used, show the contents at the conclusion of each stage of the following processes:
(a) a two-phase classification and merge using
(i) four files.
(ii) three files.
(iii) six files.
(b) a string classification and merge using four files.
(c) a single-phase merge using
(i) four files.
(ii) six files.
(d) a single-phase merge without rewind.
(e) a base ten column sort using eleven files.
(f) a base ten column sort using twenty files.
(g) a base ten column sort using four files and the partial pass column sort.
(h) a column sort using four files and a base three representation of the keys.
6.2 Modify Program 6.4 so that it will work properly without dumnly terminal
items (i.e., each terminal partition A2 is to be associated with a legitimate item).
6.3
6.4 (a) Write a program for a base b column sort which uses backward read to
eliminate rewinding.
(b) Program a variant of the two-phase colunln sort (b + 1 files) so as to
242
Sorting
eliminate the copying of the "zero items" in each merge phase. Deter
mine the relative efficiency of the method.
(c) Program an analogous variant of the nl-way two-phase merge sort so as
to eliminate the copying of part of the items in the classification phase.
6.5 Construct the matrix M (cf. Table 6.10) specifying an efficient partial pass
column sort for the following cases:
(a) base ten and three files.
(b) base ten and five files.
(c) base eight and three files.
(d) base ten and four files using no rewind, i.e., files are to be read backward.
(e) base ten and three files using no rewind.
6.6 Using a set of matrices 1M, 2M, ... , l JM, of the form of Table 6.10, write a
progran1 to generalize the partial pass sort to the case of a mixed radix key.
6.7 (a) Reprogram the amphisbaenic sort (Progran1 6.13) so as to reverse the
order of the final output. (This is the form used in Nagler, 1959.)
(b) Program a generalization of the amphisbaenic sort which makes use of
partial passes within columns of the key.
6.8 (a) Program a modification of the bubble sort process which on odd
numbered stages bubbles the smallest item to the leading end and on
even-numbered stages bubbles the largest item to the tail end.
(b) By examining all 4! cases show that for four items the eApected nunlber
of stages is slightly less for the method of part (a) than for the un
modified bubble sort.
(c) Program a bubble sort using a string indicator s as in Program 6.24 but
using backward scan only.
6.9 (a) Program a modification of Program 6.17 to specify So = 2 and to auto
matically double So and restart if necessary.
(b) Compare the efficiency of the program of part (a) with that of the
straightforward program in which the number s of strings is assumed
equal to the number of items.
6.10 (a) Derive the relation loge 171 = 1 + alnl which must be satisfied by an
optimal value of n1 in order to minimize the cost function c = (n1 + a)
logrn n (cf. Sec. 6.2).
(b) Determine the optimal integral value of 171 for each of the cases a = 0,
1, e 2
6.11 For the amphisbaenic sort on a set of bt items with distinct keys belonging
to the set lO(b t ), determine
(a) the number of item transfers required.
(b) the number of file reversals (change of direction of read and record)
required.
6.12 Write a program describing the odd-even transposition sort in terms of
vector operations so as to show clearly the parallel nature of the process. Treat
all items with odd indices (plus a dummy item) as a vector and all even itenls (plus
a dummy item) as a second vector.
Exercises
243
6.13 (a) For each of the following sorting methods, determine whether initial
order of the items is preserved, i.e., whether the relative initial order of
all item pairs wjth duplicate keys is preserved.
(i) sinlple classification and merge.
(ii) classification and simple merge.
(iii) ranking sort.
(iv) bubble sort.
(v) odd-even transposition.
(vi) radix exchange sort.
(b) Prescribe a simple modification of the key which will ensure the preser
vation of initial order.
6.14 For the sequence of keys given in Exercise 6. I, show the explicit execution
of the following internal sorting processes:
(a) bubble sort with replacement (six item positions).
(b) pth-degree selection sort with replacement, with p = 3 and 111 = 2.
(c) ranking by insertion.
6.15 If the key is represented in a base b nunlber system, with each digit repre
sented in turn in a ranked binary code, then ordering can be achieved by a base
two column sort on successive columns of the underlying binary representation.
(a) Show more generally that ordering can be achieved by a base 21.' column
sort on (the base two value of) successive groups of k binary digits.
(b) Program the process suggested in part (a), including the deternlination of
an optimum value of k for a given nunlber n of available files. Assume an
original key of q digits, each represented by r binary conlponents. Do not
neglect the problenl of terminal conditions.
(c) If b = 10, r = 4, and if the successive decinlal digits are coded alternately
in a (ranked) bi-quinary and qui-binary systenl, the binary digits can be
grouped in twos and threes so as to allow column sorting with a nlaxinlunl
of five output files. Progranl a suitable process.
6.16 Program a sequence of rotations of infixes of the vector x which will
reverse the order of its components. (See the Ranking by insertion progranl
(6.29) for the case when the key defines a complete reversal of order.)
6.17 Assuming that an item transfer takes c times as long as a comparison of
two keys, determine a criterion for the choice of 171 in an 171-way internal revision
merge for the following cases
(a) assuming 2111 comparisons per item (n1 comparisons for eligibility and 111
for minimization).
(b) assuming that a ranking sort is used on the 111 itenl positions.
6.18 (a) Let z be a vector key of dinlension three whose successive components
represent department nunlber, job nunlber, and nanle, respectively.
Two lists are to be produced, one ordered by name within department
within job and the other by departnlent within job within name. Deter
lnine a mapping vector p such that y = zp is the vector key of least
dimension which contains the two required orderings.
(b) Let yi = Zpi be a set of vector keys defining a set of related orderings.
244
Sorting
6.22 (a) The determination of the permutation vector required in the address
table sort can be considered as a mapping from each item onto its rank
in the set. Show that for distinct keys this mapping can be performed
by counting for each item the number of items having a smaller key.
(b) Progranl the method of part (a). (This is known as a counting sort.)
6.23
Exercises
245
6.26 If the nunlber of input buffers serving 111 files is reduced to I1Z -t- 1 sonle
advantage nlay still be gained by "predicting" the file whose (currently) associ
ated buffer will next be exhausted, and initiating a transfer from it to the idle
buffer. Repeat parts (a) and (b) of Exercise 6.25 for (111 + 1) and (b + 1) input
buffers, respectively. (See Friend, 1956.)
6.27 Repeat parts (a) and (b) of Exercise 6.25 with the nunlber of output buffers
also reduced as in Exercise 6.26.
6.28 Since a given initial arrangement may be easier to bring to descending than
to ascending order on the keys, and since a final reversal of order nlay be easy to
achieve (by backward read in the case of serial files or by address modification in
the case of internal storage), it nlay be advantageous to choose ascending or
descending order according to some estimate based on the initial arrangenlent.
Write a program which first counts the number of ascending strings and then
executes a ranking sort by insertion to produce either ascending or descending
order according to which appears to be the easier to achieve.
6.29 For the first few values of n, compute and compare the following alterna
tive evaluations of the expected nunlber of stages in a bubble sort
'It
sn-s s !
(a) n + 1 - zen), where zen) =
.'i
1
n.
2: -,- .
(b)n+l-v1Tn/2.
(c) c/n!, where c is the total count of all stages required for the n! possible
initial arrangements of n distinct keys.
chapter
7.1
ELEMENTARY IDENTITIES
(V\=F ~)
o=
/\ Ix = V Ix
=FIx = =Ix
De Morgan's laws
(7.1)
(7.2)
(7.3)
(7.4)
=FIx
21 +Ix
(7.5)
=FIx = ((x ~. y) =F (x
-# / X
r y) -# (X ~ y))
(7.6)
(7.7)
(q A r)
(a /\ q) A (c /\ r)
(7.8)
= (\I Ix)
/\
(V Iy)
(7.9)
(7.10)
= ((X
y))
/<=
V Iv
(a
f c) /\
II(x r, y)
X ~ Y.
246
7.2
Canonical forms
247
/\
Yj)
1\ Y j )
V YJ
(X = Y)/.
=1= Ix
==
Moreover,
1\
y) == =f/(x
1\
y),
the first and second and the third and fourth limbs being related by
equation 7.5. Consequently,
== (( X ~\ y) i= (x <= y)).
=1= Ix
Z/ ==
Consequently,
==
==
==
(a i 1\ c j ) 1\ (qi 1\
rJ
(a i 1\ qi) 1\ (c j 1\ r j )
(a 1\ q)i 1\ (c 1\ r)j.
(a 1\ q) c; (c 1\ r).
==
1\
(vII M ) == (v/x)e 1\ y.
v/vll M == (v/ x) 1\ (vly).
and
Finally,
7.2
CANONICAL FORMS
Intrinsic vector
248
7.2
For n
k.
i(f)
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1 1
1
0
1
0
Xo 1\
Xo 1\
Xo 1\
Xo 1\
X o 1\ Xl
0
0
0
Xo
0
0
0
0
1
1
1
1\
Xl
Xl
Xl
Xl
Xl
X o 1\ Xl
Xo
1\
Xl
1\
1\
1\
1\
1\
1\
1\
1\
x2
x2
x2
x2
x2
x2
x2
x2
.((X) = i(() XP
=
(x o 1\
1\
Xl
Table 7.1
x2)
(x o 1\
Xl
1\
x2 )
V (x o 1\ Xl 1\
x 2)
I(x) =
=
(x o 1\ Xl 1\ x2 ) V (x o 1\
(x o V Xl) 1\ x2
Xl 1\
x2 )
(x o 1\
Xl 1\
x2 )
it!) =
=
i(1 V g)
j(f)
i(/) V i(g).
Canonical fornls
7.2
249
Characteristic vectors
f(x)
= V /(i(f)jp)
= V /(i(f) /\ p)
= i(f) p.
f(x)
i(f)
P = iCf) > (T ~ x)
v,A,i=,or=.
The characteristic vector and the specific vector appropriate to each forn1
will be characterized by its over-all operator 01' Thus
* The functions x V !J, x A y, (x i-: Y), and (x = y) are, except for the trivial functions,
the only associative commutative functions of two variables.
til
~
~
I i(n
II y(j./\) I
T~X
II y(j. \/) I
~X
y(f/)
ITO
y(f.=) I
XX
;<7)
I Y(f,V)
X'o /\ Xl /\
Xo
xl
Xo A xl A x 2
Xo
xl \j
Xz
Xo A xl !'\
Xo
X2
Xo /\
xl
!\
X2
Xo
V Xl V
1 /\ xl 1\ X 2
Xo
/\
xl
I, XZ
Xo
xl
\I x 2
Xo
!\ 1 1\ 1
Xo
Xo
!\
xl
!,
Xz
Xo
Xl
Xz
Xo
!'\ 1 A X z
Xo V
Xo
xl
!\
X2
Xo
Xl
\I x 2
Xo
;\
xl
!\
X2
Xo
\I Xl V
(Xo II
_
j(x)
(x o V
_
Xl)
!\
X2
Y(f"AJ
y(J,ic )
y(f.=)
r:;'
-
~
~
o
o
aO'Q
Xl /\
i;)
xl
V (0) V
(1) !'I (X O V Xl V
X2 )
V Xz
(XO /\
1\ (1) ;\
xl
Xo
X2 )
!'I
(X O
Xl
V (0) V
V
X2)
(X O
Xl
!\
/\ (1) /\
!\
(X 2)
Xl)
#- (x o A
[(1)
(x2)
Xl)
(1)
(1)
Table 7.2
(1)
(1)
= (Xo V
Xl
V 0
V 0 V 0
0 V
XOVXIVO
X2
Xo
X2 )
Xl
s:::
0
0
0
0
Xl
Xl /\
(xo V Xl
X2
X'2
o V Xl V X2
(XO V
0 V 0 V
Xl ;\
[(1)
oV
!\ 1
X o /\ xl /\
X2
Xl
1 /\ 1 !\ x 2
1 /\
o I
oV0 V0
1/\1 A 1
x2 ) A (xo V Xl
x 2)
(Xo
Xl
x2 ) (Conjunctive)
x 2 )] (Exclusive disjunctive)
x2)] (Equivalence)
fD)
-.I
Canonical forms
7.2
25]
f(x) =
Y(f, V) X (T ~- x)
(Disjunctive)
(7.11a)
y(f, /\) 0 (T ~ x)
y(f, efe) :(c (f 0 x)
(Conjunctive)
(Exclusive disjunctive)
(7.11b)
Y(f, =) v (T X x)
(Equivalence)
(7.11d)
(7.11c)
Table 7.2 shows the intrinsic vector of the function f of Table 7.1
together with corresponding pairs of characteristic and specific vectors.
These may be substituted in equations 7.11 (a-d) to verify that they do
represent the function f
Since x = Tk = Tk for some k, equation 7.1la may be written as
Tk ).
Consequently,
i(f)
y(f, V) X (T ~
T) =
y(f, V) X S(V)
(7.12a)
Y(f, A) 0 (T
T) =
y(j~ A) '0 S( /\ )
(7.12b)
y(f, #) ~~ (T~,
T) =
Y(f, #) ~ S( # )
(7.12c)
y(f, =) ~ (T /~ T) = Y(f, =) v S( = )
(7.12d)
junctive specific) matrix. Since i(f) is a function of y(f, 0) and S( 0), the
y(f, v) = iC[)
Similarly, S( /\)
= I,
and y(f, A)
0 S( /\) =
(7.13)
y(f, A) = i(f).
(7.14)
T(n
+ 1) = [E<,:__ !~!!}]'
E:
T(n)
expression T ~ x used here for the specific vector in the disjunctive form is
equivalent to the expression T !;;. x used earlier. Its use increases the uniformity of the
expressions for the canonical forms.
* The
7.2
252
where and
S(i=, n
+ 1) =
since
E \~
EvE
f, and EvE
S(#, n
+ 1) =
f. Finally,
[S(i=,
n) S(i=, n)]
-------~----------------------.
Since S( i=, 1) =
[~ :] it is clear that
1 1 1 1
0
S( =1=,2)
(7.15)
S(#, n)
1 0
0 1
0 0
, S( =1=,3)
1 0
1 0
1 0 0
1 1
1 0
1 1
1 0
1 0
1 1
0 0 0 0 0 0 0 1
and so forth. *
The following useful properties of S(#) are easily verified for the fore
going examples and may be established generally by formal induction.
The matrix is self-inverse with respect to the operations (~), that is,
S( =1=) ~ S( =1=) = I.
(7.16)
Moreover, since every row of the transpose S( #) save the zeroth has an
even number of ones,
(2) I+IS(#) = EO.
Hence by equation 7.5,
#IS(#)
EO.
(7.17)
* This result was first obtained by Muller (1954), who employed the matrix C of
binomial coefficients and showed that S( i~) = (2f)l oC. Also see Calingaert (1960).
Canonical forms
7.2
253
Equation 7.12c gives i(f) as a function of y(f, i=) and S("*). This relation
is more commonly written in transposed form and with i(f) replaced by the
equivalent y(f, V) as follows:
= S( =F)
y(f, V)
/\ y(f, =F).
(7.18)
"*/S("*).
y(l, #) =
EO.
yeO, "*) =
e.
(7.20)
= (/),
(7.21)
y(f, V)
= ref,
V),
and
y(j~ !\)
= r(f,
!\).
Moreover,
y(f, #) =
l(f),
t(f)
= iC/)
(y(f, =F) #
EO)
~ S(=F).
i([)
S( #-) ~ Y(f,
i([)
i([)
Y(f, #-)
S( #-) ~
Y(f, =)
S( =)
i(/)
i(/)
v i([)
1(/)
i(/)
Y(f, =)
Y(f, #-)
#-)
S( =)
vY(f, =)
S( =) v r(f,
1(/)
Y(f, #-)
(Y(f, =) = eO)
S( #-) ~
Y(f, =)
S( =) v Y(f,
S( #-) ~ y(f,
=)
~
~
S( =) v 1(/)
r(f, #-)
(y(f, =) #- eO)
i(/)
S( #-)
=)
~.
~
-...
~
#-)
=)
y(f, =)
S( #-) ~
y(f, =)
S( =) v 1(1)
y( f, #-)
(Y(f, =) #- eO)
S( =) v i(/)
i(/)
~ y(f, #-)
S( =) v y(f,
=)
y(f, #-)
(y(f, =) = eO)
(y(f, =) #- eO)
y(f, =)
~
~
S( #-, n)
= (T(n)
0 T(n
('~(F' n
=
S( =)
1)
S( #-)
Table 7.3
I :
Y(f, V) I E
i([)
~-~~--~-=--~-;- -~-~~-~-=--~-;
- c ~)
(3) S(#-, 1) =
(4)
S( #-) ~ r(f,
y(f,
S( #-) ~ 1(/)
(2)
#-)
.(/)
y(f, #-)
(1)
(.It
~
y(f, =)
y(f, #-)
Y(f, /\)
Y(f, #-)
I :0
Y(f, =)
EO
-...J
7.3
255
Decomposition
7 S( =).
=F) = eO).
7.3
DECOMPOSITION
f(x)
[Xi 1\
f(x vel)].
and
(2e)
i = (2e)
deco~positions
of f(x) by
2 +/u matrix F defined as
(ulk)
(2e) ~ (ulk).
If, for example, u = (1, 0, 1, 1, 0), then the index k of each component ik(f)
appearing in F is given by the matrix* C of Table 7.4. The table also shows
N
Ut
o
1
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 1
0 1
0 1
0 1
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
0
0
0
0
1
1
1
0
0
1
1
0
0
1
1 1
0 0
0 0
0 1
0 1
1 0
1 0
1 1
1 1
0 0
0 0
0 1
0 1
1 0
1 0
1 1
1 1
0 0
0 0
0 1
0 1
1 0
1 0
1 1
1 1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
;(f>
1
0
0
0
1
0
0
1
0
1
0
0
0
1
1
0
1
0
1
0
1
0
1
0
0
1
0
1
0
1
0
1
1
0
1
0
1
0
1
0
0
1
0
1
0
1
0
1
1
0
0
0
1
1
0
1
1
0
0
1
0
0
1
'f
/\
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
1
0
0
0
0
1
1
0
0
0
0
0
0
1
1
0
0
Table 7.4
Xr
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
1
dVr
/\
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
1
0
0
0
0
0
0
Xr
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
0
0
1
1
1
1
0
0
0
0
1
1
nVr
/\
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
1
1
u=(l
0
'0
c=
0)
4
5
12
13
6
7
14
15
2
3
10
11
16
17
24
25
18
19
26
27
20
21
28
29
22)
23
30
31
(~
0
0
1
1
0
b = (0
c=(l
d = (0
1
1
1
0
0
0
0
0
1
1
0
0)
1)
0)
m =(0
0)
n=(l
1)
F=
~.
~
-..
~
a
0
0
0
0
D (D
~
~
S2"
C")
0
0
1
1
0
0
I
1
0
0
1
1
0
0
CD')
--I
7.3
Decomposition
257
Let
= T
1\
c:t-'
x,
q = T .~ (ii/x),
and
r =
T~
(u/x)
be the minterm vectors of x, ii/x, and u/x, respectively. * Then the matrix
P = q
~ r
f(x)
i(f) XP
= v/v//(F;\P).
f(x)
= v/v// M,
where
(a ~ c) ;\ (q
A r).
(7.24)
(a ;\ q)
? (c
;\ r),
(7.25)
(7.26)
f(x)
= V/V//M =
= (a X q) ;\ (c X r).
Since the first and last terms on the right of equation 7.26 are, respec
tively, functions of ii/x and of u/x only, the function f(x) is decomposable.
The required functions are simply
h(ii/x)
f(x)
r =
T ~ (u/x)
a Xq
g(h, u/x)
= a /~ [T )
h ;\ [c X rJ
(u/x)]
(7.27)
Since equation 7.27 does not represent the most general possible function
of hand u/x, it appears that the characteristic matrix F = a A c does not
* Although denoted by the same symbol, the matrices T are of differing dimensions
as required by compatibility.
'j- Since i(/) is equal to
V ), it may be substituted for it in the disjunctive canonical
form.
yet,
258
7.3
A b) v
(a
7 c)
V (e ~, e),
(E ? d)
(7.28)
e=
E.
The fourth term of equation 7.28 is identically zero and is included only
for formal completeness; hence
F
(ii I~ b) V (a
1\ d).
(7.23')
A d) 1\ (q A r),
(7.24' )
c) V (E
li A b)
V (a
A c)
V (E
(7.25')
Moreover, since V I V II(X \/ Y)
may again be applied to yield
f(x)
=
I IIX)
(V V
V (V V
= V I V /IM
a X q)
1\ (b :~
a /. q) /\ (c X r
(E X q) 1\ (d X r.
( 7.26' )
/\ (c Xr V (d Xr)
(7.27')
It is interesting to note that no use has been made of the fact that b, c,
and d are disjoint. Relaxation of this restriction does not, however,
increase the generality of the matrix F, since a V E = E, a V = a, and
a V
= E. It does suggest, however, that the matrix F nlay be expressed
more compactly as
F = (a A m) V (a n n),
7.3
Decornposi t ion
259
Consequently,
f(x)
where
Since
= (li
= (a
= (Fz /\
=a
q,
c) V (e
b) V (a
m) V (a
~)
!\
(b / r)) V (h /\ (c
= T
(Xl /\
X4 ,
~\ eii/x),
Xl /\
x4 '
!\
c)
n).
r)) V (d
and r
Xl /\
r),
= f '; (ujx).
X4 ,
Xl /\
x4 ),
a = (I, 0, 0, I),
and
then
Similarly,
b
c
and
'y
(Xl /\ X4 ) V (Xl /\ x 4)
(Xl
= (xo /\ x2 /\ x~J V (X o /\ x2 /\
= x2 /\ (x o =1= x3 ),
= (x o /\ x3 ) V (xo /\ x2 /\ x3 ),
d / r = X o /\ x2 /\ xa.
x 4 )
x:~)
j{x)
= {h /\
[(in /\ x2
V
/\
x3 )
(x o
/\
V (xo
/\
(x 2
x3 ))])
3 )]}
{h /\ [(xo /\
3)
O-origin indexing
1~
(2e(v(u)))_!_k
,--------+
-<-
0
-<-
-<-
(2e) ~(ujk)
-<-
(2e)~(ujk)
Fji
k-<-k+l
7.3
260
<
'
-<-
.f(x)
il/.f)
k : 2 J1 (u)
= g(h(iijx),
ujx).
e( +ju)
-<-
e( +ju)
10
e +- e( +ju)
Base 2 representation of k.
11
d+-e~F
12
e+-e~F
13
e : (d V e)
14
15
b~a~F
16
e ~a ~ F
17
Nontrivial column of F.
(bjF)j
(ejF)j
(djF)j
(ejF)j
= a.
= a.
= e.
= E.
Legend
e : (b V e V d V e)
Program 7.5
Decolnposition of.f on u
7.3
261
Decomposition
q
r
and
= T 0 (li/x)
= T 0 (u/x),
P = q A r.
[(a
EO)
A bJ
c) V (eO ~ d),
V (a
(7.23")
(((a
* eO) A q) A(b A
r))
(a
A q)
!I (c
V (eO A q)
r))
A (d
r)), (7.25")
M = U
Vv W,
#/*//(X
Y)
#/#//X)
Hence
f(x)
= #/*//M = {[(*/=I=//U)
=1=
(#/#//Y)).
* (*/*//V)] # (=I=/=I=/W)}.
f(x)
= {[(a
EO) ~ q) A (b ~ r))
a 7~ q) A (c /\ r))J
* eO ~ q) A
(d'~ r))}.
(7.26")
262
7.3
Since a, (a
eO), and eO are the characteristic vectors of the functions
h, h, and 1, respectively, equation 7.26" may be written in the decomposed
form
h(lijx) = a .~ (T 0 (li/x
f(x) = (((h 1\ (b ~
-/\
r = T v (ujx)
(h 1\ (c ;
r)
(d
(7.27")
(i
b= (0
c =
(I
d= (0
Table 7.6
(a i~ eO)
1 0
1 0
1 0
0 0
0 0 0 1
1 1 1 1
1 1 1 1
0 0 0 0
I) (i) (I)
1)
1 0
0)
0)
b+-(a
eO) ~ F.
REFERENCES
Ashenhurst, R. L., (1957), "The Decomposition of Switching Functions," Proc. 0.( all
International Symposiunl on the Theory of Switchin/{, Harvard University, pp. 74
116.
Exercises
263
EXERCISES
7.1
0V
[j
XV.
~ (y V z) =
X ~ y)
#- (X ~ z.
7.8 Let ,( and g be two disjoint functions (i.e., ,(x) /\ g(x) = for all x), and
let h = ,( V g. Derive expressions for the four characteristic vectors of h in terms
of the four characteristic vectors of! and g.
7.9 Each of the sixteen logical functions of two variables may be characterized
by its intrinsic vector iC,() and be denoted by
+-
flex, F, y) <=>
Zi
fl(x i , F i , Yi),
264
SUMMARY OF NOTATION
S.1 CONVENTIONS
Basic conventions
(a) I-origin indexing assumed in this summary.
(b) Controlling variables appear to the left, e.g., ujx, b
r x.
y, k
t x, and
Branching conventions
(a)
jf
x:y~
(b)
x : y,
(c)
Program a, b
Scalar
u, v, w
h, i,j, k
x,y, :::
a,b,c
Vector
u,v,w
h, i,j, k
x,y, z
a,b, c
265
Matrix
V, W
H,I,J,K
X, Y,Z
A,B,C
[T,
Tree
U,V,W
H,I,J, K
X,Y,Z
A,B,C
266
Summary of notation
Dimension
Row dimension
v(A)
Column dimension
II(A)
Height
Moment
Dispersion vector
v(A)
v(A)
Moment vector
~(A)
II(A)
1.5
1.23
<5(A)
Leaf count
A(A)
Row dimension
of file
Column dimension
of file
v(<1
Degree of node i
Degree
6(i, A)
~/A)
N ull character
11(<1> )
I.3
267
SumnlalY of notation
S.3 RELATIONS
Equality
a=b
Membership
aEb
b;2a
as;b
b:J a
acb
b={1
Inclusion
Strict inclusion
Similarity
1.15
b for aU j
b ;2 a and a ~ b
b ;2 a and a ;2 b
Complementary
relations
Combined (ored)
relations
*-
w=l<=>u=O
And
*-
u 1\ v
Or
Relational state
ment
*-
u V
*-
(a .jf b)
Sum
Difference
Product
Quotient
Absolute value
z*-x+y
z*-x-y
z*-xxy
z *- xy
c*-aXlI
c *-au
z *- x
y
z
*-/
xI
Ceiling
k
k
LxJ
*- rxl
j-Residue mod h
*-
Floor
L'
*-
Ii i
1.4
= 1<=> U = I and v = 1
= I <:=:> u = 1 or v = 1
,jf
b holds
kS=:x<:::k+1
k
x
k - I
i = hq + k ~
integral.
.i ~ k <.i + h;
and q is
268
Sumn1ary of notation
a0
Ci
= ai
(a
~1.5
0 bi. Examples: x x y,
Ii
b), h
i,
1\
v, fxl.
+- x X y
+-xy
c+-aXu
C +-au
Reduction
+-
c = (0 0 0 a l 0 a 2 ) 0 a 3 ) 0 0 .) 0 (II')' 1.8
where 0 is a binary operator or rela
tion with a suitable don1ain. Examples:
+ Ix, x Ix, ~i: Iu. Reduction of the
null vector e(O) is defined as the identity
element of the operator o. Examples:
Ola
+ le(O)
/\ le(O)
= 0;
x /e(O)
= {,
V le(O)
0,
1.
1.16
Ranking
j-origin b-index
c = 0 if a b; otherwise c is thej
origin index of the first occurrence of
a in b.
ofa
j-origin b-index
ofa
a
a
Left rotation
Right rotation
Base y value of x
C ~-k ~
COlnpression
+-
Expansion
Mask
Mesh
Catenation
c
c
c
+-
u\b
tilc
+-
la, u, b/
+-
\a, u, b\ tilc=a,u/c=b
+-
ci
z+-Y~x
ulb
c +-a
0, ulc
c = (aI' a 2 ,
\a, WI'(b), b\
al'(a)' b I ,
...
bl'(b
1.6
1.14
1.9
SUlnnzary of notation
269
+-
Ey X
Wi
= (Yi
x) ~ v(w) = l'(Y)
1.15
xony
W
+-
Ej(h)
Wi
Full vector
+-
E(h)
Wi
=
=
Zero vector
W --
e(h)
W +-0
Wi
=0
Prefix of weightj
1.7
(i =j)
1
V(lV) = h
aj(h)
+-
Maximum prefix
+-
'Y./u
Maximum suffix
+-
w/u
1.1
Example:
Forward set
selector
W +-
a/a
Backward set
selector
+-
T/a
Maxima selector
+-
ufx
Wi
= I if a j
Wi
= ui
1\
/=
ai
(Xi
nl)
where
nl)
where
1.18
m = max (u/x)j
j
Minima selector
+-
ulx
Wi
nl
U i
Interval or
j-origin
identity permu
tation vector
j-origin permu
tation vector
j-origin mapping
c *- a b
c ~bLa
j-origin ordering
+-
lj(h)
1\
(Xi
= min (u/x)j
k = (j, j
+ 1, ... ,j + h
- I)
1.7
1.17
+-
()j/x
Ci
= if b i lj(v(a; otherwise
0
k i < k i+ 1
270
Z/ = X/ 0 Y/
Z ~
O/x
Zi =
CZ:/A
C = Al
+-
M~BlItA
l.16
l.6
~ktA
~k~A
Ci
~Ab
Ci
K ~ 0/t/X
+--
Ki
C ~u/B
Zi =
k i ~ Ai
yi _L Xi
l.14
C j = A bj
Sit A
l.8
1.15
= k i t Ai
A 2 (2'; ..
... ~) A"
Mi=Bil/lAi
Ci
z~Y-lX
1.5
O/Xi
l.17
= Bi S/tAi
= (),JXi
Ci =Ai
Bi
l.9
Ci = U/Bi
U/B
C =
Ul/Bl
... CD Ull/Bil
C~u\B
~U'\b
C ~'\A,u,B\
C --(- ',a, U, b'\
C ~
C
jA, u,
ja, U, bj
W~rJ./U
W~w/U
BI
/A, U, B/
a/U
W~T/U
W~UrX
W~U[X
= 0, u/C = B
ti/C
[J/C
ti/C
= A, ujC =
0, UjC
D/c = a, U/C = b
ti/C = ii/A, u/C = ujB
fJ/C = [J/A, U/C = U/B
C = jE.\a, U, E.\bj
Wi = rJ./Ui
Wi =w/Ui
Wi = a/Ui
Wi = T/Ui
Wi = Uir Xi
Wi = Uit Xi
1.10
l.18
Summary of notation
271
+--
o//X
+--
0//A
Zi
Zj
C
= X/ 0 y.iJ
= o/Xj
= AI OA2 (8
1.5
1.8
...
1.15
@AII
M
+--
tth
Mj
=
=
=
Bj
tl!
kj
t Aj
1.l6
Aj
1.6
C+--k,rA
Cj
C+--kVA
z<-YJlX
kj ~ Aj
Zj = Y j -L X j
1.14
+--
Ab
Ci =Ab,
1.l7
+--
+--
O,j/X
HI! A
C+--AGJffiB
C
<-
u//B
c+--V//B
Cj
Cj
Kj
=
=
B j Sil A j
(j,jX j
C j = u/B j
= 0, u//C = B
iJ//c = 0, V//C = b
+--
u\\B
<-
V\\b
+--
\\A, u, B\\
ii//C = A, u//C = B
+-- \
la, V, b\\
//A, u, B//
U//C
C~
C //A, V, B//
+--
+--
I/a, V, b//
ii//C
ii//C
= a, V//C = b
= iii/A, u//c =
W j = (X/V,
w
w
w//V
W+--a//V
W <- TI/V
W +-- VrrX
W <- VLlX
u//B
W+--(X//V
+--
1.9
C j = A j CD B j
j
j
a/Vj
Wj
Wj
Wj
T/Vj
V,rXj
V;lXj
=
=
I.IO
w/vj
1.18
272
E(p, q)
W/=l
Zero matrix
W +- F.(p, q)
W+-O
W/ =0
+-
kl(p, q)
Superdiagonal
Identity
W +-I(p, q)
Upper left
(triangle)
Upper right
Lower left
+-
[](p, q)
+-
[)(P,q)
+- ~(p,q)
~-
+-
Wji
W
,u(W) = P
v(W) = q, for
p andq
= (i + k = j)
= IO(p, q)
:J
Wi
Lower right
1.13
W~+l-j
= (i + j ~
W~+l-iJm =
m),
min (p,
q))
integers.
Elision of
P and q if
dimensions
determined
by
compatibility.
Wf1+ 1 - i
v+l-i
[](p,q)
S.8 TRANSPOSITION
1.12
C.i
z =
C+-B
Diagonal
C+-B
Counter diagonal
/'
C+-B
cV(B)+l-~
Horizontal
C+-B
C!~(B)+l-i
f1(B)+l-z
J
Vertical
C+-B
Vector
Y
Y
+-
Bi
J
Cf'(B)+l-i
Yi = x v+ 1
i
+-
c+-bna
Difference
c+-b~a
Union
Cartesian
product
c+-bua
+-
bi @
b n
c = EbOjb
c = EbOjb
c = b CD (a ~ b)
1.15
273
C/ = (a i 0 bj).
S.ll FILES
File
<D/
Position file
7T(<D j i )
+-
Backward
a h- l
a; Ph-l +- Ak ; stop at
position It - 1. Al lllay be elided.
Read (from position h)
Forward
a, b +- o(D/ a +- aIL; b +- Ph-t--I; stop at position
h + 1. Associated branch is controlled
by Ph+I' and b may be elided. Zero
prescript may be elided.
Backward
a +- a h - I ; b +- Ph-I; stop at position
File array
(T>
Full
Array offiles <1>/, for i E ll(/Il),
j E ll(v(D)).
Row
Row of files <I>/, for} E ll(v(<l).
Column
Column of files <1>/, for i E l\/I(<I).
Compression
u/(f)
Row
Selection as in corresponding opera
u//(I>
Colunln
tions on nlatrices.
-0(-
274
Summar.y of notation
S.12 TREES
Path i
Node i
Subtree i
+-Ai
C +-Ai
C is the subtree of A rooted in node i.
Component-bycomponent
Path reduction
C +- O/A
Level reduction
C +- O//A
j-origin b-index
B +- b
j-origin mapping
C+-bLA
C +-]A
C +-[A
C +- a 2
C +- a 2 /[A
lj
IlA}
Tree compression C
+-
U /A
Level com
pression
Level mesh
Level mask
C +-u//A
C +- \ \A, u, B\ \
C +- //A, u, B//
Path catenation C +- A ''1 B
lj
A i }l'(i)
ii//C = A; u//C = B
ii//C = ii//A; u//C = u//B.
C is obtained by connecting roots of
B to leaves of A, allotting successive
groups of at most r~I(B) ~- A(A)]
roots of B to each successive leaf of A.
SUlnmary of notation
275
Zero tree
W +-- E(k)
W +-- E
W +--0
W
Path tree
+-
E(k)
W +-- UE
W +-- UE(k)
Level tree
~ 1.23
W +-- E
W +-- u E
W +--uE(k)
Maximization
Minimization
W+--VrA
W+--VlA
Maximum path
prefix
Maximum path
suffix
W +-- w/V
Forward path
set selector
a/A
Backward path
set selector
W *--T/A
Maximum level
prefix
W ~- ex//V
Maximum level
suffix
Forward level
set selector
Backward level
set selector
W ~- w//V
ej/W
w/ej/U
W+--a//A
ej/W
a/ej/A
W ~- T//A
ej/W
T/ej/A
~-
~-
ex/V
Index
Autonlatic programming, 71
Auxiliary variables, 38
Axis of transposi tion, 25
278
Index
Cap, 29
Carr, J. \V., 171
Carter, \V. C., 198, 203, 244
Cartesian product, 30
Cascade sort, 191, 198, 203
Category, 189
Catenated scan, 135, 139
Ca tena tion, 20, 21, 29
Ceiling function, 12
Central register, 72, 78
Chain, 113, 117
filial, 128
list matrix, 121, 126
Chained representation, 110, 116, 135,
147, 221
stack, 113
Chaining block, 119
end-around, 112, 135
vector, 155
Change sign, 76
Channel-unit interlock, 95
Channel, cornn1and, 88
data, 88
input-output, 75, 95
instruction, 100
trap, 75, 97
operation, 72
point, 124
channel, 88
register, 73
Cornparison, 2
with zero,S
in corllpression, 18
of trees,S 7
of vectors, 16
Con1piler, 159
Cornponents, 13, 22
Cornpound operation, 8
staternent, 160, 165
Corllpression, 18, 21, 110, 113
tree, 54, 60
Cornputer fdes, 44
instruction, 71
progran1, 71
Congruence, 12
Conjunctive canonical fonn, 249
Connection n1a trix, 46
Contained in an ordering, 190
Control register, 72
Controlled scan, 135, 141, 147
Controlling parameter, 8
Conventions, 7
Conversion, base, 190
Convert instructions, 87
Copy operation, 177, 189
Counter, instruction, 73
Crarner, I-I., 138, 235
Cup, 29
Cycles, disjoint, 32
Cyclic scan, 135
Da ta channels, 88
path, 101
De Morgan's law, 16, 24, 64, 103, 246
Decisions, leading, 6
Decon1position, 246, 255
Index
Decomposition, chart, 257
of a vector, 21
Decrement, 78, 83
Degree, 47
Design, hardware, 71
logical, 101
systern, 71
Dickson, L. E., 65
Difference, set, 29
Din1ension, 5, 13, 38
-ordered pool, 11 7
colurnn, 14
elision of, 16
Directed graph, 46
Director, 159
Disjoin t cycles, 32
vectors, 29
Distributor, 78
Domain, 10
variables, 40
Dynamic relocation, 74
of a rna trix, 14
staten1ent, 160
End of ftIe, 90
Entry arrow, 3
function, 12
279
Equivalence, of staternents, 11
reduction, 17
Euclidean algorithm, 67
249, 261
Exclusive-or, 12
reduction, 17
Execu te instruction, 83
sequence, 2, 5
Exit arrow, 3
Expansion, 19, 21
Fanlilies of operations, 8
Fields, 205
bucket, 154
compu ter, 44
coordinate, 177
end of, 90
rewind, 183
stack, 172
vector, 128
Filler cornponents, 22
Floor function, 12
Flowcharting, 1
Fonnula, 163
equivalent, 166
Newton-R.aphson, 64
singular, 164
280
Index
vector, 15
matrix, 26
graph, 48
list, 51, 60
systems, 14
vector, 48, 60
Indexability, 76
Indexing, a-origin, 71, 186
1-origin, 12, 16
additive, 73
j-origin, 14, 43
operation, 31, 36
Indicator, busy, 94
fetch mode, 95
limit, 90
Indirect addressing, 32, 74, 76, 84
Infix vector, 16
Information store, 72
Initial node, 46
Initialization, 6
Input file, 41
Input-output channel, 75, 95
instructions, 88
I nsertion, of an instruction, 75
ranking by, 213
sort, 212
Instruction, arithmetic, 84
branch, 73, 80
channel, 100
cOlnputer, 71
convert, 87
counter, 73
enable, 75
execution, 72, 77
fetch, 72, 76
input-output, 88
logical, 78, 83
shift, 85
Integral variable, 10, 13
Interchange, 7
Interchange sort, 232
Interlock, channel-uni t, 95
Index
Internal sorting, 176, 204, 205, 212, 231,
239
Interpreter, 160
Interruption, 75, 81
Intersection, set, 28
Interval vector, 15, 33
Intrinsic vector, 248, 261
Inverse characteristic vector, 253
functions, 37
mapping, 34
permutation, 33, 139
Italics, 10
Iterns, 176
dummy, 179
eligible, 179, 181, 213, 229
relatable, 177, 189
Iteration, 4
Iverson, K. E., 69, 129
281
282
Index
Matrix, conlponent, 14
connection, 46
dimension, 5
element, 14, 75
full, 22, 26
identity, 26
nlultiplication, 4
product, 23, 33
row-chained, 120
special, 26
specific, 251
superdiagonal, 26
trace of, 27
triangular, 26
Index
Operator, statement as, 160
symnletric, 166
Optimum m in m-way sort, 200
Optinlum base for a sort, 202
Ordered set, 23, 28
tree, 45, 47
Ordering, contained in, 190
of stat emen ts, 5
on x, 29
opera tion, 36
related, 189, 200, 202
vector, 36, 176
Output file, 41
Outer product, 25
Overflow indica tor, 85
posi tions, 78
search, 149
toggle, 83
CP-notation, 163, 169
Palernlo, F. P., 154
Parameter, controlling, 8
Parenthesis, elision of, 8
notation, 161, 169
Parenthesis-free notation, 122, 163
Parity, 12
check, 98
Partial pass sort, 191, 203
Parti tion, 115
file, 41, 181
symbol, 115
Partitioned representation, 115, 118
Partitioning of a tree, 123
Path compression, 56, 60
data, 101
nlaximal, 46
tree, 57
zero extension of, 61
Permutation, 8, 32, 133, 139
of a tree, 58
vector, 33, 148, 176, 213, 231
Peterson, \V. \V., 154
Phase, 179
Phister, M., 63, 104
Phrase, 163
Physical vector, 105
Polish notation, 122, 163
Polynomial, 27
Polyphase sort, 199
Pool, 113, 116
283
284
Index
Register, command, 73
index, 73, 108
multiplier-quotient, 78
sequence, 73
Relatable items, 177, 189
Related orderings, 189, 200, 202
Relational statement, 11, 16
Relocation, dynamic, 74
Reordering, 32
Repeated selection sort, 213, 223, 229,
236
Replacement sort, 213, 226, 239
Representation, of variables, 105
chained, 110, 116, 135, 147,221
linear, 108, 110, 118
nonlinear, 109
of matrices, 119
of trees, 121
partitioned, 115, 118
solid, 106
Residue, 12
Revision operation, 183
Rewind, 90
file, 41, 183
Richards, R. K'., 63
Right list, 226
Ring, 101
Riordan, J., 69
Roman letters, 10
Root, 46
vector, 52
Rooted scan, 135
tree, 47
Ross, I. C., 132
Rota tion, 33
group, 26
left, 8, 14
Row-chained matrix, 120
Row, compression, 18, 21
dimension, 14
expansion, 21
mapping, 33
mask, 21
mesh, 20
of files, 43
operation, 8, 18
reduction, 17
vector, 14
Run signal, 81
Rutishauser, H., 69
San1uel, A. L., 153
Satellite vector, 155
Scalar n1ultiple, 13
Scan, 133
catenated, 135, 139
cyclic, 135
fixed, 137
null, 25, 28
rooted, 135
shortest, 139
Index
Sort, address table, 176, 213, 231
amphisbaenic, 191, 195, 203
block, 191, 213
bu~ble, 213, 217, 233, 239
cascade, 191, 198, 203
column, 178, 186, 204
digital, 186
exchange, 212
execution time, 199
insertion, 212
internal, 176, 204, 205, 239
merge, 178, 204
odd-even interchange, 232
optimum base, 202
partial pass, 191, 203
polyphase, 199
radix exchange, 191, 213
random-access, 176
ranking, 213, 221, 235, 239
repeated selection, 213, 223, 229, 236
serial-access, 176
string-doubling, 211
tournamen t, 237
transposition, 212, 219, 236, 239
two-phase column, 187, 193
two-phase vs single~phase, 200
with replacement, 213, 226, 239
Sparse matrix, 22, 120
Special logical trees, 60
matrices, 26
vectors, 15
Specific matrix, 251
vector, 249, 258
Specifica tion, arrow, 2
implicit, 38
program, 160
Spread, 144, 146, 154
Spruth, W. G., 154
Stack, 113, 117
vector, 166, 170
file, 172
Stage, 179, 231
Statement, compound, 160, 165
elementary, 160
equivalence, 11
number, 3
ordering,S
program, 2
relational, 11, 16
Stirling's formula, 240
285
286
Index
Tree, logical, 60
moment, 47
ordered, 45
path, 57
permutation, 58
reduction, 58
representation, 121
rooted, 47
Triangular matrix, 26
merge, 179
Union, 28
vector, 15, 30
Univac, 106
Variable, 9
arbitrary, 10, 13
auxiliary, 38
integral, 10, 13
logical, 10, 13
numerical, 10, 13
representation, 105
Vector, 13
chaining, 155
disjoint, 29
dispersion, 47, 59
filial, 128
Vector, full, 15
identity permutation, 33
index, 48, 60
infix, 16
interval, 1.1, 33
logical, 18
mapping, 134
null, 16
of rna trices, 39
path, 46
permutation, 33,148,176,213,231
physical, 105
prefix, 15
program, 7
representation, 78
root, 52
satellite, 155
selection, 22
similar, 29
special, 15
suffix, 15
tag, 79
unit, 15, 30
\Vind file, 41
\Vord of memory, 72
\Vright, H. N., 12