5
ATION PROCESSING LETTERS 2 t 1973) 1-S. NORTM-UOLLrrND PUBLISHING COMPANY REPRESMATION OF BINARY TREES ON nt of co Gun td &krrct?s. nnwpdis, Minnesota 554.55, USA !\weivd 9 Jmutuy 1973 13 February 1973 bi tr WS This paper is part of an attempt to reconsider the WC approach ta t3tating memories( l-3). One of the outcomes; of this attempt is that “content oriented”’ or “asxdative” address@, in a limited sense of the word, is ii very natural mode of operation on such memories121. PotentMy, miativc addressing is a verypowerful ~pability, but in order to utilize it we will have to reexxuine the 3 sic techniquzs which are tF.x?d Lx tie rqxe~frtatio~ ar,d nanipulation of vari- 3~s dntastructures. Is &is paper we wil! :,,ok into the repwentation of biaarytrees. In orderto put tie &~ussion into proper peiqec- tie we will first review tn~e potential associative ad- &easing capability of rotating devices; or? rather, one po&ble form of this capability. The cylindercm be partitioned into storage cells, each of which is a pair: (name-cell, data-cell), or name-cell is usually much smalletthan . The following relationship would usually + Tehhl Report 72-14. rotdlting memory be sa Wed: length (nc) 5 length (dc)/ 10 . (1; The ceils of this storage space can be.addressed “by the content” of their name-part nc. By that we me&n the folknving: The memory has a repertoire P of primitive predicates. For a given predicate p E P, we cbn retrieve a cell whose nc satisfiesp in slightly more than hatf “revolutiontime” on the average; this access time will be denoted by t,. If there is no cell whxh satisfiesp, we will say that the associative search for it “fails”; such a failure takes one revolution time, to be denoted by t,. As to the primitive predicates p, we wU only say here that they should be simple enough so that the controller of the memory can compute each of them on all the nc’s of the cylinder, in tr sec. For the purpose of this paper we will orlly need simple patterr,-matching predicates. Note that the scope of associativity is only the storage space of a cylinder, which wil1 be ixlled as- soci&e space, or AS. A disk, which consi:,ts of several cylinders cannot be considered as an associative memory, but as a fmgmented as;oci&ive memory. Note that in the above we mentioned onI>* some of the aspects of the associative addressing capaMity of rotating memories, those which are relevmt tc tic3 paper. A more complete treatment of the subjcrt is . . in refs. (2 ] and (31. Note also that we do not that existing roiating d s can be addrsssed ativekj. The claim is tha s is a latent c;lpabili-

Representation of binary trees on associative memories

Embed Size (px)

Citation preview

Page 1: Representation of binary trees on associative memories

ATION PROCESSING LETTERS 2 t 1973) 1-S. NORTM-UOLLrrND PUBLISHING COMPANY

REPRESMATION OF BINARY TREES ON

nt of co Gun td &krrct?s. nnwpdis, Minnesota 554.55, USA

!\weivd 9 Jmutuy 1973 13 February 1973

bi tr WS

This paper is part of an attempt to reconsider the WC approach ta t3tating memories ( l-3). One of the outcomes; of this attempt is that “content oriented”’ or “asxdative” address@, in a limited sense of the word, is ii very natural mode of operation on such memories 121. PotentMy, miativc addressing is a very powerful ~pability, but in order to utilize it we will have to reexxuine the 3 sic techniquzs which are tF.x?d Lx tie rqxe~frtatio~ ar,d nanipulation of vari- 3~s dnta structures. Is &is paper we wil! :,,ok into the repwentation of biaary trees.

In order to put tie &~ussion into proper peiqec- tie we will first review tn~e potential associative ad- &easing capability of rotating devices; or? rather, one po&ble form of this capability.

The cylinder cm be partitioned into storage cells, each of which is a pair: (name-cell, data-cell), or

name-cell is usually much smallet than . The following relationship would usually

+ Tehhl Report 72-14.

rotdlting memory

be sa Wed:

length (nc) 5 length (dc)/ 10 . (1;

The ceils of this storage space can be.addressed “by the content” of their name-part nc. By that we me&n the folknving: The memory has a repertoire P of primitive predicates. For a given predicate p E P, we cbn retrieve a cell whose nc satisfiesp in slightly more than hatf “revolution time” on the average; this access time will be denoted by t,. If there is no cell whxh satisfiesp, we will say that the associative search for it “fails”; such a failure takes one revolution time, to be denoted by t,. As to the primitive predicates p, we wU only say here that they should be simple enough so that the controller of the memory can compute each of them on all the nc’s of the cylinder, in tr sec. For the purpose of this paper we will orlly need simple patterr,-matching predicates.

Note that the scope of associativity is only the storage space of a cylinder, which wil1 be ixlled as- soci&e space, or AS. A disk, which consi:,ts of several cylinders cannot be considered as an associative memory, but as a fmgmented as;oci&ive memory.

Note that in the above we mentioned onI>* some of the aspects of the associative addressing capaMity of rotating memories, those which are relevmt tc tic3

paper. A more complete treatment of the subjcrt is . .

in refs. (2 ] and (31. Note also that we do not that existing roiating d s can be addrsssed ativekj. The claim is tha s is a latent c;lpabili-

Page 2: Representation of binary trees on associative memories

2 A’, Minsky, S’epresentution of binary trees

(0.0)

i ,/,T<‘< t-*0:1 (2rl) (2.2) (Zs3)

t--

Fig. 1. The nodes (r, R) of a binary tree.

tyI which em be realized on them.

P 3. A? :~wcistive wpresentation of binary trees

tit us first assume that the binary tree under con- is smah enough to be fully contained in,a

(cylinder), and that the tree is the 0nly”dat.a atd on the AS. (We will later consider

laxing the first restriction, and remov-

the path Ie;lding from the roe:’

k) in left ro right order*. e that for a given I, k

r th following representation of the ation contained in the node (I, k) is

trees represented in such a way. presentation is very

dsflition of k is possible, but it is left to

CL that each node can fit into a dc, but thczi it. Note that this means that the ly l8ugc btcausp of relation (1).

introduce later some kind of pointers

4. Walks throug!! the tree

Note first that for a given pair CZ, k) we can retrieve the node (I, k) in ta set, if it exists. If the search for (I, k) “fails”, it means that this node does not exist; such a failure takes t, sec.

This is a considerable improvement over the linked tree which requires us to “walk” all the way from the root to (I, kj in order to retrieve it. This walk normallyt t‘akes I memory accesses; the average duration of each is at least half revolution time.

However, it is only rarely the case that the nodes of a tree are acceti at random. It is more common to walk through the tree in an orderly fashion, going from a node to one of its close relatives. This type of tree-walk is alra possible on an associatively structured tree, and more efficiently than on a linked tree, since for each node (l, k) -K can compute the coordinates of its close relatives, as following:

Father: r;lyl,k)=ifl>O

thm(L1,Lfi J)daeNIL$$ Left stJ‘:7: L(2, k) = (I+ 1,2k) Right son: R@,k)=(i+lJk+l) Left brothcr:# f&(1, k) = if k > 0

then (I, k-1)dseNIL Right brother: RB(l,k)=ifA<$-- I

then (I, k+ 1) da NIL.

We can therefore get directly to any one of the five relatives of a node, a capability which requires S pointers per node in the linked tree representstion. Moreover, we can get directly i;o distant relatives of a node, since we can easily compute the coordinates of nodes deftned, ‘or example, as follows:

fiF@VV* k))))

However, or.8 disadvantage of this type of access

$ Note, however, that such a tree walk m be done more effkiently as is shown in ref. [ 1) .

$$ We are using the symbol “NIL“ for the case that a node cannot exist in the tree.

#We are using here an extended m of the tefm “brother’“, namely: the closest neighbour which has the same I*

Page 3: Representation of binary trees on associative memories

sky. Repmentation of binary trees

should be pointed out: ith the exception of F(f. k)

and FYF’...F(I, ka). .) one camrot be sure in general if a

-bit filds, L’ and I?‘,

introduce the notation:

t”(l, k) a’r L_CL :. Ljl, k)...) . ntimm

Now, suppose that after accessing the node (I, k) we have to get to the farthest left grandson, namely to the node P(I, &) wih the largest n in the tree; let us de- note this ?I by q,. Suppose also that we do not know in advance how big no is, but we know that no Q N for some given N.

One way of getting to Po(l, k) is by moving step by step, from a node to its left son; this is in fact the only available method in the case of linked trees.

n we can do better of the binary lookup

rst compute, and try to access I?‘&& k). If this node is found, we know that no > !N; if there is no such node in the tree we know that no G )N. The required node will be reached in at most IYog~ N9 probes.

5. The compkte ** Iotatree

Sometimes it is necessary to traverse the whole tree and-not just walk through one of its routes. One of the most important complete traversds is the so called symnzeti hwetsrrl, which can be defined re- cursively as follows (41:

traverse the left s joire% visit the fO0” traverse the right sub?ree .

The order in which the nodes are visited under this traversal is illustrated by the example in fig. 2.

In order to perform this traversal on a linked tree representation, we have to access twice most non- terminal nodes. AS we will show below, we can some- times traverse the tree more efficiently, if it is repre-

nted associatively. Consider t:rst a complete tree of depth L. By

66 c te” we mean that all the possible nodes (I, k) wi L exist in the tree. Let ~(1, k) be the ordinal number of the node (I, k) under the order defined by the symmetric traversal (see fig. 2 for example). It can easily be proved that:

~(1 , k)= 2L-‘(2k+l) .

Note that for a given integer s such that I Q s G 2L+l - 1, we can easily compute the pair (Z(s), k(g) of the node whose ordinal number is s.

We therefore can perform the symmetric traversal of a complete tree by means of the following (semr- formal) algorithm :

fors+lstep1unti12L+1-ldo begin compute I(s); compute k(s);

visit node (Z(s), k(s)) end;

We can thus perform the symmetric traversal of a complete tree, accessing each node just once. This al- gorithm works also if the tree is not complete, but in that case the operation “vifit node” will fail for each node (I(s), k(s)) which does not exist. If the number of missing nodes is small, this may be still more effi- cient than the normal symmetric traversal. But this algorithm cannot be used if there are too many mis- sing nodes.

We may improve our traversing idgoriti m by utiliz- ing another possible capability of rotating memories, which was not mentioned in section 2: It is shown in ref. [3] that iff is a Gmple enough function defined

e-cells, then it should be possibie to

Page 4: Representation of binary trees on associative memories

4 N. M&y, Representation of binary trees

Fig. 2, Symmetric traversal. The numbers in the boxes are the pairs (I, k) which identi@ the nodes The encircled numbers defiue e traversing order.

enough function”, we mean that it is possible to ccm- pute f on all #he name-cells in the cylinder, in one fevolutior ti.n,e. It is conceivable that with a fsst e4iough controikr, the function ~(2, k) is simple enmgh m that sense. Assum& *&at, we can modify our traurersal algorithm as fohows.

91 + 1 &op: compute Z(s1); compute k(sl);

visit the node (I’, R’f such that ((l’, d) = (I(sl), k(sl)), or s(l’, k’) has the minimal Mae, greater than 91); st + E + the s of the visited node; ifsI < 2L+4 - I then goto loop;

We are assuming here that our %orage device cat carry out Phe rather complex “visil” operation. Unaer this assumption, each “visit” would take t, 3242 if the

! ’ aci;de [@I), k(d)) is found. Ef the node is misGng, however, the visit operation would t&e fr > #a sec.

_ Therefore, tie waste invoked with missing nodes is _ :’

nob as great as before, but our method still w<luld t:ot be effkient for veq sgtrrse trees.

“6. ModificMion of the tree

We will consider two types of tree modification: &I) 1ocaI mo~i~cntkm: If we are not using the pseudo-

Zitzks int&uced in section 4 then deletion or ad- : ditioq of a sin#e node is strictly locai, and is there- R

fore, more efficient than in the case of linked representation. *

Qb)giI&Z vwdificatkwz: One of the nice properties of finked representations of trees is that it allows us

to change the location of a whole subtree just by changing two pointers. And, with the support of garbage collection mechanism, we can delete a sub tree, just by deleting its root. These capabilities, which are very important in some easea, are corn- pletely lost if we use the associative tree represen- tation.

7. Removal of some reatrktions

Until now we restricted ourselves by the followiilg two assumptions: (a) ‘l%= tree is the only data structure stored on the

associative space (cylinder). (b) The tree is small enough to be stored in a single

AS. The first restriction can be removed easily, by pay

irq only a ma@nal price: If the tree is not the only data structure ssoqd on the AS, then ail its nodes should be identif: :d by some common name, T. The nmtte-~~~ of each node should Contain therefore the triplet (T, 1, k).

As to the second restriction, first note that it still leaves a wide rang of applications: If our storage device is a drum, the whole drum can be treated as a sin@e ‘AS, Also, the cylinders of many disks are large enou@ to accomodate medium size trees. For example the volume of B (:ylinder of IBM/3330 disk file is about 2 X 106 bits. But if we want to allow the tree to overflow from the cylinder, or to be stored on several cylinders, we ca11 m&ify the proposed representation as follows.

In aildition to +he pair (I, k) stored in each node, we will mtintain in it the usual pointen to left and right

Page 5: Representation of binary trees on associative memories

h! Minsky. Representation ofbinory tmes 5

scms Since within every AS the nodes can still be ad- tree can be stored c- Q+ 6 single cylinder, and when each associatively, the pointers should be the ad- node has enough <: ry * ut uheil the proposed

an cell-addresses; they representation c3n be use it can speed up consider-

rably shorter than in the ably varir~s types of tree searches. this modifkation we can It shotid be pointed out again that this paper is

based upon a potential capability of rotating mem- ories, a capability which has not been realized yet; at

e close relatives of an arbitra- least ‘1 Jt on the commercial devices.

ration should be quite obvious and we will References

The rtive representation of binary trees, pro- I4

posed in this paper, has a limited scope of applications. 131 It is not suitable fcr cW.ain types of tree mod5 zations, and it is mainly appikable to the case where the whole

141

N. Minsky, Multi-route access on cylindet memories, Rot. Sixth Ann. Princeton Conf. of Inform. Sciences and Systems ! 1972). N. Minsky, Rotating storage devices as partially associative memories, Proc. FTX (1972). N. Miusky, Toward “Intelligent” Storage: Devices, ‘Jniv. of Minn., C’omp. Sci. Technical Report TR73-1 (Feb. 1973). D. Knuth, The Art of Computer Programming, V& 1.