Method for Developing Combinatorial Generation Algorithms Based on AND/OR Trees and Its Application

: In this paper, we study the problem of developing new combinatorial generation algorithms. The main purpose of our research is to derive and improve general methods for developing combinatorial generation algorithms. We present basic general methods for solving this task and consider one of these methods, which is based on AND/OR trees. This method is extended by using the mathematical apparatus of the theory of generating functions since it is one of the basic approaches in combinatorics (we propose to use the method of compositae for obtaining explicit expression of the coefﬁcients of generating functions). As a result, we also apply this method and develop new ranking and unranking algorithms for the following combinatorial sets: permutations, permutations with ascents, combinations, Dyck paths with return steps, labeled Dyck paths with ascents on return steps. For each of them, we construct an AND/OR tree structure, ﬁnd a bijection between the elements of the combinatorial set and the set of variants of the AND/OR tree, and develop algorithms for ranking and unranking the variants of the AND/OR tree.


Introduction
Many information objects have a hierarchical or recursive structure.In this case, a tree structure is a convenient form of representing such information objects.This allows us to describe an information object by a combinatorial set and apply combinatorial generation algorithms for it.A combinatorial set is a finite set whose elements have some structure and there is an algorithm for constructing the elements of this set.The elements of combinatorial sets (combinatorial objects) like combinations, permutations, partitions, compositions, paths, graphs, trees, etc. play an important role in mathematics and computer science.
Knuth [1] gives a detailed overview of the formation and development of the direction related to designing combinatorial algorithms.In this overview, special attention is paid to the procedure for traversing all possible elements of a given combinatorial set.This problem can be studied as enumerating, listing, and generating elements of a given combinatorial set.On the other hand, Ruskey [2] introduces the concept of combinatorial generation and distinguishes the following four tasks in this area: 1. Listing: generating elements of a given combinatorial set sequentially; 2. Ranking: ranking (numbering) elements of a given combinatorial set; 3. Unranking: generating elements of a given combinatorial set in accordance with their ranks; 4. Random selection: generating elements of a given combinatorial set in random order.
There are several basic general methods for developing combinatorial generation algorithms: • backtracking [3,4]: this method is used for exhaustive generation and based on constructing a state space tree for a combinatorial set and obtaining feasible solutions on level l of the tree that are built up from partial solutions on level l − 1; • ECO-method [5][6][7][8][9][10][11][12][13]: this method is used for exhaustive generation and based on producing a set of new objects of size n + 1, using a succession rule and starting from an object of size n; • Flajolet's method [14][15][16][17][18][19][20]: this method can be applied for listing, ranking, and unranking a large family of unlabeled and labeled admissible combinatorial classes that can be obtained by using admissible combinatorial operators (disjoint union, Cartesian unlabeled product, labeled product, sequence, set, cycle, powerset, substitution, etc.); • Ryabko's method [21][22][23]: this method can be applied for ranking and unranking combinatorial objects presented in the form of a word, this method operates with word prefixes and uses the divide-and-conquer paradigm; • Kruchinin's method [24]: this method can be applied for listing, ranking, and unranking a combinatorial set represented in the form of an AND/OR tree structure for which the total number of its variants is equal to the value of the cardinality function of the combinatorial set.
Each of these methods claims the universality of its application in the development of new combinatorial generation algorithms.The study of these methods have shown the following results connected with their limitations and requirements [25]: the main characteristic, which is necessary for developing combinatorial generation algorithms, is the cardinality function of a combinatorial set; • some methods (backtracking and ECO-method) are aimed only at the development of listing algorithms; • there are restrictions on applying some methods (ECO-method and Flajolet's method) for combinatorial sets that are described by more than one parameter; • most methods require the representation of a combinatorial object in a special form (for example, as a word, a sequence, a specification, or an AND/OR tree), but this is not always a trivial task and requires additional research; • there are requirements for additional information describing a combinatorial set.
Also, there are many combinatorial generation algorithms that are based on features of the applied combinatorial set or that are based on simple counting techniques (for example, see [26][27][28]).Therefore, the methods used for developing such algorithms cannot be universal (they cannot be applied to develop new combinatorial generation algorithms for other combinatorial sets).
Thus, there is no universal general method that can be applied for developing new combinatorial generation algorithms.The main purpose of our research is to derive and improve general methods for developing combinatorial generation algorithms.In this paper, we consider and extend Kruchinin's method for developing combinatorial generation algorithms, which is based on the use of AND/OR trees.This method:

•
allows us to develop all types of combinatorial generation algorithms (listing, ranking, and unranking algorithms); • has no restrictions on the number of parameters that describe combinatorial sets (this allows us to consider complex discrete structures); • requires only an expression of the cardinality function as additional information describing a combinatorial set.
However, to apply this method, it is necessary to know an expression of the cardinality function of a combinatorial set that must satisfy the following conditions: • the expression of the cardinality function can contain only positive integers (let N denotes the set of natural numbers); • the expression of the cardinality function can contain only such algebraic operations as addition (which is denoted by +) and multiplication (which is denoted by ×); • the cardinality function may be recursively defined in terms of itself (let R denotes a primitive recursive function).
If an expression of the cardinality function f of a combinatorial set A satisfies the conditions presented above, then we will say that f belongs to the algebra {N, +, ×, R}.The requirement of the cardinality function that belongs to the algebra {N, +, ×, R} is the main restriction of Kruchinin's method.If the required form of the cardinality function is unknown for a given combinatorial set, then this method cannot be applied to develop combinatorial generation algorithms.
The organization of this paper is as follows.Section 2 of this paper is devoted to a brief description of the main theoretical points of the used method for developing combinatorial generation algorithms.In Section 3, our modification of the original method is presented.The modification is based on applying the method of compositae from the theory of generating functions.To confirm the effectiveness of using the proposed modification of the original method, we develop new ranking and unranking algorithms for the following combinatorial sets: permutations, permutations with ascents, combinations, Dyck paths with return steps, labeled Dyck paths with ascents on return steps.The obtained results are shown in Section 4.

Method for Developing Combinatorial Generation Algorithms Based on AND/OR Trees
Kruchinin [24] introduces a method for developing combinatorial generation algorithms, which is based on the use of AND/OR trees.This method is based on representing a combinatorial set in the form of an AND/OR tree structure for which the total number of its variants is equal to the value of the cardinality function of the combinatorial set.Using an AND/OR tree structure, it is possible to develop listing, ranking, and unranking algorithms for a given combinatorial set.The effectiveness of this method is shown in the development of combinatorial generation algorithms for a large number of combinatorial sets (for example, permutations, combinations, partitions, compositions, the Fibonacci numbers, the Catalan numbers, the Stirling numbers, tree structures, and formal languages).
An AND/OR tree is a tree structure that contains nodes of two types: AND nodes and OR nodes.Figure 1 shows a way for representing nodes in an AND/OR tree.A variant of an AND/OR tree is a tree structure obtained by removing all edges except one for each OR node. Figure 2 shows an example of an AND/OR tree and all its variants.If we know the cardinality function f of a combinatorial set A that belongs to the algebra {N, +, ×, R}, then we can construct an AND/OR tree structure for which the total number of its variants is equal to the value of the cardinality function (Theorems 1-3 and Corollaries 1-2 in [24].To do this, it is necessary to perform the following steps for the cardinality function f :

… OR node
• each addition + from f must be represented as an OR node of the AND/OR tree where all terms are represented as sons of the OR node; • each multiplication × from f must be represented as an AND node of the AND/OR tree where all factors are represented as sons of the AND node; • each coefficient k ∈ N from f must be represented as an OR node of the AND/OR where all sons are leaves and their number is equal to k; • each recursive operation from f must be represented as recursion in the AND/OR tree (it will be denoted by a node with a triangle).
Thus, the method for developing combinatorial generation algorithms based on AND/OR trees can be written in the following form: Input: The cardinality function f of a combinatorial set A that belongs to the algebra {N, +, ×, R}.

Output:
The combinatorial generation algorithms The rank r of a combinatorial object a represented as a variant v of the corresponding AND/OR tree D is determined by the value of l(z) for the node z of the variant v that is the root of the AND/OR tree D.
The value of l(z) corresponds to a number for the node z that satisfies the condition 0 ≤ l(z) < w(z), where w(z) shows the number of variants in the subtree of the node z.
The value of l(z) is calculated according to the following rules: 1.If a node z of the variant v is a leaf of the AND/OR tree D, then l(z) = 0; 2. If a node z of the variant v is an AND node of the AND/OR tree D, then where n is equal to the number of sons for the node z and s i is the i-th son of the node z; 3.If a node z of the variant v is an OR node of the AND/OR tree D, then where k is the position of the son s (z) k of the node z chosen in the variant v among all its sons in the AND/OR tree D.
For the general case, the rules for ranking the variants of an AND/OR tree was formalized and presented as Algorithm 1.To run this algorithm, it is necessary to start from the command RankVariant(root, v, D), where root is the root of an AND/OR tree D.   The unranking algorithm UnrankVariant(r) performs the inverse operation to the algorithm RankVariant(v).That is, the algorithm UnrankVariant(r) allows us to associate each rank r ∈ N |W(D)| with a unique variant v of the AND/OR tree D. The algorithm UnrankVariant(r) is based on the inverse actions to the calculations used in the algorithm RankVariant(v).For the general case, the rules for unranking the variants of an AND/OR tree were formalized and presented as Algorithm 2.

Modification of the Method for Developing Combinatorial Generation Algorithms
The use of the method for developing combinatorial generation algorithms based on AND/OR trees has the following two restrictions: Firstly, if we do not know the cardinality function of a combinatorial set that belongs to the algebra {N, +, ×, R}, then we cannot construct the corresponding AND/OR tree for the combinatorial set.Therefore, this method for developing combinatorial generation algorithms cannot be applied without an AND/OR tree structure.
If an AND/OR tree structure is constructed for a combinatorial set, then there is a new problem.This problem is associated with finding a bijection between the elements of the combinatorial set and the set of variants of the AND/OR tree (that is, each variant v of an AND/OR tree D constructed for the combinatorial set A must correspond to a specific combinatorial object a ∈ A, and vice versa).A general approach for solving this problem does not exist, since each combinatorial set has its own and completely unique characteristics.We propose to use the following recommendation: it is necessary to consider the changes that occur in the structure of combinatorial objects when moving from one node of an AND/OR tree to another (considering the type of a node, the label of a node and the selected sons) and show these changes in the bijection.
For solving the first problem, we propose to apply the theory of generating functions, since it is one of the basic approaches in modern combinatorics and generating functions are already known for many combinatorial sets.An ordinary generating function of a sequence (a n ) n≥0 is the following formal power series [29]: For the coefficients of the powers of generating functions, the notion of the compositae of a generating function was introduced in [30].The composita of an ordinary generating function is the following function with two variables G ∆ (n, k), which is a coefficients function of the k-th power of the generating function G(t): This mathematical apparatus provides such operations on compositae as shift, addition, multiplication, composition, reciprocation, and compositional inversion of generating functions.Such operations on compositae allow us to obtain explicit expressions for the coefficients of generating functions.To obtain an explicit expression for the coefficients of a generating function using the method of compositae, it is necessary to decompose the given generating function into functions for that the compositae are known and apply the corresponding operations to them.More detailed information about the compositae can be found in [30][31][32][33][34][35].
If for a given combinatorial set A we consider its subset A n ⊂ A, which contains only the combinatorial objects of size n, then the cardinality function f (n) = |A n | of this combinatorial set A n can be described by a generating function Hence, to obtain an expression for the cardinality function f (n) of a combinatorial set for which a generating function is known, we can apply the method of compositae for obtaining an explicit expression of the coefficients f n of the generating function [25].Moreover, the operations on compositae can be extended to the case of multivariate generating functions.This makes it possible to obtain expressions for the cardinality functions of combinatorial sets that are described by more than one parameter.
The obtained method for developing combinatorial generation algorithms with its modification is presented as a sequence of the following steps: 1.If the cardinality function f of a combinatorial set A that belongs to the algebra {N, +, ×, R} is known, then go to Step 4. 2. If the generating function F for the values of the cardinality function f of the combinatorial set A is known, then apply the method of compositae for obtaining an explicit expression of the coefficients of the generating function.Otherwise, the method for developing combinatorial generation algorithms cannot be applied.3.If the cardinality function f of the combinatorial set A that belongs to the algebra {N, +, ×, R} is obtained, then go to Step 4. Otherwise, the method for developing combinatorial generation algorithms cannot be applied.4. Using the cardinality function f of the combinatorial set A, construct the corresponding AND/OR tree D. The combination of the algorithms defined in the last two steps of the modified method forms a bijection A ↔ N and represents the combinatorial generation algorithms Rank(a) : A → N for ranking and Unrank(r) : N → A for unranking elements of the combinatorial set A.

Application of the Modification of the Method for Developing Combinatorial Generation Algorithms
Next, we consider the process of developing ranking and unranking algorithms using the obtained method for developing combinatorial generation algorithms.We describe a combinatorial set, construct an AND/OR tree, find a bijection between the elements of the combinatorial set and the set of variants of the AND/OR tree, and develop algorithms for ranking and unranking the variants.

Combinatorial Set
Let us consider the following combinatorial object: a labeled Dyck n-path with m ascents on return steps.A Dyck n-path is a lattice path in the plane which begins at (0, 0), ends at (2n, 0), and consists of steps (1, 1) called rises or up-steps and (1, −1) called falls or down-steps [36].A return step is a down-step at level 1 (a return to the ground level 0) [37].In a labeled Dyck n-path with m ascents on return steps, each down-step has its own label (a unique value from 1 to n).If we consider the sequence of labels of down-steps of a Dyck n-path starting from (0, 0), then it has exactly m ascents.
Figure 3 shows all possible variants of the considered labeled Dyck paths for n = 3 and m = 1.The total number of labeled Dyck n-paths with m ascents on return steps is defined by the elements of the Euler-Catalan number triangle (the sequence A316773 in [38]).That is, the cardinality function of this combinatorial set is equal to the Euler-Catalan numbers, which are denoted by EC m n [39].Applying the method of compositae for obtaining explicit expressions for the coefficients of generating functions, we have found a generating function and the following explicit formula [39]: where CT m n is the transposed Catalan triangle, C m n is the number of m-combinations of n elements, E m n is the Euler triangle, and P n is the number of permutations of n elements.

AND/OR Tree
Equation ( 1) belongs to the algebra {N, +, ×, R}, and there are the well-known formulas for the components of Equation ( 1), which also belong to the required algebra: • the elements of the transposed Catalan triangle (the sequence A033184 in [38]) show the number of Dyck n-paths with m return steps and can be calculated using the following recurrence [37]: • the number of m-combinations of n elements (the sequence A007318 in [38]) can be calculated using the following recurrence [40]: • the elements of the Euler triangle (the sequence A173018 in [38]) show the number of permutations of n elements with m ascents and can be calculated using the following recurrence [41]: • the number of permutations of n elements (the sequence A000142 in [38]) can be calculated using the following recurrence [40]: Since Equation ( 1) and all the formulas for its components belong to the algebra {N, +, ×, R}, we can construct the AND/OR tree structure for EC m n , which is presented in Figure 4.A bijection between the labeled Dyck n-paths with m ascents on return steps and the variants of the AND/OR tree is defined by the following rules: Next, we need to construct AND/OR tree structures for all the subtrees of the AND/OR tree for EC m n .We also need to find bijections between the variants of these AND/OR trees and the corresponding combinatorial objects.
Since Equation ( 2) belongs to the algebra {N, +, ×, R}, we can construct the AND/OR tree structure for CT m n , which is presented in Figure 5.A bijection between the Dyck n-paths with m return steps and the variants of the AND/OR tree is defined by the following rules: • if a Dyck n-path is not completely filled and it is at the ground level 0, then it is necessary to add an up-step; For a compact representation, we encode a Dyck n-path by a sequence a = (a 1 , . . ., a 2n ), where a i ='u' encodes an up-step and a i ='d' encodes a down-step.We also encode a variant of an AND/OR tree by a sequence v = (v 1 , v 2 , . ..) of the selected sons of the OR nodes in this tree (the left son corresponds to v i = 0 and the right son corresponds to v i = 1).An example of applying the obtained bijection for Dyck paths with return steps is presented in Table A1.
Since Equation (3) belongs to the algebra {N, +, ×, R}, we can construct the AND/OR tree structure for C m n , which is presented in Figure 6.A bijection between the m-combinations of n elements and the variants of the AND/OR tree is defined by the following rules:  For a compact representation, we encode an m-combination of n elements by a sequence a = (a 1 , . . ., a n ), where a i = 0 encodes that the i-th element is not selected and a i = 1 encodes that the i-th element is selected.We also encode a variant of an AND/OR tree by a sequence v = (v 1 , v 2 , . ..) of the selected sons of the OR nodes in this tree (the left son corresponds to v i = 0 and the right son corresponds to v i = 1).An example of applying the obtained bijection for combinations is presented in Table A2.
Since Equation ( 4) belongs to the algebra {N, +, ×, R}, we can construct the AND/OR tree structure for E m n , which is presented in Figure 7.A bijection between the permutations of n elements with m ascents and the variants of the AND/OR tree is defined by the following rules: • each selected left son of the OR node labeled E m n determines that the element n does not add an ascent in a permutation of n elements, and the selected son of the OR node labeled m + 1 determines the position of the element n in the permutation (there are exactly m + 1 possible positions); • each selected right son of the OR node labeled E m n determines that the element n adds an ascent in a permutation of n elements, and the selected son of the OR node labeled n − m determines the position of the element n in the permutation (there are exactly n − m possible positions); • if a leaf of the AND/OR tree is reached (when m = 0), then it is necessary to arrange all n elements in a permutation of n elements in decreasing order; • if a leaf of the AND/OR tree is reached (when m = n − 1), then it is necessary to arrange all n elements in a permutation of n elements in increasing order.For a compact representation, we encode a variant of an AND/OR tree by a sequence v = (v 1 , v 2 , . ..) of the selected sons of the OR nodes in this tree, where each v i is represented as a pair (v i,1 , v i,2 ).In this pair: v i,1 = 0 corresponds to the left son of the OR node labeled E m n and v i,2 determines the selected son of the OR node labeled m + 1; v i,1 = 1 corresponds to the right son of the OR node labeled E m n , v i,2 determines the selected son of the OR node labeled n − m.An example of applying the obtained bijection for permutations with ascents is presented in Table A3.
Since Equation ( 5) belongs to the algebra {N, +, ×, R}, we can construct the AND/OR tree structure for P n , which is presented in Figure 8.A bijection between the permutations of n elements and the variants of the AND/OR tree is defined by the following rules: • each selected son of the OR node labeled n determines the position of the element n in a permutation of n elements; • if a leaf of the AND/OR tree is reached (when n = 0), then it is necessary to form an empty permutation.For a compact representation, we encode a variant of an AND/OR tree by a sequence v = (v 1 , v 2 , . ..) of the selected sons of the OR nodes in this tree.An example of applying the obtained bijection for permutations is presented in Table A4.
We have constructed AND/OR trees for all the combinatorial sets presented in this paper.Hence, we can develop algorithms for ranking and unranking the variants of the AND/OR trees.

Ranking and Unranking Algorithms
Based on Algorithms 1 and 2, we can develop algorithms for ranking and unranking the variants of the constructed AND/OR trees for EC m n , CT m n , C m n , E m n , and P n .For the AND/OR tree for CT m n , which is presented in Figure 5, we develop an algorithm for ranking its variants (Algorithm 3) and an algorithm for unranking its variants (Algorithm 4).Combining the developed algorithms with the derived rules for the bijection, we get algorithms for ranking and unranking the combinatorial set of Dyck n-paths with m return steps.For the AND/OR tree for C m n , which is presented in Figure 6, we develop an algorithm for ranking its variants (Algorithm 5) and an algorithm for unranking its variants (Algorithm 6).Combining the developed algorithms with the derived rules for the bijection, we get algorithms for ranking and unranking the combinatorial set of m-combinations of n elements.
For the AND/OR tree for EC m n , which is presented in Figure 4, we develop an algorithm for ranking its variants (Algorithm 11) and an algorithm for unranking its variants (Algorithm 12).Combining the developed algorithms with the derived rules for the bijection, we get algorithms for ranking and unranking the combinatorial set of labeled Dyck n-paths with m ascents on return steps.Algorithm 11: An algorithm for ranking the variants of the AND/OR tree for EC m n .
In these algorithms, we use all the above mentioned algorithms for ranking and unranking the variants of the AND/OR trees for CT m n , C m n , E m n , and P n .For a compact representation, a variant of the AND/OR tree for EC m n is encoded by a sequence v = (k, v 1 , v 2 , v 3 , v 4 ), where: • k is the label of the selected son of the OR node labeled EC m n in a variant of the AND/OR tree; • v 1 corresponds to the variant of the subtree of the node labeled CT k n ; • v 2 corresponds to the variant of the subtree of the node labeled C k n ; • v 3 corresponds to the variant of the subtree of the node labeled E m k ; • v 4 corresponds to the variant of the subtree of the node labeled P n−k .

Conclusions
In this paper, we study methods for developing combinatorial generation algorithms and present basic general methods for solving this task.We consider one of these methods, which is based on AND/OR trees, and extend it by using the mathematical apparatus of the theory of generating functions.
Using an AND/OR tree structure, it is possible to develop listing, ranking, and unranking algorithms for a given combinatorial set.However, the use of the method for developing combinatorial generation algorithms based on AND/OR trees has the following restriction: the cardinality function of a combinatorial set must belong to the algebra {N, +, ×, R}.For solving this problem, we propose to apply the method of compositae for obtaining explicit expression of the coefficients of generating functions, since the theory of generating functions is one of the basic approaches in combinatorics.The limitation of this method is that it can be applied only for a combinatorial set for which a generating function is known.
As a result, we formalize the proposed idea in our modification of the original method for developing combinatorial generation algorithms.In addition, one of the main contributions of the paper is the application of this method.To confirm the effectiveness of using the proposed method, we develop new ranking and unranking algorithms for the following combinatorial sets: labeled Dyck n-paths with m ascents on return steps, Dyck n-paths with m return steps, m-combinations of n elements, permutations of n elements with m ascents, permutations of n elements.For each of them, we construct an AND/OR tree, find a bijection between the elements of the combinatorial set and the set of variants of the AND/OR tree, and develop algorithms for ranking and unranking the variants of the AND/OR tree.
All the developed algorithms have been realized in the computer algebra system "Maxima" and validated by exhaustive generation for fixed values of combinatorial set parameters.It also has shown that all the developed algorithms have polynomial time complexity.Several examples of applying the obtained results can be found in Appendix A.
As further research, we will consider the development of new and effective combinatorial generation algorithms in the field of applied mathematics.For example, it can be done for combinatorial sets that represent different types of chemical compounds [42], molecular structures such as RNA and DNA [43][44][45], etc.We also plan further improvements to the presented method for developing combinatorial generation algorithms, for example, through the usage of other types of trees [46].

Figure 1 .
Figure 1.The representation of nodes in an AND/OR tree.

Figure 2 .
Figure 2.An AND/OR tree and all its variants.
where each variant v of an AND/OR tree D constructed for the combinatorial set A must correspond to a specific combinatorial object a ∈ A. That is, the bijection A ↔ W(D) must be defined, where W(D) is the set of all the variants v of the AND/OR tree D. The combination of this bijection with the algorithms RankVariant(v) and UnrankVariant(r) represents the desired combinatorial generation algorithms Rank(a) : A → N and Unrank(r) : N → A (for ranking and unranking elements of the combinatorial set A).The ranking algorithm RankVariant(v) allows us to associate each variant v ∈ W(D) of the AND/OR tree D with a unique number r ∈ N |W(D)| = {0, 1, . . ., |W(D)| − 1} called the rank.

Algorithm 1 :
A general algorithm for ranking the variants of an AND/OR tree. 1 RankVariant (z, v, D) 2 begin 3 if z = a leaf of the AND/OR tree D then l := 0 4 if z = an AND node of the AND/OR tree D then 5 n := the number of sons for the node z

6
an OR node of the AND/OR tree D then 10 k := the position of the son of the node z chosen in the variant v among all its sons 11 l := RankVariant (s (z) k , v, D) 12 for i := 1 to k − 1 do l := l + w(s

Algorithm 2 : 3 Push 4 Add root to the variant v 5 while
A general algorithm for unranking the variants of an AND/OR tree.1 UnrankVariant (r, D) 2 begin (r, root) onto the stack the stack is not empty do6 Pop (l, z) from the stack 7 if z = an AND node of the AND/OR tree D then 8 n := the number of sons for the node z 9 for i := 1 to n do 10 l i := l mod w(s z = an OR node of the AND/OR tree D then 17 k := 1 18 sum := 0 19 while sum + w(s (z) k ) ≤ l do 20 sum := sum + w(s A ↔ W(D) between the elements of the combinatorial set A and the set of variants v of the AND/OR tree D in the form of the algorithms ObjectToVariant(a, D) : A → W(D), where a ∈ A, and VariantToObject(v, D) : W(D) → A, where v ∈ W(D). 6. Find a bijection W(D) ↔ N |W(D)| between the elements of the set of variants v of the AND/OR tree D and the finite set of natural numbers N |W(D)| = {0, 1, . . ., |W(D)| − 1}, using the algorithms RankVariant(root, v, D) : W(D) → N |W(D)| , where root is the root of an AND/OR tree D, v ∈ W(D), and UnrankVariant(r, D) : N |W(D)| → W(D), where r ∈ N |W(D)| .

Figure 3 .
Figure 3.All labeled Dyck paths of size 3 with 1 ascent on return steps.

•Figure 4 .
Figure 4.An AND/OR tree for EC m n .

Figure 5 .
Figure 5.An AND/OR tree for CT m n .

•
each selected left son of the AND/OR tree (the node labeled C m n−1 ) determines that the element n is not selected in an m-combination of n elements;• each selected right son of the AND/OR tree (the node labeled C m−1 n−1 ) determines that the element n is selected in an m-combination of n elements;• if a leaf of the AND/OR tree is reached (when m = 0), then it is necessary to not select all n elements in an m-combination of n elements; • if a leaf of the AND/OR tree is reached (when m = n), then it is necessary to select all n elements in an m-combination of n elements.

Figure 6 .
Figure 6.An AND/OR tree for C m n .

Figure 7 .
Figure 7.An AND/OR tree for E m n .

Figure 8 .
Figure 8.An AND/OR tree for P n .

12 :1 9 r := r − sum 10 l 1 := r mod CT k n 11 r
An algorithm for unranking the variants of the AND/OR tree for EC m n .UnrankVariant_EC (r, n, m)