university of illinois library At urbana-champaign Digitized by the Internet Archive in 2013 http://archive.org/details/generatingbinary888zaks 7ir, 777 7^r/ ^^ UIUCDCS-R-77-838 UILU-ENG 77 17^8 GENERATING BINARY TREES LEXICOGRAPHICALLY by S. Zaks August 1977 DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN URBANA, ILLINOIS 970 GENERATING BINARY TREES LEXICOGRAPHICALLY* by S. Zaks Department of Computer Science University of Illinois at Urbana-Champaign Urbana, Illinois 61801 August 1977 * This work was supported in part by the National Science Foundation under Grant Number MCS-73-03408. TABLE OF CONTENTS 1. Introduction 2. Definitions and Notations 3. Existing Algorithms 4. Trees and Integer Sequences; The Generating Algorithm 5. The Ranking Function 6. The Unranking Procedure 7. k-ary Trees 8. Summary Appendix: An example to the structures and sequences mentioned in the paper. I. INTRODUCTION We show a 1-1 correspondences among all the regular binary trees On with n internal nodes, all the 0,1-sequences x = {x.}, of n l's and n O's in which the total number of l's in each prefix {x.}-, [i <_ n) is at least as the total number of O's, all the integer sequences y = {y.K in which y,_ 2 we define a k-ary tree T as follows: either T is empty or it has a distinguished node r called its root that is connected to T, , T ? , ... , T. , each of which is a k-ary tree. For k = 2 we write T. and T R instead of T, and T ? , respectively, which will be referred to as left subtree and right subtree . The root of each non-empty T. for 1 <_ i <_ k is called a son of the root r, while r is its father . A vertex in a tree can be an internal node or an external node (also called a leaf ). A regular k-ary tree is a non-empty k-ary tree with each internal node having k sons. We denote by |T| the number of vertices of a tree T. We denote T(k,n ) = {all the regular k-ary trees with n internal nodes}. t(k,n) will be the number of elements in T(k,n). We define B = T(2,n) and b = t(2,n). 2.3 There is a well -known 1-1 correspondence between B and all the binary trees with n vertices: From a tree T e B remove all the leaves and the edges n incident with them. We get a binary tree with n vertices, and this trans- formation establishes the 1-1 correspondence. (See [KN 1: p. 559] for this correspondence, and [TR 1: p. 3] for an extension for k-ary trees). 2.4 We explain first what we mean by a "lexicographic order" of trees. The following definition is used in [KN 1: 2.3.1, ex. 25], [KNO: p. 113] and the first few sections of [TR 1]: Definition 2.5 : Given two k-ary trees T and T', we say that T < T' if (1) |T| < |T'|. or (2) |T| = |T' | > and for some 1 <_ i <_ k we have (a) T. = T. for j = 1 , 2, ... , i-1, and (b) t, < t: (See [TR 1: p. 16]). This defines a linear order in T(k,n). See Appendix for an example. 2.6 Unfortunately, no algorithm is known yet which generates those trees 1n order using this definition. In [KNO] and [TR 1] we have the ranking func- tion and unranking procedure .which may be used in an indirect way to generate the trees lexicographically (given a tree, apply the ranking function to find its position, then apply the unranking procedure to build the tree that occupies the next position). 2.7 We define now another "lexicographic order" of trees. As will be shown later, all the existing algorithms which (directly ) generate trees in "lexicographic order" are using this definition. Definition 2.8 : Given two k-ary trees T and T', we say that T < V if (1 ) T is empty, or (2) T is not empty, and for some i, 1 <_ i <_ k, we have (a) T, = T. for j = 1 , 2, . .. , i-1, and (b) T. s.t. y-i < y? < • • • < y < 2n and y. >_ 2i for i = 1 , 2, . . . , n. n (4) All the interger sequences z = {z,-}-i. s.t. < z, < z« < ... < z and z . <_ 2i - 1 for i = 1 , 2, . > . , n. Proof : (1) e (2) See Theorem 4.2. (2) e (3) 2n With a 0,1-sequence x = {x.}, , we associate a corresponding sequence n n {y.}, as explained in 4.1. Suppose x satisfies (2). If for some £, 1 <_ £ <_ n, y < 2£, then among x-, , x 2 , ... , x ?0-i there are at least £ O's, which violates the dominat- ing property of x. Hence y. >_ 2i for i = 1, 2, ... , n. Conversely, assume x doesn't satisfy (2). It it doesn't have n O's its corresponding y(x) doesn't satisfy (3). If it has n l's and n O's but doesn't have the dominating property, then for some £, 1 <_ z <_ 2n, the num- z ber t of O's in a prefix {x-K is more than the number I - t of l's, or i < 2t. Hence the position y. of the t-th staisfies y. <_ £ < 2t , hence y doesn't satisfy (3). It is clear that different sequences x and x' correspond to different sequences y and y', respectively, and this completes the proof. (3) = (4) Left to the reader. □ n 4.7 We define the lexicographic order for sequences as usual: Let u = {u^ }, n and v = {v.},. We say that u < v if there exist an index £, 1 <_ l <_ n, s.t. u. = v. for j = 1, 2, ... , £-1 and u < v . J J J6 X. The following observation is essential for our work: Theorem 4.8 : Let T and T' be two regular binary trees with n internal nodes, and let the corresponding sequences x, y, z and x', y', z' be as defined above. The following are eauivalent: (1) T < T' (definition 2.8) (2) x < x' (3) y < y' (4) z > z' (5) T < T' according to Ruskey-Hu's level sequence (see 3.1) (6) T < T' according to Trojanowski 's permutation (see 3.2) Proof: (2) ~ (3) ~ (4) Immediately from the definition of y and z (4.1). (1) ~ (2) T < T' iff the i vertex visited is a leaf in T but is an internal node in T', while the first i - 1 vertices are the same, for some i, 1 < i < 2n. This happens iff x. = x. for i = 1 , 2, . . . , £-1 and x = < 1 = x X/ X/ for some i as above, which happens iff x < x 1 . (2) ~ (5) x < x' iff for some i, !<£<2n, x i = x^ for i = 1 ,2, . . . , £-1 , and x £ = 0<1 = x . Let us look at those parts of T and T', corresponding to the first i - 1 nodes traversed in preorder. Those parts must be isomorphic, otherwise we could not have (x-j , .. . , x £ _ 1 )=(x* .... ,x^-,), by the equivalence (1)^(2). Hence, x - index (z) + 1. 5.2 To determine the ranking function we define the doubly indexed sequence a. . , « j * i-l : 1 >j a 1.1-l ■ ' for all i , i,o ■ b i-i?rfi 1 i fora11 ' ■ a. . = a. .,, + a. , . ■, otherwise . 1 1 2 3 4 5 6 7 1 1 2 1 5 3 1 14 9 4 1 42 28 14 5 1 132 90 48 20 6 1 429 297 165 75 27 7 1 1430 1001 572 275 110 35 8 1 The Sequence a- • > »J Figure 3 13 n 5.3 Given a sequence z = {z-h, let £ = initCz) denote the largest i s.t. n-1 z-j= i (note that z-j=l , so init(z) >_ 1). Let z = {z^ 1 be the sequence built from z by deleting z and setting z. + z. for j < £, z. «-z.., - 2 for ~ J J J Jt" i j > £. The following theorem is the key to the ranking algorithm: Theorem 5.4 : The following definition of the function index(z) assigns to a feasible sequence z = {z.}? its position in the lexicographic ordering of all these sequences: [ 1 if £ = n index(z) = / \ a n,£ + index(z) if a j n Proof : It is clear that index(z) = [number of feasible sequences z s.t. init(z) > £ + 1] + [position of z among all those feasible sequences z for which init(z) = £J. We show that the first term in this sum equals a „ and that the second one n n,£ is index(z~) (it is clear that if £ = n then index(z)=l - see step 1 in Algorithm 4.13). . =0: a_ « = :-rr- \ n n )'' s the number of sequences that begin - _L 'n,0 " n+1 with 1, which is all our sequences. For i = n-l: a , = 1 and there is M n,n-l really only one sequence z s.t. init(z) >_ i + 1 = n, namely {1, 2, ... , n}. For any other i the sequences z with init(z) _> i + 1 are partitioned into those for which init(z) > i + 1 and those for which init(z) = z + 1, and this is taken case by the relation a „ = a „,, + a , „ , .. , .. . J n s z n,£+l n-l,fc-l. We leave the rest of the induction details to the reader. Second term All the sequences z s.t. init(z) = £ corresponds to a q,1- sequence x = 11 . . . Qo^. . . .The sequence z as described above is exactly the £ 2n-£ 14 sequence that we get from x by omitting the first 10 patterns from the left (encircled above). So the position of z among all the sequences z with init(z) = i is exactly index(z). D Example 5.5 : Given the tree in Figure 2, we have: index(l,2,3,4,8,10,ll,14) = a g 4 + index(l ,2,3,6,8,9,12) index(l,2,3,6,8,9,12) = a 7 3 + index(T ,2,4,6,7,10) index(l,2,4,6,7,10) = a 6 2 + index ( 1 > 2 »4,5,8) index(l,2,4,5,8) = a 5 2 + index O > 2 > 3 > 6 ) index(l,2,3,6) = a 4 3 + index(l,2,4) index(l,2,4) = a 3 2 + index n.2) index(l,2) = 1 so index(l,2,3,4,8,10,ll,14) = a Q ^ + a ? ^ + a e ^ + a 5>2 + a 4>3 + a 3)2 + 1 = 110 + 75 + 48 + 14 + 1 + 1 + 1 = 250. Thus Index(T)=b 8 - 250 + 1 = 1181. 5.6 The solution to the recurrence relation for a. • is a = j±2_/2i-j\ d i,j 2i-j li-j-lj (See [RH] for an analytic approach, or apply the technique in [YY: problem 83] for a combinatorial approach , which is also found in [WH] ) . 15 VI. THE UNRANKING PROCEDURE 6.1 Given a number i, 1 <_ i £ b , we show in this section how to find the regular binary tree T with n internal vertices s.t. Index(T) = i. As explained in 5.1, it is enough if we know how to do it for a z sequence. 6.2 The algorithm we are presenting follows immediately from the way we calculated index(z) using Theorem 5.4, so we shall skip the proof of it here. We first bring an example: Example 6.3 : To find T e EL s.t. Index(T) = 1181, we note that it is sufficient to find the appropriate z sequence for which index(Z) = b g - Index(T) + 1 = 250. By Theorem 5.4 we know that 250 = a Q + index(z) o, x, As a consequence from Section 5, we choose i s.t. a 8,£ < 250 ^ a 8,£-l Here we choose i = 4, and get 250 = 110 + index(z), or index(z) = 90, where z is a sequence corresponding to a tree T e B-,. Next we get 90 = a-, 3 + index(z), or index(z) = 15, and so on. At the end we have 250 = a Q A + a 7 - + a c 9 + a c + a, ^ + a- + a , . 8,4 7,3 6,2 5,2 4,3 3,2 2,1 From this decomposition of 250, we reconstruct the sequence z: The last 1 tells us that at the \jery end (of computing index(z)) we had {1,2}. Then a 3 2 tells us that a step before we had the sequence {l,2,t}, and that after omitting the 2 and setting t «- t - 2 we get {1,2}. So we have {1,2,4}. Recurring in this manner, we get: a^ 3 -y 1 ,2,3,6 a 5,2 * 1 ' 2 ' 4 ' 5 ' 8 16 a 6,2 "* 1 » 2 ' 4 ' 6 ' 7 »" | a ?j3 + 1,2,3,6,8,9,12 a 8)4 - z = {1,2,3,4,8,10,11,14} and now we build the tree (see Figure 2, and compare this example with Example 5.5). 6.4 We bring here the algorithm that converts a number to its corresponding z sequence. We are given n and t, and look for a sequence z = {z.-}-| (0 < z, < z« < ... < z , z. <_ 2i - 1 for i = 1, 2, ... , n) s.t. index (z) = t : Algorithm 6.5 : Step 1 : A -*- t, j «- n Step 2 : Find £. s.t. a. < A <_ a. J J)^ J » * .r - 1 Step 3 : A + t - a J.A. j «- j - 1 if A > then go to Step 2. n Step 4 : We have now t = 2a. J=J J»*. Step 5 : Set z *■ {1,2, ... , j n } m * j + ] ' s * £ m Step 6 : Change z as follows z i+l * z t + 2 z s* s 1 < s i = m , m- 1 , Step 7 : m ■«- m + 1 , s if m z' * See [DM] for a related problem . 19 (4) T < T' according to Ruskey-Hu's level sequence as extended to k-ary trees ( see 3.1 ) . (5) T < T' according to Trojanowski 's permutation as extended to k-ary tree ( see 3.2). Corollary 7.9 : In order to generate (lexicographically) all the regular k-ary trees with n internal nodes, it is sufficient to generate all the sequences x(lexicographically) or z(antilexicographically) of Theorem 7.6. The note after corollary 4.9, and the discussion in 4.10 - 4.11 (replacing 100 and 10 patterns with 100 . . . y and 100 • --O, patterns respect- k ~~k^T ively), should be applied here as well. Algorithm 7.10 : (Generating the z sequences lexicographically): Exactly as algorithm 4.13, with one change. In step (2) replace the upper bound 2j - 1 by kj- (k-1). 7.11 All the discussion in Section 4, following algorithm 4.13, applies here. 7.12 : As for the ranking function and unranking procedure we were not able to extend the algorithms from the binary case to the k-ary case; yet, as follows from Theorem 7.8, we can use the appropriate algorithms in [TR 1, 2] for these tasks. It should be noted that generating the k-ary trees by the z sequences, is simpler than that of level numbers ([RH]) or permutations ([KM 1], [TR 1, 2], [KN0]). 7.13 : Two methods for ranking and unranking k-ary trees- one of which is presented among other combinatorial objects ([ZR]), and the other performs these tasks in an order different from the two definitions, as discussed in Section 2 ([ZA])- are a subject of future work. 20 VIII. SUMMARY 8.1 After discussing the term "lexicographic order of trees," we have seen algorithms that generate all the regular binary trees with n internal vertices lexicographic order, find the position of a given tree in this ordering and find a tree given its position. For regular k-ary trees we treated the generating algorithm. 8.2 As explained in 2.2, there is a simple 1 - 1 correspondence between all the regular k-ary trees with n internal vertices and all the k-ary trees with n vertices, so the results mentioned in 8.1 can be extended to this new class. 8.3 If we take any tree with n edges and travese it in the way shown in Figure 5, (see [BN]),when 1 means "going down" and means "going up" we get a 0,1-sequence 110110001010 Figure 5 which have the dominating property - the number of "going down" must be at least as that of "going up," otherwise we will get above the root! Consequently, our algorithms can be used to generate, rank and unrank all the trees with n edges. See Appendix for an example. 8.4 In finding the ranking function we defined the sequence a- • and then proved that a is the number of feasible sequences z s.t.init(z) >_ n + 1 . We could as well choose the alternative way: define a. . by this last property, and then prove that a. . satisfies the relations by which we defined it. 21 8.5 The following remark concerns the difference between the two ordering of trees (definitions 2.5 and 2.8): Given 2 trees T and T'^to determine whether T < T, we scan both trees in preorder. Using definition 2.5, we compare the sizes of the subtrees rooted at the concurrent nodes; in other words, we use a global information concerning those nodes. On the other hand, using definition 2.8 we compare the characters of the concurrent nodes (whether they are internal nodes or leaves); in other words, we use local information concerning those nodes. ACKNOWLEDGE I wish to thank Professor C. L. Liu for many helpful suggestions while working on this paper. 22 APPENDIX We show here all the 14 regular binary trees with 4 internal nodes in lexicographic order. To each of them we assign the structures and sequences introduced in the paper, as follows: (1) The x sequence (0, 1-sequence) (2) The y sequence (3) The z sequence (4) Ruskey and Hu's level sequence (5) Trojanowski 's permutation (note that reading only the internal vertices in Trojanowski 's labeling in preorder (Root-Left-Right) gives us again the corresponding z sequence, and the reasoning for this is left to the reader. ) (6) The corresponding binary tree with 4 vertices. (7) The corresponding tree with 4 edges. (8) The index while being ordered according to definition 2.5. 23 o o o m CO «=* r*s CO CO r- C\J CM CO CM in o o CO 00 co in i— CM CM ro cr> ro 00 co in CM <^ ro o o r>. oo CO CO co m ro o o o o co co in r«» ro «3- i— CM co CM CM o o o o r^. co in wo co «d- r— CM •3- CO CM CO CD O •r- 10 4-> S- > •> 1— *— ** t mm 00 >> 03 . S- E CM na s- I E O) e •r- -M o CO e •r- •r- --M s- •r- ns ** E p— ► •!— Z3 _E 4- CD+-> i+^ i- s~ n3 CD e >• cu o CD 3 O" 0J 00 CO >* x cu > ■— ^Z CD co > 3 a> or: _j C7>-^ o> C CO E •<- s •p- co O r— S- E CD at to JQ > »n fO «3 O _J i- s- 1— 1— — * S- +-> a> s- *> o ■o cd .e e s- TJ +-> i«£ o S- 3 ai O E "O s- e ^ e a_ •— t ■> — ' n3 o co +J ai en CD -o E --- LxJ •r- in -a • «3- s- CM o -E o e +-> o o •r- ■=C -r- 2 — +-> •r— co X E ai a> t- cd ID lj- s- E (— i-h Q 24 *s ^ o o o in oo n— >.^ CT» 5 *C ^*\ r— **■ r^ OO ^^VT" *3- -,*£r o ^«wr x, ^* r— CM tO *3" P*» j fT^^ ^~ ^^< o i— CO CVJ CO to uo to CM OO ^^ o o-> -c^ _ o —J^**^^ T— M ^* ^^-^ ^r r— to CO r— ■ m ^J^*^^ 00 S •C >^ ^/^ o ^ r^ «3" ^So^ _/^° * to - X , CTi ^\^^^- ^■s. *S^ CM IX) «3- •C ^^^.^ r* r>» \ r o ^, ^»n» 1^ CVJ ^^^^^ LO LO cm ^ro CM OO » sCi X r— P^^^ r^» _^-» jr**~ X o r^ oo CVJ ^r ^"^»C0 CO *\_ CVJ ^^vfo "^ \r> ^>» CM ^^ CM oo ^r"^- oo /^^-^ o y -X\. 1— to CO CVJ >/Lo ^<-^ to ^. \, X. o i— oo CVJ ^\ «3" » t— CM CM ^N. CM r— CO* OO ^<< s o CT» y <7 \ o i— CO CVJ •— ' ^^^v -*^** ^~ V >N^ ^x ^v r— CM ^^0^r j" «^- ^» ro CM OO CO 0) o • ^ tO 4-> #4 cd s- •r- o O) CD CT>-i<: to +-> s~ > -SZ cn c to CD en h- +-> C -r- 2 CD C7) c: -— ^ r— • T— •r- to O TO C ^-» i- 00 >> fO 2 CD i— S- £Z LU •r- LO ■o • s- c <_> CD CD ro "° rv*l S- CM ro s_ to C -Q > -r-i ^d" j_ CVJ o c cd CD CD 3 CD ra ro O O (J c •1- +J CD to O QJ nr 3 _l s- $_ JC U C o o CO <= S- <1J O) CD (J O" (—1——^ +-> U O ■=c •-- 1— 1 l— u o C SZ oS CD S- 4-> • r— < -r- V +J s- • f— c CD CD 00 CD i- •> O s ■*-> •r - 03 <3- >>+■> Ol 13 3 >> T3 CD -C C •r— X c ^~ s- s- O" cr cr CD r— s_ -a 4-> i^ to X c O) 1- 3 -c f0 to to to to > CJ O CTJ CD ■O M- C CD CD i- 'r- 1 1 1 3 CD i- C i^ c t- C 0) i—i Q o: s CO «d- X >> N or _i Q_ i— i — * ro r- H-i a 25 -<* _^--%i CX> ^cr> CT> _^-* o ^v^^-^"^ -^^ co r»v CM C^s-^^Ln ^"Vo ^ • ■ f^ co ^C ^^ V o CNJ CO «* «^ ^-w^ * X. j m r— ■— *3- «3- cnj >^ m -id ^ w ^N^ ^W" — r— co cn^~-m CO >► ? «* <^< •v o o UD 00 <^c i vl ^N^^^^ ^^^-* o oo r«. CO *r 15. <^ ^N^^^^ CM ^Q X o CM LO i— -et CO CO CO - y< • o ^^-» en en X^^oo CO / y o r- oo CM ^^ S ./ o CO CO CM *C ^> i^^ - ^>^— -* < o CNJ LO CM ~ >r — ^° cm ^^^.^^ cn ^^: X ^_ 1— ^1- CO CO ^^"^ •> •j- to 0) u ■r* to +-> »> 3 ^: to cu +-> 7 t— +-> C-r- S C7> cn Z "s r— •r- •r- tO O T3 E *—» O >} fO 3 cu i— S- C LU •i- LO 3 • s- c o CU CU fO -a • -J CO s- co c .a > T-j «* S- i— 5 E CU a> 3 CU ro fO o o j: 1- +J CU oo CD cu a> ZT. 3 _J s_ S- -C u c ■>D CO c i. cu U o o O" h- h--—» -(-> o o C- I— I l— a c c c oS CU S- -M •r— < -r- - _> S- •^ a; cu cu CO cu s- •> o s +* ™ <0 «d" >>4-> 3 3 3 >> •d air c •r" <; r— S- j_ a- o- o- CU i— i. -a +-> ^ to X C >- 3 .c fO CD cu cu cu ^ cu O S- 3 cu CU T- 3 - CT>+-> C > to to to to > CU O C "O cu -O 4- = L) 0) •.- • r— i 1 1 3 CU S- C S*£ C S- c cu -o a: 2 OQ «fr X >> N or _i Q_ t— t ro I— l-H Q 26 REFERENCES [BM] N. G. DeBruijn and B. J. M. Morselt, "A Note on Plane Trees," Journal of Combinaotiral Theory 2, 27-34 (1967). [DM] A. Dvoretzky and T. Motzkin, "A Problem of Arrangements," Duke Math. Journal 14 (1947), 305-313. [GA] M. Gardner, "Mathematical Games": Catalan Numbers, Scientific American , June 1976, pp. 120-122. [GN] B. N. Gnedenko, The Theory of Probability , Chelsea Publishing Company, N.Y., N.Y., 1962. [KL] D. A. Klarner, "Correspondences Between Plane Trees and Binary Sequences," Journal of Combinatorial Theory 9, 401-411 (1970) [KNO] Gary D. Knott, "A Numbering System for Binary Trees," Communications of the ACM , Vol. 20, Number 2, February 1977. [KN1] Donald E. Knuth, The Art of Computer Programming Vol. 1: Fundamental Algorithms, Addi son-Wesley, Reading, MA 1968. [KN3] Donald E. Knuth, The Art of Computer Programming Vol. 3: Sorting and Searching, Addi son-Wesley, Reading, MA 1973. [LI1] C. L. Liu, Topics in Combinatorial Mathematics Mathematical Association of America, 1972. [LI2] C. L. Liu, Elements of Discrete Mathematics McGraw-Hill, 1977. [RH] F. Ruskey and T. C. Hu, "Generating Binary Trees Lexicographically," SIAM Journal on Computing , to appear. [TR1] Anthony E. Trojanowski, "On the Ordering, Enumeration and Ranking of k-ary Trees," Tech. Report UIUCDCS-R-77-850, Department of Computer Science, University of Illinois at Urbana-Champaign, February, 1977. [TR2] Anthony E. Trojanowski, "Ranking and Listing Algorithms for k-ary Trees," SIAM Journal on Computing , to appear. [WH] W. A. Whitworth, "Arrangements of m Things of One Sort and m Things of Another Sort Under Certain Conditions of Priority," Messenger of Math. 8 (1878), 105-114. [YY] A. M. Yaglom and I. M. Yaglom, Challenging Mathematical Problems with Elementary Solutions Vol. 1: Combinatorial Analysis and Probability Theory | Hoi den-Day, 1964. [ZA] S. Zaks, "Generating k-ary Trees Lexicographically," to appear. [ZR] S. Zaks and D. Richards, "Generating Trees and Other Combinatorial Objects Lexicographically," to appear. .LIOGRAPHIC DATA EET 1. Report No. UIUCDCS-R-77-888 2. 3. Recipient's Accession No. "itle and Subtitle 5. Report Date October, 1977 6. uthor(s) S. Zaks 8. Performing Organization Rept. No. "erforming Organization Name and Address Department of Computer Science 10. Project/Task/Work Unit No. University of Illinois at Urbana-Champaign Urbana, IL 61801 11. Contract /Grant No. MCS-73-03408 Sponsoring Organization Name and Address National Science Foundation 13. Type of Report & Period Covered Washington, DC 14. Supplementary Notes Abstracts We show a one-one correspondence between all the regular binary trees with n internal nodes and certain integer sequences, an algorithm for generating these trees lexicographically, and the ranking function and the corresponding unranking procedure. We then extend the generating algorithm to k-ary trees. Relations to existing algorithms are discussed. Key Words and Document Analysis. 17a. Descriptors k-ary tree, ordered tree, lexicographic order , ranking, and unranking Identifiers/Open-Ended Terms COSATI Field/Group Availability Statement 19. Security Class (This Report) UNCLASSIFIED 21. No. of Pages 20. Security Class (This Page UNCLASSIFIED 22. Price * NT IS- 35 (10-70) USCOMM-DC 40329-P71 J M 2 5 1978 OCT 2" MO W ^OVND ( UNIVERSITY OF ILLINOIS-URBAN A 510 84 IL6R no COO? no 886 893(1977 Generating binary trees lexicographical! 3 0112 088403594 B8 r^LaaV HH ■M H ■I la ML n I IffigH ■ US ■ HLaTflHf DBF