Next Article in Journal
Learning Individualized Hyperparameter Settings
Next Article in Special Issue
A Surprisal-Based Greedy Heuristic for the Set Covering Problem
Previous Article in Journal
Hybrid Genetic and Spotted Hyena Optimizer for Flow Shop Scheduling Problem
Previous Article in Special Issue
Subgroup Discovery in Machine Learning Problems with Formal Concepts Analysis and Test Theory Algorithms
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

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

Laboratory of Algorithms and Technologies for Discrete Structures Research, Tomsk State University of Control Systems and Radioelectronics, 634050 Tomsk, Russia
This paper is an extended version of our paper published in the proceedings book of the 5th Mediterranean International Conference of Pure & Applied Mathematics and Related Areas (MICOPAM 2022, Antalya, Turkey, 27–30 October 2022).
Algorithms 2023, 16(6), 266; https://doi.org/10.3390/a16060266
Submission received: 5 May 2023 / Revised: 21 May 2023 / Accepted: 23 May 2023 / Published: 26 May 2023

Abstract

:
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 confirmed the obtained theoretical estimation of asymptotic computational complexity for the developed ranking and unranking algorithms.

1. 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 = i = 1 t ( 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 n-paths. 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.

2. 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].

3. 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 A 007318 in OEIS [20]):
L n m = n + m m = n + m n .
The value of L n m can also be calculated using the following recurrence that belongs to the required algebra { N , + , × , R } :
L n m = L n m 1 + L n 1 m , L n 0 = L 0 m = 1 .
In addition, the sequence of values of L n m is defined by the bivariate generating function
n 0 m 0 L n m x n y m = 1 1 x y .

3.1.2. AND/OR Tree Structure

Since Equation (2) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for L n m can therefore be constructed (see Figure 2).
For this AND/OR tree structure, there are the following initial conditions:
  • Each node labeled L n 0 is a leaf node in the AND/OR tree for L n m ;
  • Each node labeled L 0 m is a leaf node in the AND/OR tree for L n m .
Figure 3 presents an example of the AND/OR tree structure for L n m 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 n m 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 n m .
Proof. 
The total number of North-East lattice paths beginning at  ( 0 , 0 ) and ending at ( n , m ) is equal to L n m . The total number of variants of the AND/OR tree for L n m presented in Figure 2 is also equal to L n m . Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for L n m . 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 n m is defined by the following rules:
  • Each selected left child of the OR node labeled L n m determines the addition of one North-step to the North-East lattice path obtained by the subtree of the node labeled L n m 1 : the resulting lattice path is s 1 , , s n + m 1 , N ;
  • Each selected right child of the OR node labeled L n m determines the addition of one East-step to the North-East lattice path obtained by the subtree of the node labeled  L n 1 m : the resulting lattice path is s 1 , , s n + m 1 , E ;
  • Each leaf node labeled L n 0 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 0 m 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.

3.1.3. Ranking and Unranking Algorithms

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 n m . In these algorithms, ( ) denotes an empty sequence and the function concat ( a , b ) denotes merging sequences a and b.
Algorithm 1: An algorithm for ranking a variant of the AND/OR tree for  L n m .
Algorithms 16 00266 i001
Algorithm 2: An algorithm for unranking a variant of the AND/OR tree for  L n m .
Algorithms 16 00266 i002
    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 n m 1 ). Applying Equation (1), the calculation of L n m has linear time complexity O ( m ) for m < n and O ( n ) for m > n . Hence, Algorithm 1 has polynomial time complexity O ( n m ) 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 n m 1 . Hence, Algorithm 2 has polynomial time complexity O ( m ( n + m ) ) for m < n and O ( n ( n + m ) ) for m > n .
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 ) .

3.2. Combinatorial Generation Algorithms for Dyck Paths

3.2.1. 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 A 000108 in OEIS [20]):
C n = 1 n + 1 2 n n .
The value of C n can also be calculated using the following recurrence that belongs to the required algebra { N , + , × , R } :
C n = i = 0 n 1 C i C n 1 i , C 0 = 1 .
In addition, the sequence of values of C n is defined by the generating function
n 0 C n x n = 1 1 4 x 2 x .

3.2.2. 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 .
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).
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:
  • 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 2 I steps and the Dyck ( n 1 I ) -path obtained by the subtree of the node labeled C n 1 I and consisting of ( 2 n 2 I 2 ) steps: the resulting Dyck n-path is s 1 , , s 2 I , E , s 2 I + 2 , , s 2 n 1 , N ;
  • The subtree of the node labeled  C I (the left subtree) determines the Dyck I-path of the form s 1 , , s 2 I ;
  • The subtree of the node labeled  C n 1 I (the right subtree) determines the Dyck ( n 1 I ) -path of the form s 2 I + 2 , , s 2 n 1 ;
  • Each leaf node labeled C 0 determines the empty lattice path.
The algorithms that implement the developed bijection rules have polynomial time complexity O ( n 2 ) , since they make 2 n recursive calls, where each such recursive call requires one pass to fill a sequence of 2 n elements. An example of applying these bijection rules is presented in Table 2.

3.2.3. 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:
  • Algorithm 3 has at most n recursive calls, where each such recursive call requires calculations of C n maximum ( 2 n 1 ) times. Applying Equation (3), the calculation of C n has linear time complexity O ( n ) . Hence, Algorithm 3 has polynomial time complexity O ( n 3 ) ;
  • Algorithm 4 has at most n recursive calls, where each such recursive call requires calculations of C n maximum ( 2 n + 1 ) times. Hence, Algorithm 4 has polynomial time complexity O ( n 3 ) .
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 .
Algorithms 16 00266 i003
Algorithm 4: An algorithm for unranking a variant of the AND/OR tree for  C n .
Algorithms 16 00266 i004

3.3. Combinatorial Generation Algorithms for Delannoy Paths

3.3.1. 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 N E . 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 n m (the sequence A 008288 in OEIS [20]):
D n m = i = 1 min ( n , m ) n i m i 2 i .
The value of D n m can also be calculated using the following recurrence that belongs to the required algebra { N , + , × , R } :
D n m = D n m 1 + D n 1 m + D n 1 m 1 , D n 0 = D 0 m = 1 .
In addition, the sequence of values of D n m is defined by the bivariate generating function
n 0 m 0 D n m x n y m = 1 1 x y x y .

3.3.2. AND/OR Tree Structure

Since Equation (6) satisfies the requirements of the applied method, the corresponding AND/OR tree structure for D n m can therefore be constructed (see Figure 8).
For this AND/OR tree structure, there are the following initial conditions:
  • Each node labeled D n 0 is a leaf node in the AND/OR tree for D n m ;
  • Each node labeled D 0 m is a leaf node in the AND/OR tree for D n m .
Figure 9 presents an example of the AND/OR tree structure for D n m where n = 3 and m = 2 . The total number of its variants is equal to D 3 2 = 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 n m 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 n m .
Proof. 
The total number of Delannoy paths beginning at  ( 0 , 0 ) and ending at ( n , m ) is equal to D n m . The total number of variants of the AND/OR tree for D n m presented in Figure 8 is also equal to D n m . Therefore, it is possible to associate each such lattice path with one specific variant of the AND/OR tree for D n m . 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 n m is defined by the following rules:
  • Each selected left child of the OR node labeled D n m determines the addition of one North-step to the Delannoy path obtained by the subtree of the node labeled D n m 1 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 n m determines the addition of one East-step to the Delannoy path obtained by the subtree of the node labeled D n 1 m 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 n m determines the addition of one North-East-step to the Delannoy path obtained by the subtree of the node labeled D n 1 m 1 and consisting of k steps: the resulting lattice path is s 1 , , s k , N E ;
  • Each leaf node labeled D n 0 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 0 m 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.

3.3.3. 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 n m .
Algorithm 5: An algorithm for ranking a variant of the AND/OR tree for  D n m .
Algorithms 16 00266 i005
Algorithm 6: An algorithm for unranking a variant of the AND/OR tree for  D n m .
Algorithms 16 00266 i006
The developed algorithms have the following computational complexity:
  • Algorithm 5 has at most m recursive calls where v 1 = 1 (each such recursive call requires one assignment), has at most n recursive calls where v 1 = 2 (each such recursive call requires calculations of D n m 1 ), and has at most min ( n , m ) recursive calls where v 1 = 3 (each such recursive call requires calculations of D n m 1 and D n 1 m ). Applying Equation (5), the calculation of D n m has polynomial time complexity O ( m 2 ) for m < n and O ( n 2 ) for m > n . Hence, Algorithm 5 has polynomial time complexity O ( m 2 ( n + m ) ) for m < n and O ( m + n 3 ) for m > n ;
  • Algorithm 6 has at most ( n + m ) recursive calls where each such recursive call requires calculations of D n m 1 or D n 1 m . Hence, Algorithm 2 has polynomial time complexity O ( m 2 ( n + m ) ) for m < n and O ( n 2 ( n + m ) ) for 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 ) .

3.4. Combinatorial Generation Algorithms for Schroder Paths

3.4.1. 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 A 006318 in OEIS [20]):
S n = i = 0 n 1 i + 1 n + i i n i .
The value of S n can also be calculated using the following recurrence that belongs to the required algebra { N , + , × , R } :
S n = S n 1 + i = 0 n 1 S i S n 1 i , S 0 = 1 .
In addition, the sequence of values of S n is defined by the generating function
n 0 S n x n = 1 x 1 6 x + x 2 2 x .

3.4.2. 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 , v 1 ) , where
    • I = 1 ;
    • v 1 corresponds to the variant of the subtree of the node labeled S n 1 ;
  • 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 ;
  • An empty sequence v = ( ) corresponds to the selection of a leaf node labeled S 0 .
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 .
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 , N E ;
  • 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 ().
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 2 n elements. An example of applying these bijection rules is presented in Table 4.

3.4.3. 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 2 n 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 ( 2 n + 2 ) times). Hence, Algorithm 8 has polynomial time complexity O ( n 4 ) .
Algorithm 7: An algorithm for ranking a variant of the AND/OR tree for  S n .
Algorithms 16 00266 i007
Algorithm 8: An algorithm for unranking a variant of the AND/OR tree for  S n .
Algorithms 16 00266 i008
    Table 4 presents an example of ranking the combinatorial set of all Schroder paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .

3.5. Combinatorial Generation Algorithms for Motzkin Paths

3.5.1. 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 A 001006 in OEIS [20]):
M n = i = 0 n 2 1 i + 1 n 2 i 2 i i .
The value of M n can also be calculated using the following recurrence that belongs to the required algebra { N , + , × , R } :
M n = M n 1 + i = 0 n 2 M i M n 2 i , M 0 = M 1 = 1 .
In addition, the sequence of values of M n is defined by the generating function
n 0 M n x n = 1 x 1 2 x 3 x 2 2 x 2 .

3.5.2. 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 M 3 = 4 .
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
    • I = 1 ;
    • v 1 corresponds to the variant of the subtree of the node labeled M n 1 ;
  • Otherwise v = ( I , v 1 , v 2 ) , 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 ;
  • 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:
  • 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 , N E ;
  • each selected child of the OR node labeled M n determines the addition of two East-steps 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 = N E ;
  • each leaf node labeled M 0 determines the empty lattice path ().
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 2 n elements. An example of applying these bijection rules is presented in Table 5.

3.5.3. 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:
  • 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 ( 2 n 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 2 n times). Hence, Algorithm 10 has polynomial time complexity O ( n 4 ) .
Algorithm 9: An algorithm for ranking a variant of the AND/OR tree for  M n .
Algorithms 16 00266 i009
Algorithm 10: An algorithm for unranking a variant of the AND/OR tree for  M n .
Algorithms 16 00266 i010
Table 5 presents an example of ranking the combinatorial set of all Motzkin paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .

3.6. 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 n m , C n , D n m , 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 n m 1 , Algorithms 1 and 2 have polynomial time complexity O ( n m ) for m < n and O ( n 2 ) for n < m . Figure 16a presents the average time for unranking and ranking such variants of the AND/OR tree for L n m 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 n m 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.
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 ) .
For the maximum rank r : = D n m 1 , Algorithms 5 and 6 have the following polynomial time complexity (due to all special cases of the calculation of Equation (5)): O ( m 3 ) for 2 m < n , O ( m 2 ( n m ) ) for m < n < 2 m , O ( n 2 ( m n ) ) for n < m < 2 n , and O ( n 3 ) for 2 n < m . Figure 18a presents the average time for unranking and ranking such variants of the AND/OR tree for D n m 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 n m 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.
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 ) .
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 ) .

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 s u m (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 } .

Funding

This research was funded by the Russian Science Foundation, grant number 22-71-10052.

Data Availability Statement

Source code can be made available on request.

Acknowledgments

The author would like to thank the referees for their helpful comments and suggestions.

Conflicts of Interest

The author declare no conflict of interest.

References

  1. Kreher, D.L.; Stinson, D.R. Combinatorial Algorithms: Generation, Enumeration, and Search; CRC Press: Boca Raton, FL, USA, 1999. [Google Scholar]
  2. Ruskey, F. Combinatorial Generation. Available online: https://page.math.tu-berlin.de/~felsner/SemWS17-18/Ruskey-Comb-Gen.pdf (accessed on 1 May 2023).
  3. Knuth, D.E. The Art of Computer Programming, Volume 4A: Combinatorial Algorithms, Part 1; Addison-Wesley Professional: Boston, MA, USA, 2011. [Google Scholar]
  4. Stanley, R.P. Enumerative Combinatorics: Volume 1, 2nd ed.; Cambridge University Press: New York, NY, USA, 2012. [Google Scholar]
  5. Wallner, M. Combinatorics of Lattice Paths and Tree-Like Structures. Ph.D. Thesis, Institute of Discrete Mathematics and Geometry, Vienna University of Technology, Vienna, Austria, 2016. [Google Scholar]
  6. Humphreys, K. A history and a survey of lattice path enumeration. J. Statist. Plann. Inference 2010, 140, 2237–2254. [Google Scholar] [CrossRef]
  7. Krattenthaler, C. Lattice path enumeration. In Handbook of Enumerative Combinatorics; Bona, M., Ed.; CRC Press: New York, NY, USA, 2015; pp. 589–678. [Google Scholar]
  8. Zaks, S.; Richards, D. Generating trees and other combinatorial objects lexicographically. SIAM J. Comput. 1979, 8, 73–81. [Google Scholar] [CrossRef]
  9. Bent, S.W. Ranking trees generated by rotations. Lect. Notes Comput. Sci. 1990, 447, 132–142. [Google Scholar]
  10. Parque, V.; Miyashita, T. An efficient scheme for the generation of ordered trees in constant amortized time. In Proceedings of the 15th International Conference on Ubiquitous Information Management and Communication (IMCOM), Seoul, Republic of Korea, 4–6 January 2021. [Google Scholar]
  11. Barcucci, E.; Bernini, A.; Pinzani, R. Exhaustive generation of positive lattice paths. In Proceedings of the 11th International Conference on Random and Exhaustive Generation of Combinatorial Structures (GASCom), Athens, Greece, 18–20 June 2018. [Google Scholar]
  12. Barcucci, E.; Bernini, A.; Pinzani, R. Exhaustive generation of some lattice paths and their prefixes. Theoret. Comput. Sci. 2021, 878–879, 47–52. [Google Scholar] [CrossRef]
  13. Kuo, T. From enumerating to generating: A linear time algorithm for generating 2D lattice paths with a given number of turns. Algorithms 2015, 8, 190–208. [Google Scholar] [CrossRef]
  14. The Combinatorial Object Server. Available online: http://combos.org/ (accessed on 1 May 2023).
  15. Barcucci, E.; Del Lungo, A.; Pergola, E.; Pinzani, R. ECO: A methodology for the enumeration of combinatorial objects. J. Differ. Equ. Appl. 1999, 5, 435–490. [Google Scholar] [CrossRef]
  16. Flajolet, P.; Zimmerman, P.; Cutsem, B. A calculus for the random generation of combinatorial structures. Theoret. Comput. Sci. 1994, 132, 1–35. [Google Scholar] [CrossRef]
  17. Shablya, Y.; Kruchinin, D.; Kruchinin, V. Method for developing combinatorial generation algorithms based on AND/OR trees and its application. Mathematics 2020, 8, 962. [Google Scholar] [CrossRef]
  18. Shablya, Y.; Tokareva, A. Development of combinatorial generation algorithms for some lattice paths using the method based on AND/OR trees. In Proceedings of the 5th Mediterranean International Conference of Pure & Applied Mathematics and Related Areas (MICOPAM), Antalya, Turkey, 27–30 October 2022. [Google Scholar]
  19. Mohanty, G. Lattice Path Counting and Applications; Academic Press: New York, NY, USA, 1979. [Google Scholar]
  20. The On-Line Encyclopedia of Integer Sequences. Available online: https://oeis.org/ (accessed on 1 May 2023).
  21. Mansour, T. Statistics on Dyck paths. J. Integer Seq. 2005, 9, 06.1.5. [Google Scholar]
  22. Banderier, C.; Schwer, S. Why Delannoy numbers? J. Statist. Plann. Inference 2005, 135, 40–54. [Google Scholar] [CrossRef]
  23. Shapiro, L.W.; Sulanke, R.A. Bijections for the Schroder numbers. Math. Mag. 2000, 73, 369–376. [Google Scholar] [CrossRef]
  24. Oste, R.; Van der Jeugt, J. Motzkin paths, Motzkin polynomials and recurrence relations. Electron. J. Combin. 2015, 22, P2.8. [Google Scholar] [CrossRef] [PubMed]
  25. Maxima, a Computer Algebra System. Available online: https://maxima.sourceforge.io/ (accessed on 1 May 2023).
  26. Kruchinin, V.; Shablya, Y.; Kruchinin, D. Unranking small combinations of a large set in co-lexicographic order. Algorithms 2022, 15, 36. [Google Scholar] [CrossRef]
  27. Deutsch, E.; Munarini, E.; Rinaldi, R. Skew Dyck paths. J. Statist. Plann. Inference 2010, 140, 2191–2203. [Google Scholar] [CrossRef]
  28. Prodinger, H. Skew Dyck paths with catastrophes. Discrete Math. Lett. 2022, 10, 9–13. [Google Scholar]
  29. Kruchinin, D.; Kruchinin, V.; Shablya, Y. On some properties of generalized Narayana numbers. Quaest. Math. 2022, 45, 1949–1963. [Google Scholar] [CrossRef]
Figure 1. All North-East lattice paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Figure 1. All North-East lattice paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Algorithms 16 00266 g001
Figure 2. An AND/OR tree for L n m .
Figure 2. An AND/OR tree for L n m .
Algorithms 16 00266 g002
Figure 3. An AND/OR tree for L 3 3 .
Figure 3. An AND/OR tree for L 3 3 .
Algorithms 16 00266 g003
Figure 4. All Dyck paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Figure 4. All Dyck paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Algorithms 16 00266 g004
Figure 5. An AND/OR tree for C n .
Figure 5. An AND/OR tree for C n .
Algorithms 16 00266 g005
Figure 6. An AND/OR tree for C 3 .
Figure 6. An AND/OR tree for C 3 .
Algorithms 16 00266 g006
Figure 7. All Delannoy paths beginning at ( 0 , 0 ) and ending at ( 3 , 2 ) .
Figure 7. All Delannoy paths beginning at ( 0 , 0 ) and ending at ( 3 , 2 ) .
Algorithms 16 00266 g007
Figure 8. An AND/OR tree for D n m .
Figure 8. An AND/OR tree for D n m .
Algorithms 16 00266 g008
Figure 9. An AND/OR tree for D 3 2 .
Figure 9. An AND/OR tree for D 3 2 .
Algorithms 16 00266 g009
Figure 10. All Schroder paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Figure 10. All Schroder paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Algorithms 16 00266 g010
Figure 11. An AND/OR tree for S n .
Figure 11. An AND/OR tree for S n .
Algorithms 16 00266 g011
Figure 12. An AND/OR tree for S 3 .
Figure 12. An AND/OR tree for S 3 .
Algorithms 16 00266 g012
Figure 13. All Motzkin paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Figure 13. All Motzkin paths beginning at ( 0 , 0 ) and ending at ( 3 , 3 ) .
Algorithms 16 00266 g013
Figure 14. An AND/OR tree for M n .
Figure 14. An AND/OR tree for M n .
Algorithms 16 00266 g014
Figure 15. An AND/OR tree for M 3 .
Figure 15. An AND/OR tree for M 3 .
Algorithms 16 00266 g015
Figure 16. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for L n m : (a) dependence on n when m = 100 ; and (b) dependence on m when n = 100 .
Figure 16. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for L n m : (a) dependence on n when m = 100 ; and (b) dependence on m when n = 100 .
Algorithms 16 00266 g016
Figure 17. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for C n .
Figure 17. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for C n .
Algorithms 16 00266 g017
Figure 18. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for D n m : (a) dependence on n when m = 50 ; and (b) dependence on m when n = 50 .
Figure 18. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for D n m : (a) dependence on n when m = 50 ; and (b) dependence on m when n = 50 .
Algorithms 16 00266 g018
Figure 19. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for S n .
Figure 19. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for S n .
Algorithms 16 00266 g019
Figure 20. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for M n .
Figure 20. Average time for unranking (blue) and ranking (red) variants of the AND/OR tree for M n .
Algorithms 16 00266 g020
Table 1. Ranking the set of North-East lattice paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Table 1. Ranking the set of North-East lattice paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Lattice PathVariant of AND/OR TreeRank
E , E , E , N , N , N ( 1 , 1 , 1 ) 0
E , E , N , E , N , N ( 1 , 1 , 2 , 1 ) 1
E , N , E , E , N , N ( 1 , 1 , 2 , 2 , 1 ) 2
N , E , E , E , N , N ( 1 , 1 , 2 , 2 , 2 ) 3
E , E , N , N , E , N ( 1 , 2 , 1 , 1 ) 4
E , N , E , N , E , N ( 1 , 2 , 1 , 2 , 1 ) 5
N , E , E , N , E , N ( 1 , 2 , 1 , 2 , 2 ) 6
E , N , N , E , E , N ( 1 , 2 , 2 , 1 , 1 ) 7
N , E , N , E , E , N ( 1 , 2 , 2 , 1 , 2 ) 8
N , N , E , E , E , N ( 1 , 2 , 2 , 2 ) 9
E , E , N , N , N , E ( 2 , 1 , 1 , 1 ) 10
E , N , E , N , N , E ( 2 , 1 , 1 , 2 , 1 ) 11
N , E , E , N , N , E ( 2 , 1 , 1 , 2 , 2 ) 12
E , N , N , E , N , E ( 2 , 1 , 2 , 1 , 1 ) 13
N , E , N , E , N , E ( 2 , 1 , 2 , 1 , 2 ) 14
N , N , E , E , N , E ( 2 , 1 , 2 , 2 ) 15
E , N , N , N , E , E ( 2 , 2 , 1 , 1 , 1 ) 16
N , E , N , N , E , E ( 2 , 2 , 1 , 1 , 2 ) 17
N , N , E , N , E , E ( 2 , 2 , 1 , 2 ) 18
N , N , N , E , E , E ( 2 , 2 , 2 ) 19
Table 2. Ranking the set of Dyck paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Table 2. Ranking the set of Dyck paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Lattice PathVariant of AND/OR TreeRank
E , E , E , N , N , N ( 0 , ( ) , ( 0 , ( ) , ( 0 , ( ) , ( ) ) ) ) 0
E , E , N , E , N , N ( 0 , ( ) , ( 1 , ( 0 , ( ) , ( ) ) , ( ) ) ) 1
E , N , E , E , N , N ( 1 , ( 0 , ( ) , ( ) ) , ( 0 , ( ) , ( ) ) ) 2
E , E , N , N , E , N ( 2 , ( 0 , ( ) , ( 0 , ( ) , ( ) ) ) , ( ) ) 3
E , N , E , N , E , N ( 2 , ( 1 , ( 0 , ( ) , ( ) ) , ( ) ) , ( ) ) 4
Table 3. Ranking the set of Delannoy paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 2 ) .
Table 3. Ranking the set of Delannoy paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 2 ) .
Lattice PathVariant of AND/OR TreeRank
E , E , E , N , N ( 1 , 1 ) 0
E , E , N , E , N ( 1 , 2 , 1 ) 1
E , N , E , E , N ( 1 , 2 , 2 , 1 ) 2
N , E , E , E , N ( 1 , 2 , 2 , 2 ) 3
N E , E , E , N ( 1 , 2 , 2 , 3 ) 4
E , N E , E , N ( 1 , 2 , 3 ) 5
E , E , N E , N ( 1 , 3 ) 6
E , E , N , N , E ( 2 , 1 , 1 ) 7
E , N , E , N , E ( 2 , 1 , 2 , 1 ) 8
N , E , E , N , E ( 2 , 1 , 2 , 2 ) 9
N E , E , N , E ( 2 , 1 , 2 , 3 ) 10
E , N E , N , E ( 2 , 1 , 3 ) 11
E , N , N , E , E ( 2 , 2 , 1 , 1 ) 12
N , E , N , E , E ( 2 , 2 , 1 , 2 ) 13
N E , N , E , E ( 2 , 2 , 1 , 3 ) 14
N , N , E , E , E ( 2 , 2 , 2 ) 15
N , N E , E , E ( 2 , 2 , 3 ) 16
E , N , N E , E ( 2 , 3 , 1 ) 17
N , E , N E , E ( 2 , 3 , 2 ) 18
N E , N E , E ( 2 , 3 , 3 ) 19
E , E , N , N E ( 3 , 1 ) 20
E , N , E , N E ( 3 , 2 , 1 ) 21
N , E , E , N E ( 3 , 2 , 2 ) 22
N E , E , N E ( 3 , 2 , 3 ) 23
E , N E , N E ( 3 , 3 ) 24
Table 4. Ranking the set of Schroder paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Table 4. Ranking the set of Schroder paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Lattice PathVariant of AND/OR TreeRank
N E , N E , N E ( 1 , ( 1 , ( 1 , ( ) ) ) ) 0
E , N , N E , N E ( 1 , ( 1 , ( 0 , ( ) , ( ) ) ) ) 1
E , N E , N , N E ( 1 , ( 0 , ( ) , ( 1 , ( ) ) ) ) 2
E , E , N , N , N E ( 1 , ( 0 , ( ) , ( 0 , ( ) , ( ) ) ) ) 3
N E , E , N , N E ( 1 , ( 1 , ( 1 , ( ) ) , ( ) ) ) 4
E , N , E , N , N E ( 1 , ( 1 , ( 0 , ( ) , ( ) ) , ( ) ) ) 5
E , N E , N E , N ( 0 , ( ) , ( 1 , ( 1 , ( ) ) ) ) 6
E , E , N , N E , N ( 0 , ( ) , ( 1 , ( 0 , ( ) , ( ) ) ) ) 7
E , E , N E , N , N ( 0 , ( ) , ( 0 , ( ) , ( 1 , ( ) ) ) ) 8
E , E , E , N , N , N ( 0 , ( ) , ( 0 , ( ) , ( 0 , ( ) , ( ) ) ) ) 9
E , N E , E , N , N ( 0 , ( ) , ( 1 , ( 1 , ( ) ) , ( ) ) ) 10
E , E , N , E , N , N ( 0 , ( ) , ( 1 , ( 0 , ( ) , ( ) ) , ( ) ) ) 11
N E , E , N E , N ( 1 , ( 1 , ( ) ) , ( 1 , ( ) ) ) 12
E , N , E , N E , N ( 1 , ( 0 , ( ) , ( ) ) , ( 1 , ( ) ) ) 13
N E , E , E , N , N ( 1 , ( 1 , ( ) ) , ( 0 , ( ) , ( ) ) ) 14
E , N , E , E , N , N ( 1 , ( 0 , ( ) , ( ) ) , ( 0 , ( ) , ( ) ) ) 15
N E , N E , E , N ( 2 , ( 1 , ( 1 , ( ) ) ) , ( ) ) 16
E , N , N E , E , N ( 2 , ( 1 , ( 0 , ( ) , ( ) ) ) , ( ) ) 17
E , N E , N , E , N ( 2 , ( 0 , ( ) , ( 1 , ( ) ) ) , ( ) ) 18
E , E , N , N , E , N ( 2 , ( 0 , ( ) , ( 0 , ( ) , ( ) ) ) , ( ) ) 19
N E , E , N , E , N ( 2 , ( 1 , ( 1 , ( ) ) , ( ) ) , ( ) ) 20
E , N , E , N , E , N ( 2 , ( 1 , ( 0 , ( ) , ( ) ) , ( ) ) , ( ) ) 21
Table 5. Ranking the set of Motzkin paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Table 5. Ranking the set of Motzkin paths beginning at  ( 0 , 0 ) and ending at  ( 3 , 3 ) .
Lattice pathVariant of AND/OR treeRank
N E , N E , N E ( 1 , ( 1 , ( 1 , ( ) ) ) ) 0
E , E , N , N , N E ( 1 , ( 0 , ( ) , ( ) ) ) 1
E , E , N E , N , N ( 0 , ( ) , ( 1 , ( ) ) ) 2
N E , E , E , N , N ( 1 , ( 1 , ( ) ) , ( ) ) 3
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Shablya, Y. Combinatorial Generation Algorithms for Some Lattice Paths Using the Method Based on AND/OR Trees. Algorithms 2023, 16, 266. https://doi.org/10.3390/a16060266

AMA Style

Shablya Y. Combinatorial Generation Algorithms for Some Lattice Paths Using the Method Based on AND/OR Trees. Algorithms. 2023; 16(6):266. https://doi.org/10.3390/a16060266

Chicago/Turabian Style

Shablya, Yuriy. 2023. "Combinatorial Generation Algorithms for Some Lattice Paths Using the Method Based on AND/OR Trees" Algorithms 16, no. 6: 266. https://doi.org/10.3390/a16060266

APA Style

Shablya, Y. (2023). Combinatorial Generation Algorithms for Some Lattice Paths Using the Method Based on AND/OR Trees. Algorithms, 16(6), 266. https://doi.org/10.3390/a16060266

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop