Microprocessor
Microprocessor
AND
S. L. H A K I ~ I
Department of Electrical Engineering, Northwestern University, Evanston, Illinois
60201
I. INTRODUCTION
I n r e c e n t y e a r s a n u m b e r of a u t h o r s , such as K a s a m i (1961), H u f f m a n
(1964), F r a z e r (1964), H a k i m i a n d F r a n k (1965), B r e d e s o n a n d H a k i m i
(1967), a n d H a k i m i a n d B r e d e s o n (1968), h a v e a p p l i e d g r a p h t h e o r y t o
t h e s u b j e c t of e r r o r - c o r r e c t i n g a l g e b r a i c (fixed-length) codes. T h e p u r -
p o s e of t h i s p a p e r is to a p p l y g r a p h t h e o r y t o t h e a r e a of v a r i a b l e - l e n g t h
codes.
* This research was sponsored by the Air Force Office of Scientific Research,
Office of Aerospace Research, United States Air Force, under grant no.
AF-AFOSR-98-67.
** Formerly at Northwestern University.
7O
GRAPH THEORETIC PREFIX CODES 71
(T ~- ~ oJljD-~j
j=l
where ~b" is the number of code words of length l~.
Given a set of probabilities P -=- { p l , p2, " . , p~ [ ~ = 1 p~ = 1},
Huffman (1952) presented a method for the construction of an optimum
prefix code. Gilbert and Moore (1959) have shown that, for a given
discrete probability distribution, a Huffman code has an average length
• Any prefix code is uniquely decipherable.
72 B O B R O W AND HAKIMI
which is less than or equal to that of any uniquely decipherable code for
the same distribution. Furthermore, they proved that every binary
Huffman code is exhaustive.
It is known that a uniquely decipherable D-nary code with W =
~ = i ~tj code words exists if and only if ¢ =< 1 (McMillan, 1956 and
Kraft, 1949). Also, any uniquely decipherable exhaustive code has the
prefix property (Gilbert and iVfoore, 1959), and such a code exists if
and only if ¢ = 1 (Gilbert and Moore, 1959 and Fano, 1961).
GRAPHICAL REPRESENTATION OF PREFIX CODES
Any D-nary prefix code X = {xz, x2, -.. , x~} can be represented
graphically by a coding tree (Fano, 1961). For example, the binary prefix
code X = {10, 11, 010, 011, 0000, 0001, 0010, 0011} corresponds to the
tree shown in Fig. 1. Each vertex of ith order produces j vertices of
(i + 1)st order, where j G {0, 1, 2, -.. , D - 1, D}. A vertex which
produces no new vertices of higher order (j = 0) is called a terminal
vertex. A complete tree is a tree in which every vertex of ith order either
produces D vertices of (i + 1)st order or is a terminal vertex. Clearly,
: , T"order
0 order ~ i vertices
vertex 3 rdOrder
• vertices
ISt order "
vertices 2.a order
vertices
FJQ. 1
GRAPH THEORETIC PREFIX CODES 73
Y4
Y3
Y2
put
Y2
input
Y~
Yl
FIG. 2
the tree of Fig. 1 is complete. It can be shown (Fano, 1961) that a prefix
code is exhaustive if and only if its corresponding coding tree is complete.
An obvious consequence of this fact is that the number of code words of
maximum length is a multiple of D.
It can be demonstrated (Bobrow, 1968) 5 that if W is the number of
terminal vertices of a complete tree (i.e., W is the number of code words
of the corresponding code), then the number of branches in the tree is
exactly [ D / ( D - 1 ) ] ( W - 1).
DECODING P R E F I X CODES
The most direct general method for decoding any D-nary prefix code
is to construct a switching network based upon the tree corresponding
to the code. Such a network is formed by replacing each branch, situated
between an ith order vertex and an (i -b 1)st order vertex, which is
labeled d C I0, 1, -.. , D -- 1}, by a normally open contact that closes
2 As a m a t t e r of convenience, for the r e m a i n d e r of this p a p e r the symbol # will
i n d i c a t e reference to Bobrow (1968).
74 BOBROW AND HAKIMI
L.(t) u7
D bl
>
FIG. 3
Fig. 3. A branch labeled b~~) signifies that branch b~ has weight d. The
arrows indicate vertices v~ and v~. Choose the partition: gx = {b~, b.,, be},
g~ = {54, bh}, g3 = {b6}, g4 = {bT},g5 = {ba}, g~ = {bg}.Thus,
p0 =~, P11 = {bt,b~}, Px2 = {be}
p 0 = ¢, P2 ~ = {b4}, p 2 = {bh}
Pa ° = ¢, Pa x = {b6}, Pa 2 = ¢
open contact that closes when the ith digit of a sequence is d. Since no
proper prefix of a code word in X corresponds to a subgraph which con-
tains a path in G, the formation of a path of transmission in the switching
network indicates the reception of a code word.
If G contains a branch t h a t is not in any path between v~ and v~,
clearly, t h a t branch is not necessary for decoding purposes. Thus, a path
decoder requires at most [GI contacts.
C~ ° = g5 = {b~}, C5 ~ = ¢ , C5 ~ = {b~}
C6 ~ = g6 = {bg}, C8 ~ = ¢ , C6 ~ = {bg}
The code words of the ternary basic cut-set code Y generated by G are:
00 022 122 0210 1010 02110 021110
20 O20 120 0212 1012 02112 021112
102 222 1210
100 220 1212
Although the tree for Y has 32 branches, I G I = 9.
78 BOBROW AND HAKIMI
For a given code, let o~ denote the number of code words of length I. A
code X consisting of ~i • ~ ~ " " -t- ~Q code words is said to be
equivalent to a code X' consisting of ~l' ~- ~2' ~ " . -}- ~2' code words
if ~z = ~z' for l = 1, 2, .-- , m, whereto = max {Q, R}.
Suppose that X is an exhaustive D-nary prefix code. We would like to
be able to determine a graph G that can be partitioned such that the re-
sulting P.B.C.S. code Z is equivalent to X. Although we shall deal with
this general problem in Section III, for the case when X has two word
lengths/1 and l~, G can be found quite readily. For the sake of simplicity,
we now develop such a procedure for binary codes. The subsequent al-
gorithm can be extended to cover the case of non-binary codes.#
Let X be a binary exhaustive prefix code with word lengths/1 and/2.
Since X is exhaustive
= wz~ 2 - q ~ w~ 2- ~ = 1.
First consider an exhaustive binary code X' having word lengths/1 and
/1 + 1, where
(A)
¢.:.N _
FIG. 4
bT
i+
i
~ vT.+l
~ bTi ,+l
FI~. 5
bi 2
V2
bil+~
FIG. 6
82 BOBROW AND HAKIMI
hi2
b5
F~o. 7
Call G the graph obtained from G' by relabeling btl+l by b** and adding
branches bz~+1, bz1+~, • • ", bl,-1 such that these branches are not con-
tained in any path between v~ and v~. Since G generates a code having
word lengths/1 and l~ only, and the number of words of length/1 is wh ; G
must generate Z.
E x a m p l e 4. Consider a binary exhaustive prefix code X with w14 =
14,954 and wl~ = 11,440. First realize, w~4 = 14,954 and w15 = 2860.
Since w1~/2 = 1430 = 21° + 28 + 2 ~ + 24 + 2~ 4- 21, a graph which
generates a P.B.C.S. code Z equivalent to X is given by Fig. 7. The par-
tition for this graph is the trivial partition gl = {bd, for i = 1, 2, • •., 17.
I t should be noted that for any binary exhaustive prefix code with two
word lengths, Algorithm 1 will always result in G having the trivial par-
tition.
Although any code equivalent to X, given in Example 4, can be repre-
sented by a tree with 2 ( W - 1) = 52,786 branches; Z is equivalent to
X , and Z can be represented by a graph with 17 branches.
In applying Algorithm 1, it is not difficult to show that for the resulting
graph G, [ G { =< (W - 1) = (w h + w~ - 1). In general, for t h e D - n a r y
ease, it can be shown//that [ G { < ½ [ ( D / ( D - 1)) (W - 1)].
In the next section, we will describe how to determine a graph which
generates a P.B.C.S. code eqtfivalent to any exhaustive D-nary prefix
code.
GRAPH THEORETIC PREFIX CODES 83
Let T be any complete tree having rth order vertices and no vertices of
order rl > r. At each vertex of order r2 < r, label the branches 0, 1, • •.,
D - 1 as shown in Fig. 8.
Let the number of rth order vertices be 7. Label the ~/D terminal
Tth order vertices incident to a branch labeled d(d E { 1, 2, . . . , D - 1}),
upward as shown in Fig. 8. In addition, label the ~/D terminal rth order
vertices incident to a branch labeled 0, downward. Call the D-nary se-
quence corresponding to the path from v0 to v~, x~; for i = 1, 2, • •., ~/D
and d E {0, 1, 2, . . . , D - 1}. Suppose that a is a non-empty, finite D-
nary sequence. We then have the following lemmas.
LEMM~ 1. I f f > e, for e, f = 1, 2, . . . , ~/D; then x~a does not include
d
xe (d E {1,2, . . . , D - 1 } ) .
Proof. Let v be the highest order vertex in common with the paths
from v0 to vy and from v0 to v~. By construction, one of the two following
cases must occur: (A) The (v W 1)st digit of xff is 0, and the (v -}- 1)st
digit of x~ is nonzero; (B) The (v ~- 1)st digit of xf~ i s j E {1, 2, . . . ,
D--2}, and the (v Jr 1)st digit of x~ is k E {J -~- 1, j Jr 2, . . . ,
D -- 1}. In both cases, by definition, x J a does not include x[.
Q.E.D.
84 B O B R O W AND H A K I M I
vp
o
i °
1
v~
~: ~io~-,
.i <
2-! 1iO
(',7/o)-i
~i v~,
Fro. 8
GRAPH THEORETIC PREFIX CODES 85
x~0 is
•
0, and the (v + 1)st digit of xs° is nonzero; (B) The (v + 1)st digit
of x~°'is3 C {1, 2 , . . . , D - 2} and the (v -5 1)st digit of x7 is k C {j -5
• 0
1, j -5 2, . . . , D - 1}. Thus, xs°a does not include x~. Q.E.D.
I t should also be noted that if dl E {0, 1, . •., D - 1} and d~ E {0, 1,
• " ", •1, "" ", D -- 1} ; then a~la does not include x~~, for all e, f = I,
2, . . . , 7/D.
Let X be any D-nary exhaustive prefix code having ~ = 1 w b. code
words, where 0 < 11 < 12 -- • < lr. Now, we present a method for con-
structing a D-nary exhaustive prefix code X', which is equivalent to X,
such that X ' has the inclusion property.
Algorithm 2. Given ~-~=1w~iD-~i = 1, where 0 < ll < l~ • - • < 1,.
Step 1. Construct a complete coding tree T1 with D ~ vertices of/1st
order. Label the D ~ = 71 vertices of l~st order as if in Fi:g. 8, li = r and
71 -- 7- Choose as terminal vertices the first wz~ vertices in the sequence
~)11' 1 I 2 2 2 D--1 D--1 D--I
V2 , " " " , V~IlD , V l , V2 , " " " , V~/I/D , " " ", Vl , V2 , " " " , V~IID ,
0
V?, Y20, • • "~ ~)~IlD
Step f (i" = 2, 3, • •., r). To each nonterminal l~_lst order vertex, con-
nect a complete tree ~4th D zr-zr-~ vertices of (l~ -- l~_l)st order. The
overall tree T: has (7:-1 -- wz~_~) D ~:-Z¢-~ = v~ vertices of l~st order.
Label these 7~ vertices as if in Fig. 8, l~ = r and 7: = 7. Choose as termi-
nal vertices the first wt~ vertices in the sequence
~)11, 1 1 2 2 2 ~--1, D--I D--I
~)2 ~ " ' ' , V~f/D , V l , Y2 , " '', VV~/D , "" ", V V2 , " '', Y~ID,
0 0
Yl 0, V2, • " ", V~/D
FIG. 9
eliminated such that the resulting P.B.C.S. code remains the same. Thus,
W - 1 is an upper bound on the number of branches required for a
graph.
E x a m p l e 6. Let X r be the binary inclusion code given in Example 5.
By the previous discussion, G is found to be the graph in Fig. 10. Since
D = 2, all branches must have weight 1. Thus, in Fig. 10, a branch la-
beled i indicates that the branch is in subgraph g~. Note that G contains
a branch in g4 which, by itself, forms a path between v~ and v~. So, sup-
pose that xr E X t, where x r = dld2d~d4 and d4 = 1. If all branches in g4 ,
except the self-path, are eliminated; then x' is still a code word of the
P.B.C.S. code generated by the resulting graph. Clearly, the removal of
these branches does not affect code words of other lengths. Hence, the
code remains unaltered. In an analogous manner, branches in gs, g6, and
3
f 6
3 6
2
f
4
| 5
FIG. 10
88 BOBROW AND HAKIMI
FIG. 11
bl ')
5(2)
3
b~l)
O, C
b~ )
FIG. 12
Clearly, all three code words of length 3 include the code word 02. Thus,
Z does not have the inclusion property.
Now, we would like to show t h a t when D = 2, the converse of Theorem
4 is valid.
THEOREM 5. Let Z be a binary P.B.C.S. code generated by some graph
G. Then X has the inclusion property.
Proof. Let zl, z2 C Z, where zl = dldg. . . . d~ and z2 = dl' dJ . . . d't, .
Assume t h a t z2 includes zl. Then, I' > 1. Suppose t h a t dz = 1[0]. Since
z2 includes zl, if d~ = 110]; then di' = 1[0] (for 1 =< i < l). But, the l's
[O's] of zl correspond to a subgraph of G which contains a path [basic
cut-set]. Thus, the l's [O's] of dl'd2' . . . d'z,-~ correspond to a subgraph of
G which contains a path [basic cut-set]. Therefore, z~. ~ Z--contradic-
tion. Hence Z has the inclusion property. Q.E.D.
Theorems 4 and 5 can be combined to yield the following obvious
theorem.
THEOREM 6. A n exhaustive binary prefix code X is a P.B.C.S. code if
and only if X has the inclusion property.
IV. SYNCHRONIZATION
In discussing decoding, it was assumed t h a t messages were received
without error (noiseless channel case) and t h a t the decoder was in its
initial state when the first digit of a message was received. Under these
circumstances, any message is synchronized with the decoder. Whether
it is due to noise or network malfunction, the loss of synchronization
could result in a significant loss of information.
In order to investigate the synchronizing properties of inclusion codes,
the following definitions are required. Suppose X is an exhaustive D-nary
prefix code. Let s be a suffix of some x E X. If there exists messages ml
and m2 such t h a t s m~ = m2, then m~ is said to be a synchronizing message
for s. If every suffix (of every x C X) has a synchronizing message, then
X is self-synchronizable.
A number of authors, such as Gilbert and Moore (1959), Schiitzen-
berger (1956, 1964, 1967), Stanfel (1966), Schwartz (1964), and Leven-
shtein (1962), have investigated the self-synchronization properties of
variable-length exhaustive prefix codes. Gilbert and Moore (1959)
showed t h a t if an exhaustive prefix code X has word lengths/1,/2, • •.,
L, then a necessary condition for X to be self-synehronizable is t h a t the
90 BOBROW" AND HAKIMI