Combinatorial Generation Algorithms for Some Lattice Paths Using the Method Based on AND/OR Trees †

: Methods of combinatorial generation make it possible to develop algorithms for generating objects from a set of discrete structures with given parameters and properties. In this article, we demonstrate the possibilities of using the method based on AND/OR trees to obtain combinatorial generation algorithms for combinatorial sets of several well-known lattice paths (North-East lattice paths, Dyck paths, Delannoy paths, Schroder paths, and Motzkin paths). For each considered combinatorial set of lattice paths, we construct the corresponding AND/OR tree structure where the number of its variants is equal to the number of objects in the combinatorial set. Applying the constructed AND/OR tree structures, we have developed new algorithms for ranking and unranking their variants. The performed computational experiments have conﬁrmed the obtained theoretical estimation of asymptotic computational complexity for the developed ranking and unranking algorithms.


Introduction
Combinatorial generation is a branch of science that lies at the intersection of computer science and combinatorics.This scientific direction is devoted to various methods that allow processing sets of discrete structures (combinatorial sets) in terms of generating elements of such sets.The following scientific monographs are devoted to a detailed description of the main concepts and significant results in combinatorial generation: Kreher and Stinson [1], Ruskey [2], and Knuth [3].
The main tasks of combinatorial generation are as follows: • Listing: the sequential generation of all objects belonging to the combinatorial set; • Ranking: the assignment of an individual number (a rank) to an object belonging to the combinatorial set (this requires some way to order the elements of the combinatorial set); • Unranking: the generation of an object belonging to the combinatorial set by the value of its rank (this requires some way to order the elements of the combinatorial set); • Random selection: the generation of random objects belonging to the combinatorial set.
In discrete mathematics, there are many typical classes of discrete structures (such as permutations, subsets, trees, lattice paths, and others), and each of them has its own specifics.In this article, we study combinatorial generation algorithms for the combinatorial sets of lattice paths [4,5].
A lattice path P is a sequence P = (P 0 , P 1 , . . . ,P k ) of points P i in the d-dimensional integer lattice (i.e., P i ∈ Z d ), where P 0 is the starting point and P k is the end point.It is also required to specify a set of possible steps S in the lattice path, where each step s i ∈ S is a vector in the d-dimensional integer lattice (i.e., s i ∈ Z d ).Furthermore, a lattice path can be represented as a sequence of steps performed, i.e., P = (s 1 , . . . ,s k ), where s i = −−−→ P i−1 P i .Lattice paths are widely used in combinatorics, since they are a fairly simple combinatorial object in terms of their representation.In addition, they are well-suited to encoding various other combinatorial objects.Therefore, it is possible to study the properties of complex discrete structures by studying the properties of the corresponding lattice paths.A brief historical review of research related to lattice paths is presented by Humphreys [6].A more detailed description of the main methods and results in lattice path enumeration is presented in [7].
An analysis of research papers shows that lattice paths are most often used to solve enumerative combinatorics problems (including other more complex structures that have a bijection with lattice paths).However, lattice paths can also be used to solve combinatorial generation problems (i.e., to obtain algorithms for generating such structures).For example, Zaks and Richards [8] developed the algorithms for ranking and unranking lattice paths in the (t + 1)-dimensional integer lattice that begin at the point (n 0 , n 1 , . . ., n t ), end at the origin, and do not go below the hyperplane x 0 = ∑ t i=1 (k i − 1)x i .The use of such lattice paths helped them to obtain combinatorial generation algorithms for the ordered trees with n 0 + 1 leaves and n i internal nodes having k i child nodes where i = 1, . . ., t. Bent [9] developed algorithms for ranking and unranking n-node binary trees by applying Dyck npaths.In this case, the order in which the trees differ by one rotation was used, and the effect of these rotations on the lattice paths was studied.Parque and Miyashita [10] also studied n-node binary trees based on their corresponding Dyck n-paths and proposed an efficient algorithm for their exhaustive generation that uses O(n) space and O(1) time on average per tree.There are also studies that consider the development of combinatorial generation algorithms directly for lattice paths.For example, Barcucci, Bernini, and Pinzani [11,12] developed the algorithms for exhaustive generation of Motzkin and Schroder positive paths and their prefixes.Kuo [13] considered the North-East lattice paths with t turns and proposed an algorithm for their generation.In addition, the Combinatorial Object Server [14] has an implementation of an algorithm for generating Dyck n-paths.
The purpose of this work is to develop new combinatorial generation algorithms for different types of lattice paths based on a common approach.As an example, it is proposed to consider the following lattice paths: North-East lattice paths, Dyck paths, Delannoy paths, Schroder paths, and Motzkin paths.

Materials and Methods
There are several basic general methods for developing combinatorial generation algorithms, such as backtracking [1], the ECO-method [15], Flajolet's method [16], and Kruchinin's method [17].This article discusses the application of the latter method, which is based on the representation of combinatorial sets in the form of an AND/OR tree structure.An AND/OR tree is a tree structure that contains nodes of two types: OR nodes (such nodes correspond to the union of sets, i.e., it is the union of elements of subsets) and AND nodes (such nodes correspond to the Cartesian product of sets, i.e., it is the combination of elements of subsets).A variant of an AND/OR tree is a tree structure obtained by removing all edges except one for each OR node.In this case, the number of variants of an AND/OR tree is equal to the number of objects of the corresponding combinatorial set.
The main restriction on the application of this method is the requirement to have the cardinality function of a given combinatorial set belonging to the algebra {N, +, ×, R} (i.e., usage of only natural numbers, addition and product operations, and the primitive recursion operator).This article continues the study presented in [18], where the possibility of constructing an AND/OR tree structure for each studied combinatorial set of lattice paths was shown.Therefore, using AND/OR tree structures, it is possible to develop new combinatorial generation algorithms for such lattice paths.A detailed description of the method for developing combinatorial generation algorithms based on AND/OR trees is presented in [17].

Results
In this section, we consider the main steps in developing combinatorial generation algorithms for combinatorial sets of several well-known lattice paths by applying the method based on AND/OR trees.
3.1.Combinatorial Generation Algorithms for North-East Lattice Paths 3.1.1.Combinatorial Set A North-East lattice path is a lattice path in the plane which begins at (0, 0), ends at (n, m), and consists of steps (0, 1) and (1, 0) [19].The step (0, 1) is called the North-step and is denoted by N; the (1, 0) step is called the East-step and is denoted by E.
Figure 1 shows all possible 20 variants of the considered North-East lattice paths for n = 3 and m = 3.The total number of North-East lattice paths is defined by the following binomial coefficient (the sequence A007318 in OEIS [20]): The value of L m n can also be calculated using the following recurrence that belongs to the required algebra {N, +, ×, R}: In addition, the sequence of values of L m n is defined by the bivariate generating function

AND/OR Tree Structure
Since Equation ( 2) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for L m n can therefore be constructed (see Figure 2).For this AND/OR tree structure, there are the following initial conditions: • Each node labeled L 0 n is a leaf node in the AND/OR tree for L m n ; • Each node labeled L m 0 is a leaf node in the AND/OR tree for L m n .Figure 3 presents an example of the AND/OR tree structure for L m n where n = 3 and m = 3.The total number of its variants is equal to L 3 3 = 20.Since the obtained AND/OR tree structure does not contain AND nodes, each variant of such a tree is a path from the root to a leaf.For a compact representation, a variant of the AND/OR tree for L m n is encoded by a sequence v = (v 1 , v 2 , . ..) of the selected children of the OR nodes in this tree (the left child corresponds to v i = 1 and the right child corresponds to v i = 2).Theorem 1.There is a bijection between the set of North-East lattice paths beginning at (0, 0) and ending at (n, m) and the set of variants of the AND/OR tree for L m n .
Proof.The total number of North-East lattice paths beginning at (0, 0) and ending at (n, m) is equal to L m n .The total number of variants of the AND/OR tree for L m n presented in Figure 2 is also equal to L m n .Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for L m n .A bijection between the set of North-East lattice paths beginning at (0, 0) and ending at (n, m) and the set of variants of the AND/OR tree for L m n is defined by the following rules: • Each selected left child of the OR node labeled L m n determines the addition of one North-step to the North-East lattice path obtained by the subtree of the node labeled L m−1 n : the resulting lattice path is (s 1 , . . . ,s n+m−1 , N); • Each selected right child of the OR node labeled L m n determines the addition of one Eaststep to the North-East lattice path obtained by the subtree of the node labeled L m n−1 : the resulting lattice path is (s 1 , . . . ,s n+m−1 , E); • Each leaf node labeled L 0 n determines the lattice path from (0, 0) to (n, 0) that consists of n East-steps: the resulting lattice path is (s 1 , . . . ,s n ) = (E, . . . ,E); • Each leaf node labeled L m 0 determines the lattice path from (0, 0) to (0, m) that consists of m North-steps: the resulting lattice path is (s 1 , . . . ,s m ) = (N, . . . ,N).
The algorithms that implement the developed bijection rules have linear time complexity O(n + m), since they require one pass to fill a sequence of (n + m) elements.An example of applying these bijection rules is presented in Table 1.

Lattice Path
Variant of AND/OR Tree Rank Applying the general approach described in [17], we develop algorithms for ranking (Algorithm 1) and unranking (Algorithm 2) the variants of the AND/OR tree for L m n .In these algorithms, () denotes an empty sequence and the function concat(a, b) denotes merging sequences a and b.Table 1 presents an example of ranking the combinatorial set of all North-East lattice paths beginning at (0, 0) and ending at (3, 3).

Combinatorial Set
A Dyck n-path is a lattice path in the plane which begins at (0, 0), ends at (n, n), consists of steps (0, 1) and (1, 0), and never rises above the diagonal y = x [21].The set of Dyck n-paths is a subset of the North-East lattice paths beginning at (0, 0) and ending at (n, n).
Figure 4 shows all possible 5 variants of the considered Dyck paths for n = 3.
The total number of Dyck n-paths is defined by the Catalan number C n (the sequence A000108 in OEIS [20]): The value of C n can also be calculated using the following recurrence that belongs to the required algebra {N, +, ×, R}: In addition, the sequence of values of C n is defined by the generating function

AND/OR Tree Structure
Since Equation ( 4) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for C n can therefore be constructed (see Figure 5).For this AND/OR tree structure, there is the following initial condition: • Each node labeled C 0 is a leaf node in the AND/OR tree for C n .Figure 6 presents an example of the AND/OR tree structure for C n where n = 3.The total number of its variants is equal to C 3 = 5.Theorem 2. There is a bijection between the set of Dyck n-paths and the set of variants of the AND/OR tree for C n .
Proof.The total number of Dyck n-paths is equal to C n .The total number of variants of the AND/OR tree for C n presented in Figure 5 is also equal to C n .Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for C n .A bijection between the set of Dyck n-paths and the set of variants of the AND/OR tree for C n is defined by the following rules: The algorithms that implement the developed bijection rules have polynomial time complexity O(n 2 ), since they make 2n recursive calls, where each such recursive call requires one pass to fill a sequence of 2n elements.An example of applying these bijection rules is presented in Table 2.

Ranking and Unranking Algorithms
Applying the general approach described in [17], we developed algorithms for ranking (Algorithm 3) and unranking (Algorithm 4) the variants of the AND/OR tree for C n .
The developed algorithms have the following the computational complexity: ).Table 2 presents an example of ranking the combinatorial set of all Dyck paths beginning at (0, 0) and ending at (3,3).Algorithm 3: An algorithm for ranking a variant of the AND/OR tree for C n .

. Combinatorial Set
A Delannoy path is a lattice path in the plane which begins at (0, 0), ends at (n, m), and consists of steps (0, 1), (1, 0) and (1, 1) [22].The step (1, 1) is called the North-East-step and denoted by NE.Thus, the set of Delannoy paths is a generalization of the North-East lattice paths beginning at (0, 0) and ending at (n, m) by adding the North-East-steps.
Figure 7 shows all possible 25 variants of the considered Delannoy paths for n = 3 and m = 2.
The total number of Delannoy paths is defined by the Delannoy number D m n (the sequence A008288 in OEIS [20]): Figure 7.All Delannoy paths beginning at (0, 0) and ending at (3,2).
The value of D m n can also be calculated using the following recurrence that belongs to the required algebra {N, +, ×, R}: In addition, the sequence of values of D m n is defined by the bivariate generating function

AND/OR Tree Structure
Since Equation ( 6) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for D m n can therefore be constructed (see Figure 8).For this AND/OR tree structure, there are the following initial conditions: • Each node labeled D 0 n is a leaf node in the AND/OR tree for D m n ; • Each node labeled D m 0 is a leaf node in the AND/OR tree for D m n .Figure 9 presents an example of the AND/OR tree structure for D m n where n = 3 and m = 2.The total number of its variants is equal to D 2 3 = 25.Since the obtained AND/OR tree structure does not contain AND nodes, each variant of such a tree is a path from the root to a leaf.For a compact representation, a variant of the AND/OR tree for D m n is encoded by a sequence v = (v 1 , v 2 , . ..) of the selected children of the OR nodes in this tree (the left child corresponds to v i = 1, the middle child corresponds to v i = 2 and the right child corresponds to v i = 3).Theorem 3.There is a bijection between the set of Delannoy paths beginning at (0, 0) and ending at (n, m) and the set of variants of the AND/OR tree for D m n .
Proof.The total number of Delannoy paths beginning at (0, 0) and ending at (n, m) is equal to D m n .The total number of variants of the AND/OR tree for D m n presented in Figure 8 is also equal to D m n .Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for D m n .A bijection between the set of Delannoy paths beginning at (0, 0) and ending at (n, m) and the set of variants of the AND/OR tree for D m n is defined by the following rules:

•
Each selected left child of the OR node labeled D m n determines the addition of one North-step to the Delannoy path obtained by the subtree of the node labeled D m−1 n and consisting of k steps: the resulting lattice path is (s 1 , . . . ,s k , N);

•
Each selected middle child of the OR node labeled D m n determines the addition of one East-step to the Delannoy path obtained by the subtree of the node labeled D m n−1 and consisting of k steps: the resulting lattice path is (s 1 , . . . ,s k , E); • Each selected right child of the OR node labeled D m n determines the addition of one North-East-step to the Delannoy path obtained by the subtree of the node labeled D m−1 n−1 and consisting of k steps: the resulting lattice path is (s 1 , . . . ,s k , NE); • Each leaf node labeled D 0 n determines the Delannoy path from (0, 0) to (n, 0) that consists of n East-steps: the resulting lattice path is (s 1 , . . . ,s n ) = (E, . . . ,E); • Each leaf node labeled D m 0 determines the Delannoy path from (0, 0) to (0, m) that consists of m North-steps: the resulting lattice path is (s 1 , . . . ,s m ) = (N, . . . ,N).
The algorithms that implement the developed bijection rules have linear time complexity O(n + m), since they require one pass to fill a sequence of maximum (n + m) elements.An example of applying these bijection rules is presented in Table 3.

Lattice Path
Variant of AND/OR Tree Rank

Ranking and Unranking Algorithms
Applying the general approach described in [17], we develop algorithms for ranking (Algorithm 5) and unranking (Algorithm 6) the variants of the AND/OR tree for D m n .Table 3 presents an example of ranking the combinatorial set of all Delannoy paths beginning at (0, 0) and ending at (3, 2).

Combinatorial Set
A Schroder n-path is a lattice path in the plane which begins at (0, 0), ends at (n, n), consists of steps (0, 1), (1, 0), and (1, 1), and never rises above the diagonal y = x [23].The set of Schroder n-paths is a subset of the Delannoy paths beginning at (0, 0) and ending at (n, n).
Figure 10 shows all possible 22 variants of the considered Schroder paths for n = 3.The total number of Schroder n-paths is defined by the Schroder number S n (the sequence A006318 in OEIS [20]): The value of S n can also be calculated using the following recurrence that belongs to the required algebra {N, +, ×, R}: In addition, the sequence of values of S n is defined by the generating function

AND/OR Tree Structure
Since Equation ( 8) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for S n can therefore be constructed (see Figure 11).For this AND/OR tree structure, there is the following initial condition: • Each node labeled S 0 is a leaf node in the AND/OR tree for S n .Figure 12 presents an example of the AND/OR tree structure for S n where n = 3.The total number of its variants is equal to S 3 = 22.
For a compact representation, a variant of the AND/OR tree for S n is encoded by a sequence v: If the left child of the OR nodde labeled S n is selected, then v = (I, 3. An empty sequence v = () corresponds to the selection of a leaf node labeled S 0 .Proof.The total number of Schroder n-paths is equal to S n .The total number of variants of the AND/OR tree for S n presented in Figure 11 is also equal to S n .Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for S n .A bijection between the set of Schroder n-paths and the set of variants of the AND/OR tree for S n is defined by the following rules:

•
Each selected left child of the OR node labeled S n determines the addition of one North-East-step to the Schroder (n − 1)-path obtained by the subtree of the node labeled S n−1 and consisting of k steps: the resulting Schroder n-path is (s 1 , . . . ,s k , NE); The algorithms that implement the developed bijection rules have polynomial time complexity O(n 2 ), since they make n recursive calls where each such recursive call requires one pass to fill a sequence of maximum 2n elements.An example of applying these bijection rules is presented in Table 4.

Ranking and Unranking Algorithms
Applying the general approach described in [17], we develop algorithms for ranking (Algorithm 7) and unranking (Algorithm 8) the variants of the AND/OR tree for S n .
The developed algorithms have the following the computational complexity: • Algorithm 7 has at most n recursive calls where I = −1 (each such recursive call requires one assignment) and has at most n recursive calls where I = −1 (each such recursive call requires calculations of S n maximum 2n times).Applying Equation ( 7), the calculation of S n has polynomial time complexity O(n 2 ).Hence, Algorithm 7 has polynomial time complexity O(n 4 ); • Algorithm 8 has at most n recursive calls where I = −1 (each such recursive call requires calculations of S n ) and has at most n recursive calls where I = −1 (each such recursive call requires calculations of S n maximum (2n + 2) times).Hence, Algorithm 8 has polynomial time complexity O(n 4 ).Table 4 presents an example of ranking the combinatorial set of all Schroder paths beginning at (0, 0) and ending at (3, 3).

Combinatorial Set
A Motzkin n-path is a lattice path in the plane which begins at (0, 0), ends at (n, n), consists of steps (0, 2), (2, 0) and (1, 1), and never rises above the diagonal y = x [24].The step (0, 2) is the double North-step, the step (2, 0) is the double East-step.The set of Motzkin n-paths is a subset of the Schroder n-paths.
Figure 13 shows all possible 4 variants of the considered Motzkin paths for n = 3.
The total number of Motzkin n-paths is defined by the Motzkin number M n (the sequence A001006 in OEIS [20]): The value of M n can also be calculated using the following recurrence that belongs to the required algebra {N, +, ×, R}: In addition, the sequence of values of M n is defined by the generating function

AND/OR Tree Structure
Since Equation ( 10) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for M n can therefore be constructed (see Figure 14).
For this AND/OR tree structure, there is the following initial condition: • each node labeled M 0 or M 1 is a leaf node in the AND/OR tree for M n .Figure 15 presents an example of the AND/OR tree structure for M n where n = 3.The total number of its variants is equal to   For a compact representation, a variant of the AND/OR tree for M n is encoded by a sequence v: If the left child of the OR node labeled M n is selected, then v = (I, v 1 ), where , where • I corresponds to the selected value of i in the AND/OR tree for M n ; • v 1 corresponds to the variant of the subtree of the node labeled M I ; • v 2 corresponds to the variant of the subtree of the node labeled M n−2−I ; 3.
An empty sequence v = () corresponds to the selection of a leaf node labeled M 0 .
Theorem 5.There is a bijection between the set of Motzkin n-paths and the set of variants of the AND/OR tree for M n .
Proof.The total number of Motzkin n-paths is equal to M n .The total number of variants of the AND/OR tree for M n presented in Figure 14 is also equal to M n .Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for M n .A bijection between the set of Motzkin n-paths and the set of variants of the AND/OR tree for M n is defined by the following rules: The algorithms that implement the developed bijection rules have polynomial time complexity O(n 2 ), since they make n recursive calls where each such recursive call requires one pass to fill a sequence of maximum 2n elements.An example of applying these bijection rules is presented in Table 5.

Ranking and Unranking Algorithms
Applying the general approach described in [17], we develop algorithms for ranking (Algorithm 9) and unranking (Algorithm 10) the variants of the AND/OR tree for M n .
The developed algorithms have the following the computational complexity: Table 5 presents an example of ranking the combinatorial set of all Motzkin paths beginning at (0, 0) and ending at (3,3).

Computational Experiments
We have also performed a computational experiment aimed at testing the obtained computational complexity of the developed ranking and unranking algorithms.For this purpose, we implemented these algorithms in the computer algebra system Maxima [25] on a laptop (Intel i7-9750H, 2.6 GHz, Windows 10, 64 bit).We then measured the elapsed time of the algorithms for ranking and unranking variants of the AND/OR trees for L m n , C n , D m n , S n and M n with different values of the parameters n and m.All calculations were made for the variants of the AND/OR trees with the maximum rank (because this is usually the hardest case to compute due to the need to traverse the entire AND/OR tree structure).
For the maximum rank r := L m n − 1, Algorithms 1 and 2 have polynomial time complexity O(nm) for m < n and O(n 2 ) for n < m. Figure 16a     For the maximum rank r := D m n − 1, Algorithms 5 and 6 have the following polynomial time complexity (due to all special cases of the calculation of Equation ( 5)):  For the maximum rank r := S n − 1, Algorithms 7 and 8 have polynomial time complexity O(n 4 ). Figure 19 presents the average time for unranking and ranking such variants of the AND/OR tree for S n where n is in the range of 1 to 50 with step 1.This figure confirms polynomial time complexity O(n 4 ).

Discussion
In this article, we have demonstrated the possibilities of using the method based on AND/OR trees to obtain combinatorial generation algorithms for combinatorial sets of several well-known lattice paths.In particular, the following lattice paths were considered: North-East lattice paths, Dyck paths, Delannoy paths, Schroder paths, and Motzkin paths.For each of these combinatorial sets of lattice paths, there is an expression of its cardinality function that belongs to the algebra {N, +, ×, R}.This fact made it possible to construct AND/OR tree structures for these combinatorial sets, in which the number of their variants is equal to the number of objects in the combinatorial set.To associate each considered lattice path with one specific variant of the corresponding AND/OR tree structure, the bijection rules were derived.
Applying the constructed AND/OR tree structures, we have developed algorithms for ranking and unranking their variants.All developed algorithms have a recursive form since the applied AND/OR tree structures were built by using recurrence relations.The developed algorithms, together with the obtained bijection rules, make it possible to encode a given lattice path as a single number (by applying ranking algorithms).For example, this reduces the amount of data stored if it is necessary to store information about a large number of lattice paths.It is also possible to recover each lattice path by decoding the corresponding rank (by applying unranking algorithms).In addition, the unranking algorithms make it possible to form a sample of random lattice paths with the given properties by applying them to random rank values.If it is necessary to generate all objects with the given parameters (for example, when an exhaustive search is needed to solve an optimization problem), then we can run the unranking algorithm for all rank values.Furthermore, the exhaustive generation can be performed by sequentially traversing all variants of the considered AND/OR tree structure.
The developed combinatorial generation algorithms for lattice paths have polynomial time complexity, which is determined by the maximum number of recursive calls (the height of an AND/OR tree), the maximum number of child nodes of a given node (the width of an AND/OR tree), and the computational complexity of calculating the value of the cardinality function.Assuming algebraic operations with numbers in O(1), the performed computational experiments confirmed the obtained theoretical estimation of asymptotic computational complexity for the developed ranking and unranking algorithms.
To reduce the time complexity of these algorithms, we can add a preliminary step where all the required values of the cardinality function are calculated and stored.In this case, the computational complexity of algorithms will depend only on the size of the AND/OR tree structure.However, this improvement requires additional memory space.In addition, if an AND/OR tree structure contains OR nodes where the number of children depends on the AND/OR tree parameters (for example, as AND/OR trees for C n , S n and M n ), then the computational complexity of ranking and unranking algorithms can be reduced as follows: • By calculating sum (for example, see Line 5 in Algorithm 3 or Lines 5-14 in Algorithm 4), applying a simpler explicit formula without using the summation operator; • By a preliminary search of the value of the selected child of the OR node (for example, the parameter I defined in Lines 6-14 in Algorithm 4), applying an approximate formula (as in [26]).
Thus, the main contribution of this article is the derivation of bijections between two sets of discrete structures (the set of lattice paths and the set of AND/OR tree variants), as well as new algorithms for their generation.The scheme used in this article to develop combinatorial generation algorithms for lattice paths can also be applied to the classes of more complex lattice paths that have additional types of steps (for example, skew Dyck paths [27] or skew Dyck paths with catastrophes [28]) or depend on more parameters (for example, lattice paths associated with the generalized Narayana numbers [29]).The main restriction is that the cardinality function for such lattice paths must belong to the required algebra {N, +, ×, R}.

Figure 2 .
Figure 2.An AND/OR tree for L m n .

Figure 3 .
Figure 3.An AND/OR tree for L 3 3 .

Algorithm 1 : 4 else 5 if v 1 = 1 2 :n 1 n.
An algorithm for ranking a variant of the AND/OR tree for L m n . 1 Rank_L(v = (v 1 , v 2 , . ..), n, m) 2 begin 3 if n = 0 or m = 0 then r := 0 then r := Rank_L((v 2 , . ..), n, m − 1) 6 else r := L m−1 n + Rank_L((v 2 , . ..), n − 1, m) An algorithm for unranking a variant of the AND/OR tree for L m n . 1 Unrank_L(r, n, m) 2 begin 3 if n = 0 or m = 0 then v := ()then v :=concat((1), Unrank_L(r, n, m − 1)) 6 else v :=concat((2), Unrank_L(r − L m−1 n , n − 1, m))The developed algorithms have the following computational complexity: • Algorithm 1 has at most m recursive calls where v 1 = 1 (each such recursive call requires one assignment) and has at most n recursive calls where v 1 = 2 (each such recursive call requires calculations of L m−1 n ).Applying Equation (1), the calculation of L m n has linear time complexity O(m) for m < n and O(n) for m > n.Hence, Algorithm 1 has polynomial time complexity O(nm) for m < n and O(m + n 2 ) for m > n; • Algorithm 2 has at most (n + m) recursive calls where each such recursive call requires calculations of L m−Hence, Algorithm 2 has polynomial time complexity O(m(n + m)) for m < n and O(n(n + m)) for m > n.

Figure 5 .
Figure 5.An AND/OR tree for C n .

Figure 6 .
Figure 6.An AND/OR tree for C 3 .

For a compact
representation, a variant of the AND/OR tree for C n is encoded by a sequence v = (I, v 1 , v 2 ), where the following apply: • An empty sequence v = () corresponds to the selection of a leaf node labeled C 0 ; • I corresponds to the selected value of i in the AND/OR tree for C n ; • v 1 corresponds to the variant of the subtree of the node labeled C I (the left subtree); • v 2 corresponds to the variant of the subtree of the node labeled C n−1−I (the right subtree).

•
Each selected child of the OR node labeled C n determines the addition of one East-step and one North-step to the Dyck (n − 1)-path that merges the Dyck I-path obtained by the subtree of the node labeled C I and consisting of 2I steps and the Dyck (n − 1 − I)path obtained by the subtree of the node labeled C n−1−I and consisting of (2n − 2I − 2) steps: the resulting Dyck n-path is (s 1 , . . . ,s 2I , E, s 2I+2 , . . . ,s 2n−1 , N); • The subtree of the node labeled C I (the left subtree) determines the Dyck I-path of the form (s 1 , . . . ,s 2I ); • The subtree of the node labeled C n−1−I (the right subtree) determines the Dyck (n − 1 − I)-path of the form (s 2I+2 , . . . ,s 2n−1 ); • Each leaf node labeled C 0 determines the empty lattice path ().

Figure 8 .
Figure 8.An AND/OR tree for D m n .

Figure 9 .
Figure 9.An AND/OR tree for D 2 3 .

Figure 11 .
Figure 11.An AND/OR tree for S n .
v 1 ), where • I = −1; • v 1 corresponds to the variant of the subtree of the node labeled S n−1 ; 2. Otherwise v = (I, v 1 , v 2 ), where • I corresponds to the selected value of i in the AND/OR tree for S n ; • v 1 corresponds to the variant of the subtree of the node labeled S I ; • v 2 corresponds to the variant of the subtree of the node labeled S n−1−I ;

Figure 12 .
Figure 12.An AND/OR tree for S 3 .

Theorem 4 .
There is a bijection between the set of Schroder n-paths and the set of variants of the AND/OR tree for S n .

•
Each selected child of the OR node labeled S n determines the addition of one East-step and one North-step to the Schroder (n − 1)-path that merges the Schroder I-path obtained by the subtree of the node labeled S I and consisting of k 1 steps and the Schroder (n − 1 − I)-path obtained by the subtree of the node labeled S n−1−I and consisting of k 2 steps: the resulting Schroder n-path is s 1 , . . ., s k 1 , E, s k 1 +2 , . . ., s k 1 +1+k 2 , N ; • The subtree of the node labeled S I (the left subtree) determines the Schroder I-path of the form s 1 , . . ., s k 1 ; •The subtree of the node labeled S n−1−I (the right subtree) determines the Schroder (n − 1 − I)-path of the form s k 1 +2 , . . ., s k 1 +1+k 2 ; • Each leaf node labeled S 0 determines the empty lattice path ().

Figure 14 .
Figure 14.An AND/OR tree for M n .

Figure 15 .
Figure 15.An AND/OR tree for M 3 .

•
each selected left child of the OR node labeled M n determines the addition of one North-East-step to the Motzkin (n − 1)-path obtained by the subtree of the node labeled M n−1 and consisting of k steps: the resulting Motzkin n-path is (s 1 , . . . ,s k , NE); • each selected child of the OR node labeled M n determines the addition of two Eaststeps and North-steps to the Motzkin (n − 2)-path that merges the Motzkin I-path obtained by the subtree of the node labeled M I and consisting of k 1 steps and the Motzkin (n − 2 − I)-path obtained by the subtree of the node labeled M n−2−I and consisting of k 2 steps: the resulting Motzkin n-path is s 1 , . . ., s k 1 , E, E, s k 1 +3 , . . ., s k 1 +2+k 2 , N, N ; • the subtree of the node labeled M I (the left subtree) determines the Motzkin I-path of the form s 1 , . . ., s k 1 ; • the subtree of the node labeled M n−2−I (the right subtree) determines the Motzkin (n − 2 − I)-path of the form s k 1 +3 , . . ., s k 1 +2+k 2 ; • each leaf node labeled M 1 determines the lattice path from (0, 0) to (1, 1) that consists of one North-East-step: the resulting lattice path is (s 1 ) = (NE); • each leaf node labeled M 0 determines the empty lattice path ().

•
Algorithm 9 has at most n recursive calls where I = −1 (each such recursive call requires one assignment) and has at most n recursive calls where I = −1 (each such recursive call requires calculations of M n maximum (2n − 2) times).Applying Equation (9), the calculation of M n has polynomial time complexity O(n 2 ).Hence, Algorithm 9 has polynomial time complexity O(n 4 ); • Algorithm 10 has at most n recursive calls where I = −1 (each such recursive call requires calculations of M n ) and has at most n recursive calls where I = −1 (each such recursive call requires calculations of M n maximum 2n times).Hence, Algorithm 10 has polynomial time complexity O(n 4 ).
presents the average time for unranking and ranking such variants of the AND/OR tree for L m n where m = 100 and n is in the range of 5 to 200 with step 5.This figure confirms polynomial time complexity O(n 2 ) for n < 100 and linear time complexity O(n) for n > 100 when m = 100.Figure 16b presents the average time for unranking and ranking variants of the AND/OR tree for L m n where n = 100 and m is in the range of 5 to 200 with step 5.This figure confirms linear time complexity O(m) for m < 100 and constant time complexity O(1) for m > 100 when n = 100.For other fixed values of m (or n), the general form of the dependence on n (or m) does not change.

Figure 16 .
Figure 16.Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for L m n : (a) dependence on n when m = 100; and (b) dependence on m when n = 100.For the maximum rank r := C n − 1, Algorithms 3 and 4 have polynomial time complexity O(n 3 ).Figure 17 presents the average time for unranking and ranking such variants of the AND/OR tree for C n where n is in the range of 1 to 50 with step 1.This figure confirms polynomial time complexity O(n 3 ).

Figure 17
presents the average time for unranking and ranking such variants of the AND/OR tree for C n where n is in the range of 1 to 50 with step 1.This figure confirms polynomial time complexity O(n 3 ).

Figure 17 .
Figure 17.Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for C n .
Figure 18a presents the average time for unranking and ranking such variants of the AND/OR tree for D m n where m = 50 and n is in the range of 5 to 200 with step 5. Figure 18b presents the average time for unranking and ranking variants of the AND/OR tree for D m n where n = 50 and m is in the range of 5 to 200 with step 5.These figures confirm the derived polynomial time complexity for all special cases.For other fixed values of m (or n), the general form of the dependence on n (or m) does not change.

Figure 18 .
Figure 18.Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for D m n : (a) dependence on n when m = 50; and (b) dependence on m when n = 50.

Figure 19 .
Figure 19.Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for S n .For the maximum rank r := M n − 1, Algorithms 9 and 10 have polynomial time complexity O(n 4 ).Figure 20 presents the average time for unranking and ranking such variants of the AND/OR tree for M n where n is in the range of 1 to 50 with step 1.This figure confirms polynomial time complexity O(n 4 ).

Figure 20
presents the average time for unranking and ranking such variants of the AND/OR tree for M n where n is in the range of 1 to 50 with step 1.This figure confirms polynomial time complexity O(n 4 ).

Figure 20 .
Figure 20.Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for M n .