Combinatorial Generation via Permutation Languages. III. Rectangulations

A generic rectangulation is a partition of a rectangle into finitely many interior-disjoint rectangles, such that no four rectangles meet in a point. In this work we present a versatile algorithmic framework for exhaustively generating a large variety of different classes of generic rectangulations. Our algorithms work under very mild assumptions, and apply to a large number of rectangulation classes known from the literature, such as generic rectangulations, diagonal rectangulations, 1-sided/area-universal, block-aligned rectangulations, and their guillotine variants, including aspect-ratio-universal rectangulations. They also apply to classes of rectangulations that are characterized by avoiding certain patterns, and in this work we initiate a systematic investigation of pattern avoidance in rectangulations. Our generation algorithms are efficient, in some cases even loopless or constant amortized time, i.e., each new rectangulation is generated in constant time in the worst case or on average, respectively. Moreover, the Gray codes we obtain are cyclic, and sometimes provably optimal, in the sense that they correspond to a Hamilton cycle on the skeleton of an underlying polytope. These results are obtained by encoding rectangulations as permutations, and by applying our recently developed permutation language framework.


Introduction
Partitioning a geometric shape into smaller shapes is a fundamental theme in discrete and combinatorial geometry. In this paper we consider rectangulations, i.e., partitions of a rectangle into finitely many interior-disjoint rectangles. Such partitions have an abundance of practical applications, which motivates their combinatorial and algorithmic study. For example, rectangulations are an appealing way to represent geographic information as a cartogram. This is a map where each country is represented as a rectangle, the adjacencies between rectangles correspond to those between countries, and the areas of the rectangles are determined by some geographic variable, such as population size [26]. If the rectangulation is area-universal [12] or aspect-ratiouniversal [16], respectively, then such an adjacency-preserving cartogram can be drawn for any assignment of area values or aspect ratios to the rectangles. Another important use of rectangulations is as floorplans in VLSI design and architectural design. These problems often involve additional constraints on top of adjacency, such as extra space for wires [33] or proportion limits for the rooms [31]. An important notion in this context are slicing floorplans [33], also known as guillotine floorplans, i.e., floorplans that can be subdivided into their constituent rectangles by a sequence of straight vertical or horizontal cuts.
Rectangulations have rich combinatorial properties, and a task that has received a lot of attention is counting, i.e., determining the number of rectangulations of a particular type with n rectangles, either exactly as a function of n [43] or asymptotically as n grows [39]. This led to several beautiful bijections of rectangulations with patternavoiding permutations [1,4,36] or with twin binary trees [43]. The focus of this paper is on another fundamental algorithmic task, which is more fine-grained than counting, namely exhaustive generation, meaning that every rectangulation from a given class must be produced exactly once. While such generation algorithms are known for many other discrete objects such as permutations, combinations, subsets, trees etc. and covered in standard textbooks such as Knuth's [25], much less is known about the generation of geometric objects such as rectangulations.
The ultimate goal for a generation algorithm is to produce each new object in time O (1), which requires that consecutively generated objects differ only by a 'small local change'. Such a minimum change listing of combinatorial objects is often called a Gray code [38]. If the time bound O(1) for producing the next object holds in every step, then the algorithm is called loopless [11], and if it holds on average it is called constant amortized time (CAT) [37]. The Gray code problem entails the definition of a flip graph, which has as nodes all the combinatorial objects to be generated, and an edge between any two objects that differ in the specified small way. Clearly, computing a Gray code ordering of the objects is equivalent to traversing a Hamilton path or cycle in the corresponding flip graph. It turns out that some interesting flip graphs arising from rectangulations can be equipped with a natural lattice structure [29], analogous to the Tamari lattice on triangulations, and realized as polytopes in high-dimensional space [27], analogous to the associahedron (see [34] for generalizations). This ties in the Gray code problem with deep methods and results from lattice and polytope theory.

Our Results
The main contribution of this paper is a versatile algorithmic framework for generating a large variety of different classes of generic rectangulations, i.e., rectangulations with the property that no four rectangles meet in a point. In particular, we obtain efficient generation algorithms for several interesting classes known from the literature, in some cases loopless or CAT algorithms; see Table 1.
The initialization time and memory requirement for all these algorithms is linear in the number of rectangles. The classes of rectangulations shown in the table arise from generic rectangulations by imposing structural constraints, such as the guillotine property or forbidden configurations, or by equivalence relations, and they will be defined in Sect. 2.2. We implemented the algorithms generating the classes of rectangulations from the table in C++, and we made the code available for download and experimentation on the Combinatorial Object Server [45].
The classes of rectangulations that our algorithms can generate are not limited to the examples shown in Table 1, but can be described by the following closure property; see Fig. 1. Given an infinite class of rectangulations C, we require that if a rectangulation R is contained in C, then the rectangulation obtained from R by deleting the bottom-right rectangle is also in C, and the two rectangulations obtained from R by inserting a new rectangle at the bottom or right, respectively, are also in C (formal definitions of deletion and insertion are given in Sect. 2). If C satisfies this property, then our algorithms allow generating the set C n ⊆ C of all rectangulations from C with exactly n rectangles, for every n ≥ 1, by so-called jumps, a minimum change operation that generalizes simple flips, T-flips, and wall slides studied in [9,36] (the formal definition of jumps is in Sect. 3.1). Moreover, if the class C is symmetric, i.e., if R is in C then the rectangulation obtained from R by reflection at the diagonal from top-left to bottom-right is also in C, then the jump Gray code for C n is cyclic, i.e., the last rectangulation differs from the first one only by a jump. In other words, we not only obtain a Hamilton path in the corresponding flip graph, but a Hamilton cycle. In fact, all the classes of rectangulations listed in Table 1 satisfy the aforementioned closure and symmetry properties, so in all those cases we obtain cyclic jump Gray codes.
Generic rectangulations and diagonal rectangulations, shown in the first two rows of Table 1, have an underlying lattice and polytope structure [27,29], and in those two cases our Gray codes form a Hamilton cycle on the skeleton of this polytope, i.e., jumps are provably optimal minimum change operations. The Gray codes for these two rectangulation classes with n = 1, . . . , 5 rectangles are shown in Appendix D. It turns out that many interesting classes of rectangulations can be characterized by pattern avoidance; see the second column in Table 1. Under very mild conditions on the patterns, these classes satisfy the aforementioned closure property, and can hence be generated by our framework. In this work we initiate a systematic investigation of pattern avoidance in rectangulations, and we obtain the first counting results for many known and new classes; see the third column in Table 1 and the more extensive table in Sect. 9.
Our generation framework for rectangulations consists of two main algorithms. The first is a simple greedy algorithm that generates a jump Gray code ordering for any set of rectangulations C n ⊆ C for which C satisfies the aforementioned closure property; see Algorithm J and Theorem 3.3 in Sect. 3. The second is a memoryless version of the first algorithm, which computes the same ordering of rectangulations; see Algorithm M and Theorem 5.1 in Sect. 5. This algorithm can be fine-tuned to derive efficient algorithms for several known rectangulation classes such as the ones listed in Table 1, by providing corresponding jump oracles for the class C.
To prove Theorems 3.3 and 5.1, we encode rectangulations by permutations as described by Reading [36], and we then apply our framework for exhaustively generating permutation languages presented in [20][21][22]. The minimum change operations on permutations used in that framework translate to jumps on rectangulations. Generating different classes of rectangulations efficiently is thus another major new application of our permutation language framework, and in this paper we flesh out the details of this application.

Related Work
There has been some prior work on generating a few special classes of rectangulations, all based on Avis and Fukuda's reverse search method [6]. Specifically, Nakano [32] described a CAT generation algorithm for generic rectangulations, which does not produce a Gray code, however. This algorithm has been adapted by Takagi and Nakano [40] to generate generic rectangulations with bounds on the number of rectangles that do not touch the outer face. Yoshii et al. [44] gave a Gray code for generic rectangulations based on a generating tree that is different from ours, resulting in a loopless algorithm. Their Gray code changes at most three edges of the rectangulation in each step, whereas our algorithm changes only 1 edge in each step for generic and for diagonal rectangulations. Consequently, none of the listings produced by these earlier algorithms corresponds to a walk along the skeleton of the underlying polytope.
There has been a lot of work on combinatorial properties of rectangulations. Yao et al. [43] showed that diagonal rectangulations are counted by the Baxter numbers and that guillotine diagonal rectangulations are counted by the Schröder numbers, using a bijection between diagonal rectangulations and twin binary trees. Ackerman et al. [1] presented another bijection between diagonal rectangulations and Baxter permutations, which also yields a bijection between guillotine diagonal rectangulations and separable permutations. Leifheit [28] showed that this bijection can be restricted to the 1-sided variants of these two rectangulation classes by adding two permutation patterns; see Table 1. Shen and Chu [39] provided asymptotic estimates for diagonal rectangulations and their guillotine variant. Moreover, He [18] presented an optimal encoding of diagonal rectangulations with n rectangles using only 3n − 3 bits, which is optimal.
The term 'generic rectangulation' was coined by Reading [36], who established a bijection between generic rectangulations and 2-clumped permutations, proving that these permutations are representatives of equivalence classes of a lattice congruence of the weak order on the symmetric group. Earlier, generic rectangulations had been studied under the name 'rectangular drawings' by Amano et al. [3] and by Inoue et al. [15,23], who established recursion formulas and asymptotic bounds for their number. More general classes of rectangular partitions were analyzed by Conant and Michaels [10].
Ackerman et al. [2] considered the setting where we are given a set of n points in general position in a rectangle, and the goal is to partition the rectangle into smaller rectangles by n walls, such that each point from the set lies on a distinct wall. They showed that for every set of points that forms a separable permutation in the plane, the number of possible rectangulations is the (n + 1)st Baxter number, and for every point set the number of possible guillotine rectangulations is the nth Schröder number. They also presented a counting and generation procedure based on simple flips and T-flips using reverse search, which was later improved by Yamanaka et al. [42].

Outline of This Paper
In Sect. 2 we provide basic definitions and concepts that will be used throughout the paper. In Sect. 3 we present a greedy algorithm for generating a set of rectangulations by jumps, and we provide a sufficient condition for the algorithm to succeed. In Sect. 4 we show that the algorithm applies to a large number of rectangulation classes that are characterized by pattern avoidance. In Sect. 5 we demonstrate how to make our generation algorithm memoryless and efficient. The data structures and basic functions used by our algorithms are provided in Sects. 6 and 7. The proofs of Theorems 3.3 and 5.1 are presented in Sect. 8, by establishing a connection between rectangulations and permutations and by applying our permutation language framework. In Sect. 9 we  Table 1 are deferred to Appendices A and B, as well as several visualizations of Gray codes produced by our algorithms.

Generic Rectangulations
A generic rectangulation, or rectangulation for short, is a partition of a rectangle into finitely many interior-disjoint axis-aligned rectangles, such that no four rectangles of the partition have a point in common; see Fig. 2. In other words, every point where three rectangles meet, or where two rectangles meet the outer face forms a T-joint with the incident rectangle boundaries. Given rectangles r and s, we say that r is left of s, and s is right of r , if the right side of r intersects the left side of s (necessarily in a line segment, rather than a single point). Similarly, we say that r is below s, and s is above r , if the top side of r intersects the bottom side of s. We consider generic rectangulations up to equivalence that preserves the left/right and below/above relations between rectangles, and we use R n , n ≥ 1, to denote the set of all rectangulations with n rectangles. We write for the unique rectangulation in R 1 , i.e., the rectangulation consisting of a single rectangle.
We refer to every rectangle corner in a rectangulation as a vertex, to every minimal line segment between two vertices as an edge, and to every maximal line segment between two vertices that are not corners of the rectangulation as a wall. The type of a vertex that is not a corner of the rectangulation describes the shape of the T-joint at this vertex, and it is one of , , ⊥, or .

Flip Operations and Classes of Rectangulations
Our Gray codes use three types of local change operations on rectangulations; see Fig. 3.
A wall slide swaps the order of two neighboring vertices of types and along a vertical wall, or of types and ⊥ along a horizontal wall. A simple flip swaps the orientation of a wall that separates two rectangles. Given a vertex v that belongs to three rectangles, we consider the wall w that goes through v and the wall t that ends at v, and we let w and w be the two halves of w meeting in v. If w or w is an edge, respectively, then a T-flip swaps the orientation of this edge so that it merges with t.
We now define various interesting subclasses of generic rectangulations that have been studied in the literature and that appear in Table 1. Examples illustrating these classes are in Fig. 4. A diagonal rectangulation is one in which every rectangle intersects the main diagonal that goes from the top-left to the bottom-right corner of the rectangulation. We write D n ⊆ R n for the set of all diagonal rectangulations with n rectangles. Diagonal rectangulations are characterized by avoiding the wall patterns and [9]. Consider the equivalence relation on R n obtained from wall slides, sometimes referred to as R-equivalence [4]. The equivalence classes are referred to as mosaic floorplans, and every equivalence class contains exactly one diagonal rectangulation, obtained by repeatedly destroying occurrences of or by wall slides [9]. Consequently, in a diagonal rectangulation, along every vertical wall, all -vertices are below all -vertices, and along every horizontal wall, all ⊥-vertices are to the left of all -vertices.
In a 1-sided rectangulation, every wall is the side of at least one rectangle, i.e., these rectangulations are characterized by avoiding the four patterns , , , and . The notion of 1-sidedness was introduced by Eppstein et al. [12] to characterize area-universal rectangulations, i.e., for any assignment of areas to the Examples of different classes of rectangulations: a diagonal, but neither 1-sided nor guillotine, b 1-sided, but not guillotine, c guillotine, but not diagonal, d guillotine and 1-sided. Occurrences of the corresponding forbidden patterns are highlighted rectangles, the rectangulation can be drawn so that each rectangle has the prescribed area.
Asinowski et al. [4] also considered the equivalence relation on R n obtained from wall slides and simple flips, and they called it S-equivalence. By definition, S-equivalence is a coarser relation than R-equivalence, i.e., the equivalence classes are obtained by identifying mosaic floorplans that differ in simple flips. In Appendix B we introduce block-aligned rectangulations, which are a subset of diagonal rectangulations with the property that every equivalence class of S-equivalence contains exactly one block-aligned rectangulation.
A rectangulation is guillotine, if each of its rectangles can be cut out from the entire rectangulation by a sequence of straight vertical or horizontal cuts. Guillotine rectangulations are characterized by avoiding the windmill patterns and , which is a folklore result. Various special classes of guillotine diagonal rectangulations, characterized by the avoidance of certain wall configurations, were introduced by Asinowski and Mansour [5] (see Sect. 4 for precise definitions of these configurations). Mosaic floorplans that are guillotine are also known as slicing floorplans.
Felsner, Nathenson, and Tóth [16] showed that 1-sided guillotine rectangulations are precisely the aspect-ratio-universal rectangulations, i.e., for any assignment of aspect ratios to the rectangles, the rectangulation can be drawn so that each rectangle has the prescribed aspect ratio.

Deletion of Rectangles
We now describe two operations on a generic rectangulation R, namely deleting a rectangle and inserting a rectangle. The resulting rectangulations will be denoted by p(R) and c i (R), notations that refer to the parent and children of R, in a tree structure that will be discussed shortly. The deletion and insertion operations were introduced in [19] and heavily used e.g. in [1] and [32].
The idea of deletion is to contract the rectangle in the bottom-right corner of the rectangulation. Formally, given a rectangulation R ∈ R n , n ≥ 2, we consider the rectangle r in the bottom-right corner, and we consider the top-left vertex of r . If this vertex has type , then we collapse r by sliding its top side, which forms a wall, downwards until it merges with the bottom side of r ; see . . . p(R) = R [8] p 2 (R) = R [7] p 3 (R) = R [6] R   Fig. 6 A rectangulation and the indexing of its rectangles given by repeated deletion vertex has type , then we collapse r by sliding its left side, which forms a wall, to the right until it merges with the right side of r ; see Fig. 5b. We denote the resulting rectangulation with n−1 rectangles by p(R) ∈ R n−1 , and we say that p(R) is obtained from R by deletion.
Moreover, we denote the n rectangles of R by r n , r n−1 , . . . , r 1 in the order in which they are deleted when applying the deletion operation exhaustively; see Fig. 6. Clearly, if r i is deleted and its top-left vertex has type , then the rightmost rectangle above r i is r i−1 . Similarly, if the top-left vertex has type , then the lowest rectangle to the left of r i is r i−1 .
For any R ∈ R n and i = 1, . . . , n we define R [i] := p n−i (R), i.e., this is the sub-rectangulation of R formed by the first i rectangles; see Fig. 6.

Insertion of Rectangles
The idea of insertion is to add a new rectangle into the bottom-right corner of the rectangulation. Given a rectangulation R ∈ R n−1 , we first define a set of points in R that can become the top-left corner of the newly added rectangle; see Fig. 7.
For any rectangle r in R ∈ R n−1 , n ≥ 2, that touches the bottom boundary of R, we consider all edges forming the left side of r , and from every such edge we select one interior point, and we refer to it as a vertical insertion point. Similarly, for any rectangle r in R that touches the right boundary of R, we consider the set of all edges forming the top side of r , and from every such edge we select one interior point, and we refer to it as a horizontal insertion point. Combinatorially it does not make a difference which interior point of each edge is selected.
We order the insertion points linearly, by sorting all vertical insertion points lexicographically by their (x, y)-coordinates, followed by all horizontal insertion points sorted lexicographically by their (y, x)-coordinates; see Fig. 7. We write I (R) = (q 1 , q 2 , . . . , q ν ) for the sequence of all insertion points ordered in this linear order. In particular, ν = ν(R) denotes the number of insertion points.

Lemma 2.1 For any rectangulation R
Proof Each rectangle in R has at most one vertical insertion point on its right side, and at most one horizontal insertion point on its bottom side. Moreover, no rectangle has both, the bottom-right rectangle r n−1 has neither of the two, and exactly two insertion points lie on the boundary of R. Combining these observations shows that ν(R) ≤ ((n − 1) − 1) + 2 = n.
Clearly, the upper bound in Lemma 2.1 is attained if every rectangle touches the bottom or right boundary of R.
Given R ∈ R n and the sequence of insertion points I (R) = (q 1 , . . . , q ν ), for each i = 1, . . . , ν we define a rectangulation c i (R) ∈ R n as follows: If q i is a vertical insertion point, then c i (R) is obtained from R by inserting a new rectangle r n in the bottom-right corner such that r n has above it exactly all rectangles which in R lie to the right of q i and touch the bottom boundary of R, and such that r n has to its left exactly all rectangles which in R touch the vertical wall through q i below q i ; see Fig. 8a. Similarly, if q i is a horizontal insertion point, then c i (R) is obtained from R by inserting a new rectangle r n in the bottom-right corner such that r n has to its left exactly all rectangles which in R lie below q i and touch the right boundary of R, and such that r n has above it exactly all rectangles which in R touch the horizontal wall through q i to the right of q i ; see Fig. 8b. We say that c i (R) is obtained from R by insertion.

Fig. 8 Insertion operation
By these definitions, the operations of deletion and insertion are inverse to each other, which we record in the following lemma.

Lemma 2.2
For any rectangulation R ∈ R n−1 and any two distinct insertion points q i and q j from I (R), the rectangulations c i (R) ∈ R n and c j (R) ∈ R n are distinct, and we have R = p(c i (R)) = p(c j (R)). Moreover, for any R ∈ R n with p(R ) = R there is an insertion point q i in I (R) such that c i (R) = R .
The first and last insertion point play a special role in our arguments, which is why they are highlighted in Fig. 8. We say that R is bottom-based if R has a rectangle whose bottom side is the entire bottom boundary of R, and R is right-based if R has a rectangle whose right side is the entire right boundary of R. Note that the rectangulation ∈ R 1 is both bottom-based and right-based, and if n ≥ 2, then R ∈ R n is bottom-based if and only if R = c 1 ( p(R)) and right-based if and only if R = c ν( p(R)) ( p(R)).

The Basic Algorithm
In this section we present the basic algorithm that we use to generate a set of rectangulations C n ⊆ R n .

Jumps in Rectangulations
To state the algorithm, we first introduce a local change operation that generalizes the three kinds of flips introduced in Sect. 2.2 (recall Fig. 3) and that will be applied when moving from one rectangulation in C n to the next in the algorithm. A jump changes the insertion point for exactly one rectangle of the rectangulation. Formally, for a rectangulation R ∈ R n , we say that R ∈ R n differs from R by a right jump of rectangle r j by d steps, denoted R = #" J (R, j, d), where 2 ≤ j ≤ n and d > 0, if one of the following conditions holds; see • j = n, and we have p(R) = p(R ) =: P ∈ R n−1 , R = c k (P), and R = c k+d (P) for some k > 0; • j < n, and R and R are either both bottom-based or both right-based, and p(R ) differs from p(R) in a right jump of rectangle r j by d steps.
In words, the first condition asserts that the first n − 1 rectangles in R and R form the same rectangulation P ∈ R n−1 , and R and R are obtained by insertion from P using the kth and (k + d)th insertion point, respectively. The second condition asserts that R and R agree in the rectangle r n , which either forms the bottom boundary or the right boundary of those rectangulations, and p(R ) differs from p(R) in a right jump with the same parameters. A right jump as before is called minimal w.r.t. to a set of rectangulations C n ⊆ R n , if in the first condition above there is no index with k < < k + d such that , is defined analogously by replacing c k+d by c k−d and k < < k +d by k > > k −d in the definitions above. Clearly, if R differs from R by a right jump of rectangle r j by d steps, then R differs from R by a left jump of rectangle r j by d steps, and vice versa, i.e., we have R = #" J (R, j, d) if and only if R = # " J (R , j, d). We sometimes simply say that R and R differ in a jump, without specifying the direction left or right.
We state the following simple observations for further reference; see Fig. 9.  For any rectangulation R ∈ R n , we say that two insertion points from I (R) belong to the same vertical or horizontal group, if they lie on the same vertical or horizontal wall in R, respectively. In the sequence I (R), insertion points belonging to the same group appear consecutively.

Generating Rectangulations by Minimal Jumps
Consider the following algorithm that attempts to greedily generate a set of rectangulations C n ⊆ R n using minimal jumps.
Algorithm J (greedy minimal jumps). This algorithm attempts to greedily generate a set of rectangulations C n ⊆ R n using minimal jumps starting from an initial rectangulation R 0 ∈ C n . J1.
[Jump] Generate an unvisited rectangulation from C n by performing a minimal jump of the rectangle with largest possible index in the most recently visited rectangulation. If no such jump exists, or the jump direction is ambiguous, then terminate. Otherwise visit this rectangulation and repeat J2.
To illustrate how Algorithm J works, we consider the set of five rectangulations C 4 = {R 1 , . . . , R 5 } ⊆ R 4 shown in Fig. 11. If initialized with R 0 := R 1 , then the algorithm performs a left jump of rectangle 4 by one step (a right jump of rectangle 4 is impossible) to reach R 2 , i.e., we have R 2 = # " J (R 1 , 4, 1). In R 2 , there are two options, Example execution of Algorithm J either a right jump of rectangle 4 by one step, leading back to R 1 , which has been visited before, or a left jump of rectangle 4 by two steps, leading to R 3 , so we visit 4,2). In R 3 , the jumps involving rectangle 4 lead to rectangulations that were visited before (R 1 and R 2 ). Moreover, a jump of rectangle 3 does not lead to a rectangulation in C 4 . However, a right jump of rectangle 2 by one step leads to R 4 (a left jump of rectangle 2 is impossible), so we visit R 4 = #" J (R 3 , 2, 1). Finally, in R 4 a right jump of rectangle 4 by two steps leads to R 5 = #" J (R 4 , 4, 2) (a left jump of rectangle 4 is impossible). In this example, Algorithm J successfully visits every rectangulation from C 4 exactly once.
On the other hand, suppose we instead initialize the algorithm with R 0 := R 3 . The algorithm will then visit R 2 := #" J (R 3 , 4, 2) followed by R 1 := #" J (R 2 , 4, 1), and then terminates without success, as from R 1 no jump leads to an unvisited rectangulation from C 4 . Lastly, suppose we initialize Algorithm J with R 0 := R 2 . As before, in R 2 , there are two possibilities, either a right jump or a left jump of rectangle 4, both leading to an unvisited rectangulation from C 4 . Both are minimal jumps in opposite directions, and as the jump direction is ambiguous, the algorithm terminates immediately without success.

Remark 3.2
We do not recommend using Algorithm J in the stated form to generate a set of rectangulations efficiently! This is because the algorithm requires to maintain the list of all previously visited rectangulations (possibly exponentially many), and to look up this list in each step to check whether a rectangulation obtained by a jump from the current one has been visited before. For us, Algorithm J is merely a tool to define a Gray code ordering of the rectangulations in the given set C n in way that is easy to remember (cf. [41]). In fact, in Sect. 5 we will present a modified algorithm that dispenses with the costly lookup operations, and that computes the very same sequence of rectangulations.

A Guarantee for Success
By definition, Algorithm J visits every rectangulation from a given set C n ⊆ R n at most once, but it may terminate before having visited all. We now provide a sufficient condition guaranteeing that Algorithm J visits every rectangulation from C n exactly once.
A set of generic rectangulations C n ⊆ R n is called zigzag, if either n = 1 and C 1 = { }, or if n ≥ 2 and C n−1 := { p(R) | R ∈ C n } is zigzag and for every R ∈ C n−1 we have c 1 (R) ∈ C n and c ν(R) (R) ∈ C n . In words, the set C n must be closed under repeatedly deleting bottom-right rectangles and replacing them by rectangles inserted either below or to the right of the remaining ones; recall Fig. 1. The name 'zigzag' does not refer to the shape of a rectangulation, but to the order in which they are visited by Algorithm J , which will become clear momentarily. We also say that C n is symmetric, if reflection at the main diagonal is an involution of C n , i.e., if R ∈ C n , then the rectangulation obtained from R by reflection at the main diagonal is also in C n . We write ... n for the rectangulation that consists of n vertically stacked rectangles. Theorem 3.3 Given any zigzag set of rectangulations C n and initial rectangulation R 0 = ... n , Algorithm J visits every rectangulation from C n exactly once. Moreover, if C n is symmetric, then the ordering of rectangulations generated by Algorithm J is cyclic, i.e., the first and last rectangulation differ in a minimal jump.
The proof of Theorem 3.3 is provided in Sect. 8.
Note that the rectangulation R 0 = ... n is contained in every zigzag set by definition, so this is a valid initialization for Algorithm J . We write J (C n ) for the sequence of rectangulations generated by Algorithm J for a zigzag set C n when initialized with It is easy to see that the number of distinct zigzag sets of generic rectangulations is at least 2 |R n |(1−o(1)) ≥ 2 (11.56 n ) (the latter estimate uses the best known lower bound on |R n | from [3]), i.e., at least double-exponential in n. In other words, Algorithm J exhaustively generates a given set of generic rectangulations in a vast number of cases. Moreover, many natural classes of rectangulations are in fact zigzag. In particular, all the different classes introduced in Sect. 2.2 and shown in Table 1 satisfy the aforementioned closure property. Moreover, all of these classes are symmetric, so for each of them we obtain cyclic jump orderings. Several such Gray codes are visualized in Appendix D.

Tree of Rectangulations
The notion of zigzag sets and the operation of Algorithm J can be interpreted combinatorially in the so-called tree of rectangulations, which is an infinite rooted tree, defined recursively as follows; see Fig. 12: The root of the tree is a single rectangle ∈ R 1 . For any node R ∈ R n−1 , n ≥ 2, of the tree we consider all insertion points of the rectangulation R, and the set of children of R in the tree is {c i (R) ∈ R n | i = 1, . . . , ν(R)}. Conversely, the parent of each R ∈ R n , n ≥ 2, is p(R) ∈ R n−1 . In words, insertion leads to the children of a node, and deletion leads to the parent of a node. By Lemma 2.2, each generic rectangulation appears exactly once in the tree, and the set of nodes at distance n from the root of the tree is precisely the set R n+1 of generic rectangulations with n + 1 rectangles. We emphasize that this tree is unordered, i.e., there is no specified ordering among the children of a node. By Lemma 2.1, a node R ∈ R n in the tree has at most n + 1 children, i.e., we have |R n | ≤ n!. As we see from Fig. 12, this inequality is tight up to n = 4, but starting from n = 4, there are nodes R ∈ R n with strictly less than n + 1 children, i.e., we have |R 5 | < 5!. In fact, it was shown in [3] that |R n | = O(28.3 n ).
A subset C n ⊆ R n of nodes in depth n − 1 of this tree is zigzag, if and only if it arises from the full tree of rectangulations by pruning some subtrees whose roots are neither bottom-based nor right-based rectangulations. In Fig. 12, all bottom-based or right-based rectangulations are highlighted by gray boxes, and can therefore not be pruned, while all other nodes can possibly be pruned. If no nodes are pruned, then we have C n = R n , and if all possible nodes are pruned, then C n is the set B n of 2 n−1 rectangulations obtained by repeatedly stacking a new rectangle either below or to the right of the previous ones, i.e., B n = {c 1 (R), c ν(R) (R) | R ∈ B n−1 } for n ≥ 2 and B 1 = { }. Moreover, we have B n ⊆ C n ⊆ R n for any zigzag set C n .
The operation of Algorithm J for a zigzag set C n as input can be interpreted as follows: Given the pruned tree corresponding to C n , we consider the set of nodes on all previous levels of the tree, i.e., the sets C i−1 := { p(R) | R ∈ C i } for i = n, n−1, . . . , 2, which are all zigzag sets by definition. Moreover, we consider the orderings J (C i ), i = 1, . . . , n, defined by Algorithm J for each of these sets. These sequences turn the unordered tree corresponding to C n into an ordered tree, where the children c i (R) of each node R from left to right appear alternatingly in increasing order i = 1, . . . , ν(R) or in decreasing order i = ν(R), ν(R) − 1, . . . , 1. Consequently, in the sequence J (C i ), i ≥ 2, which forms the left-to-right sequence of all nodes in depth i − 1 of this ordered tree, the rectangle r i alternatingly jumps left and right between the first and last insertion point, which motivates the name 'zigzag' set; see also the animations provided in [45].
It is important to realize that these orderings are not consistent with respect to taking subsets, i.e., if we have two zigzag sets C n ⊆ C n , then the entries of the sequence J (C n ) do not necessarily appear in the same relative order in the sequence J (C n ).

Pattern-Avoiding Rectangulations
In this section we show that Algorithm J applies to a large number of rectangulation classes that are defined by pattern avoidance, under some very mild conditions on the patterns; recall Table 1.
A rectangulation pattern is a configuration of walls with prescribed directions and incidences. For example, the windmill patterns and describe four walls such that when considering the walls in clockwise or counterclockwise order, respectively, the end vertex of one wall lies in the interior of the next wall. We can also think of a pattern as the rectangulation formed by the given walls and incidences. For example, we can think of the windmill patterns as rectangulations with five rectangles. We say that a rectangulation R contains the pattern P, if R contains a subset of walls with the directions and incidences specified by P. Otherwise we say that R avoids P. For any set of rectangulation patterns P and for any set of rectangulations C, we write C(P) for the rectangulations from C that avoid each pattern from P. For example, diagonal rectangulations are given by D n = R n , . Examples of rectangulations containing and avoiding various patterns are shown in Fig. 4.
We say that a rectangulation pattern P is tame, if for any rectangulation R that avoids P, we also have that c 1 (R) and c ν(R) (R) avoid P. In words, inserting a new rectangle below R or to the right of R must not create the forbidden pattern P. The next lemma follows directly from these definitions. , each of the patterns  ,  ,  ,  ,  , , , is tame.

Lemma 4.1 If a rectangulation pattern is neither bottom-based nor right-based, then it is tame. In particular
The following powerful theorem allows to obtain many new zigzag sets of rectangulations from a given zigzag set C n ⊆ R n by forbidding one or more tame patterns. All of these zigzag sets can then be generated by our Algorithm J . Theorem 4.2 Let C n ⊆ R n be a zigzag set of rectangulations, and let P be a set of tame rectangulation patterns. Then C n (P) is a zigzag set of rectangulations. Moreover, if P is symmetric, then C n (P) is symmetric.
Recall that P is symmetric if for each pattern P ∈ P, we have that the pattern obtained from P by reflection at the main diagonal is also in P. The significance of the second part of the theorem is that if C n (P) is symmetric, then the ordering of rectangulations of C n (P) generated by Algorithm J is cyclic by Theorem 3.3.
Proof As C n is a zigzag set of rectangulations, we know that . . , 2 are also zigzag sets. We argue by induction that C i (P) is also a zigzag set for all i = 1, . . . , n. For the induction basis i = 1 note that the rectangulation that consists of a single rectangle has no walls, so it avoids any pattern, showing that C 1 (P) = C 1 = { }. For the induction step we assume that , which is guaranteed by the assumption that each pattern P ∈ P is tame. This proves the first part of the theorem.
It remains to prove the second part. If R ∈ C n (P), then R avoids every pattern from P. Let R be the rectangulation obtained from R by reflection at the main diagonal. R must also avoid every pattern from P, because if it contained a pattern P from P, then R would contain the corresponding reflected pattern P , which is in P because of the assumption that P is symmetric. It follows that R ∈ C n (P), completing the proof.

Efficient Computation
Recall from Remark 3.2 that Algorithm J in its stated form is unsuitable for efficient implementation. We now discuss how to make the algorithm efficient, so as to achieve the time bounds claimed in Table 1 for several interesting classes of rectangulations.

Memoryless Algorithm
Consider Algorithm M below, which takes as input a zigzag set of rectangulations C n ⊆ R n and generates them exhaustively by minimal jumps in the same order as Algorithm J , i.e., in the order J (C n ). After initialization in line M1, the algorithm loops over lines M2-M5, visiting the current rectangulation R at the beginning of each iteration (line M2), until it terminates (line M3).
The key idea of the algorithm is to track explicitly which rectangle jumps in each step, and the direction of the jump. With this information, the jump is determined by the condition that it must be minimal w.r.t. C n , i.e., starting from the current insertion point of the given rectangle, we choose the first insertion point (w.r.t. their linear ordering) for that rectangle in the given direction that creates the next rectangulation from C n .
Algorithm M (memoryless minimal jumps). This algorithm generates all rectangulations of a zigzag set C n ⊆ R n by minimal jumps in the same order as The array s = (s 1 , . . . , s n ) is used to determine which rectangle jumps in each step. Specifically, the last entry s n determines the rectangle that jumps in the current iteration (line M3). This array simulates a stack in a loopless fashion, following an idea first used by Bitner et al. [7]. The stack is initialized by (s 1 , . . . , s n ) = (1, 2, . . . , n) (line M1), with s n being the value on the top of the stack. The stack is popped (by the instruction s j ← s j−1 in line M5) when rectangle r j reaches its first or last insertion point in this step, meaning that this rectangle is not eligible to jump in the next step, but becomes eligible again after the next step, which is achieved by pushing the value j on the stack again (by the instructions s n ← n and s j−1 ← j − 1 in line M5). Table 2 shows the execution of Algorithm M with input C 4 = D 4 being the set of all diagonal rectangulations with four rectangles.

Theorem 5.1
For any zigzag set of rectangulations C n ⊆ R n , Algorithm M visits every rectangulation from C n exactly once, in the order J (C n ) defined by Algorithm J .
The proof of Theorem 5.1 is provided in Sect. 8. To make meaningful statements about the running time of Algorithm M , we need to specify the data structures used to represent the current rectangulation R, and the operations on this data structure to Table 2 Execution of Algorithm M for the set C 4 = D 4 of diagonal rectangulations with four rectangles. Empty entries in the o and s column are unchanged compared to the previous row perform jumps in line M4 and to check the bottom-based and right-based property in line M5. Most importantly, we will develop oracles which efficiently compute the next minimal jump w.r.t. C n for some interesting zigzag sets C n . One should think of C n here as a class of rectangulations specified by some properties or forbidden patterns, such as 'diagonal guillotine rectangulations', and not as a large precomputed set of rectangulations. All of these details are described in the following sections, and they are part of our C++ implementation provided in [45].

Data Structures and Basic Functions
In the following we describe the data structures we use to represent and manipulate generic rectangulations, and the efficient implementation of jump operations using those data structures.

Data Structures
We represent a generic rectangulation with n rectangles as follows; see Fig. 13: Rectangles are stored in the variables r 1 , . . . , r n , indexed by the reverse deletion order described in Sect. 2.3 (recall Fig. 6). Vertices and edges are stored in variables v 1 , . . . , v 2n+2 and e 1 , . . . , e 3n+1 , respectively (indexed in no particular order). Each vertex v points to the edges incident to it in the four directions by v.north, v.east, v.south, and v.west. Some of these can be 0, indicating that no edge is incident. This information determines the type v.type, which is one of , , ⊥, , or 0 at the corner vertices of the rectangulation. We give all edges a default orientation from left to right, or from bottom to top. The dir entry of each edge e specifies its direction, which is either e.dir = for a horizontal edge or e.dir = for a vertical edge. Each edge e points to its two end vertices, specifically to its tail by e.tail and to its head by e.head (with respect to the default orientation). It also points to the previous and next edge, in the direction of its orientation, by e.prev and e.next, respectively, which can be 0 if no such edge exists. The rectangle to the left and right side of an edge e, in the direction of its orientation, are stored in e.left and e.right, which can be 0 at the boundary of the rectangulation. Each rectangle r points to its four corner vertices by r .neast, r .seast, r .swest, and r .nwest in the corresponding directions.
For some rectangulation classes it is useful to store information about walls, i.e., maximal sequences of edges between two vertices that are not corners of the rectangulation. These are stored in w 1 , . . . , w n+3 , where for simplicity we also keep track of the four maximal line segments between corners of the rectangulation (which are not walls in our definition). We also think of walls having a default orientation from left to right, or from bottom to top, and each wall w points to its first and last vertex by w.first and w.last, respectively, in the direction of its orientation. Moreover, each edge e has an entry e.wall pointing to the wall that contains it.

Remark 6.1
The aforementioned data structures are natural in the sense that they also capture the dual graph of the rectangulation, i.e., the graph obtained by replacing every rectangle by a vertex, and by joining any two vertices that correspond to rectangles sharing a common edge. This allows constructing the so-called transversal structure [17] (also known as regular edge labeling [24]), which is useful for computing a layout of the rectangulation; see Felsner's survey [13]. Our data structures also allow to easily extract the twin binary tree representation of diagonal rectangulations described in [43].
We now use these data structures for implementing jumps efficiently. Recall the conditions stated in Lemma 3.1 when a jump is one of the three flip operations shown in Fig. 3. We refer to a jump as in (a), (b), or (c) in the lemma as a W-jump, S-jump, or T-jump, respectively. By these definitions, a W-jump is a special wall slide, an S-jump is a special simple flip, and a T-jump is a special T-flip. We refer to W-, S-and T-jump as local jumps collectively. Moreover, a W-jump or T-jump between two horizontal insertion points, or between two vertical insertion points, is referred to as a horizontal or vertical W-or T-jump, respectively.
Consider two rectangulations R and R that differ in a jump of rectangle r j . If the jump is an S-jump or a horizontal T-jump, we let h(R, R ) denote the number of horizontal insertion points of  Clearly, every jump can be performed as a sequence of local jumps, and then the time bounds given by Lemma 6.2 can be added up. Proof The time bounds follow from the number of incidences that change during local jumps. The crucial point is that during a jump of rectangle r j between R and R , all rectangles r k for k = j + 1, . . . , n are right-based or bottom-based in R [k] and R [k] , entailing that only constantly many incidences with such rectangles have to be modified.

Auxiliary Functions
In Sect. 6.3 we provide implementations of local jumps with the runtime guarantees stated in Lemma 6.2. Before doing so, we introduce some auxiliary functions to add and remove edges from a rectangulation. These auxiliary functions only update the incidences between edges, vertices and walls, but not the incidences between rectangles and any other objects and the type of vertices (this will be done separately later).
The following function remHead(β) removes the edge e β together with its head vertex.
After defining some auxiliary variables in the first step, the function remHead(β) updates the incidences between edges and vertices in the second step, and the incidences between walls and edges in the third step. We also define an analogous function remTail(β) that removes e β and its tail instead of its head. For details, see our C++ implementation [45].
The following two functions insBefore(β, a, γ ) and insAfter(α, a, β) insert the edge e β with head v a or tail v a , respectively, before or after the edge e γ or e α .

Local Jumps
Armed with these auxiliary functions, we now tackle the implementation of local jumps with the time guarantees stated in Lemma 6.2. Each of the functions Wjump(R, j, d, α), Sjump(R, j, d, α), and Tjump(R, j, d, α) below takes as input the current rectangulation R in which the jump is performed, the index j of the rectangle r j to be jumped, the direction d ∈ { , } of the jump, and the index α of the edge e α which contains the insertion point of R [ j−1] that will become the top-left vertex of r j after the jump. In the pseudocode of these algorithms, all references to rectangles r i , edges e i , vertices v i or walls w i are with respect to the current rectangulation R.
We first present the implementation of W-jumps. For simplicity, we only show the implementation of left horizontal W-jumps in the function Wjump h (R, j, , α) below; see Fig. 15a. The implementation of right horizontal W-jumps, and of left and right vertical W-jumps in a function Wjump v (R, j, d, α) is very similar; we omit the details here.  We proceed with the implementation of S-jumps. For simplicity, we only provide the implementation of left S-jumps in the function Sjump(R, j, , α) below; see Fig. 15b. The implementation of right S-jumps is very similar.  (R, j, , α) below. The implementation of right horizontal T-jumps, and of left and right vertical T-jumps in a function Tjump v (R, j, d, α) is very similar.
Let R be the rectangulation obtained from R by one call of Tjump h (R, j, , α). The running time of this call is O(h(R, R ) + 1), as claimed in part (c) of Lemma 6.2. This time is incurred by the while-loop in step 3, which is iterated exactly h(R, R ) + 1 times.

Minimal Jump Oracles
A minimal jump oracle is a function that is called in line M4 of Algorithm M to compute a jump in the current rectangulation R that is minimal respect to the given zigzag set of rectangulations C n ⊆ R n . In this section we specify such oracles for the zigzag sets C n mentioned in Table 1, which allows us to establish the runtime bounds for Algorithm M stated in the last column of the table (except for block-aligned rectangulations, which are handled in Appendix B). A minimal jump oracle has the form next C n (R, j, d), and this function call performs in the current rectangulation R a jump of rectangle r j in direction d that is minimal w.r.t. C n , and the function will modify R accordingly. Depending on C n , our minimal jump oracles perform a suitable W-, S-, or T-jump, or a combination thereof, as implemented in the previous section.

Generic Rectangulations
We first consider the case C n = R n of generic rectangulations. Given the current rectangulation R, upon a jump of rectangle r j in direction d, every insertion from I (R [ j−1] ) is used, so we simply need to detect the next one. By Lemma 3.1, a W-jump occurs between any two consecutive (w.r.t. I (R [ j−1] )) insertion points belonging to the same horizontal or vertical group, an S-jump occurs between the last vertical insertion point and the first horizontal insertion point, and a T-jump occurs between the last insertion point of a group and the first insertion point of the next group, if both groups are vertical or horizontal. Specifically, suppose there are λ vertical groups and μ horizontal groups with cardinalities g k , k = 1, . . . , λ, and h k , k = 1, . . . , μ, respectively in I (R [ j−1] ) (note that g 1 = h μ = 1). Then the jump sequence consisting of letters {W , S, T } that specifies the types of jumps performed with rectangle r j from the first to the last insertion point is Fig. 16a. Of course, during Algorithm M , these jump operations are not consecutive, but they are interleaved with the jump sequences of other rectangles r k , k > j.
The details are spelled out in the function next R n (R, j, d).
The four distinct cases treated in lines N2-N4 come from the directions d ∈ { , } and whether the jump is horizontal or vertical. The latter condition is determined in line N1 by querying the type of the top-left vertex of r j , which is either or . Note that the code in lines N2 and N4 is symmetric by reflecting all directions at the main diagonal. The same holds for the code in lines N3 and N5.
Lemma 7.1 Consider a rectangulation P ∈ R n−1 with ν = ν(P) insertion points. Then calling next R n (R, n, ) exactly ν − 1 times with initial rectangulation R = c 1 (P), yields c i (P) for i = 1, . . . , ν, and the total time for these calls is O(ν). An analogous statement holds for next R n (R, n, ).
. . . Proof If the sequence of insertion points I (P) has λ vertical groups and μ horizontal groups of cardinalities g k , k = 1, . . . , λ, and h k , k = 1, . . . , μ, respectively, then the sequence of jumps performed by the calls to next R n has the form (1). We clearly have ν = λ k=1 g k + μ k=1 h k . We use Lemma 6.2 to bound the overall time to perform those operations; see Fig. 16a. The number of W-jumps in (1)  Proof For some fixed j ∈ {2, . . . , n}, we consider all jumps of rectangle r j . Whenever rectangle r j jumps in a rectangulation R ∈ R n , then R [k] is either bottom-based or right-based for all k = j + 1, . . . , n. Moreover, none of the rectangles k = j − 1, j − 2, . . . , 2 jumps unless R [ j] is bottom-based or right-based. Consequently, we can partition the jumps of r j in the entire jump sequence into subsequences, such that in each subsequence, for each rectangulation R ∈ R n of the subsequence, R [ j−1] ∈ R j−1 is the same subrectangulation and in R the rectangle r j jumps to the next insertion point of I (R [ j−1] ). By Lemma 7.1, the total time for visiting the ν = ν(R [ j−1] ) many rectangulations of this subsequence is O(ν), which is O(1) on average.

Remark 7.3
By slightly modifying our data structures, we could even obtain a loopless algorithm for generic rectangulations. The idea is to introduce an additional data structure called sides. Each rectangle is subdivided into four sides, and in the incidence relations, sides sit between edges and rectangles, i.e., edges do not point to the two touching rectangles directly, but to the relevant sides of those rectangles, and each side points to the rectangle it belongs to. During S-jumps and T-jumps, a rectangle can be broken up into its four sides and the sides of two rectangles can be interchanged in constant time, avoiding the while-loops in the functions Sjump and Tjump that need to update possibly linearly many incidences between edges and rectangles. To keep the presentation simple, we do not show these modifications. Also, the resulting improvement is not substantial, and sides are a somewhat artificial concept.

Diagonal Rectangulations
Recall that in a diagonal rectangulation R ∈ D n , every rectangle intersects the main diagonal, or equivalently, R avoids the patterns and . Consequently, during a jump of rectangle r j in the current rectangulation R, we need to consider precisely the insertion points from I (R [ j−1] ) that are the first insertion point of a vertical group, or the last insertion point of a horizontal group, as any other insertion point from each group would create one of the forbidden pattern; see Fig. 16b. Consequently, if the sequence I (R [ j−1] ) has λ vertical groups and μ horizontal groups, then the jump sequence that specifies the types of jumps with rectangle r j from the first to the last insertion point is In particular, we do not perform any wall slides. An implementation of this is provided in the function next D n (R, j, d).  (R, j, , γ ). Return.
Similarly to before, the code in lines N2 and N4, and in lines N3 and N5 is symmetric by reflecting all directions at the main diagonal. For diagonal rectangulations the runtime analysis is straightforward and gives a loopless algorithm.

Lemma 7.4 Each call next D n (R, j, d) takes time O(1).
Proof Let R be the rectangulation after the call next D n (R, j, d) Remark 7.6 Jumps as performed by the oracles next R n and next D n and shown in Fig. 16 correspond to cover relations in the lattice of generic rectangulations and the lattice of diagonal rectangulations described by Meehan [29] and Law and Reading [27], respectively, which both arise as lattice quotients of the weak order on the symmetric group. Consequently, our cyclic Gray codes correspond to Hamilton cycles in the cover graphs of those lattices. In [22] we showed that our permutation language framework can be used to generate a Hamilton path on every lattice quotient of the weak order, which also yields a Hamilton path on the skeleton of the corresponding polytope [35] (see also [34]).

Pattern-Avoiding Rectangulations
For any zigzag set of rectangulations C n ⊆ R n , and any set of tame patterns P, Theorem 4.2 guarantees that the set C n (P) of rectangulations that avoid all patterns from P is also a zigzag set. We now describe how we can obtain a minimal jump oracle for C n (P) from a minimal jump oracle next C n (R, j, d) for C n . The idea is simply to perform a minimal jump of r j w.r.t. C n , and to test after each jump whether the resulting rectangulation contains any pattern from P, repeating this process until we arrive at a rectangulation that avoids all patterns from P. This is guaranteed to terminate after at most j ≤ n iterations, as the first and last insertion point of I (R [ j−1] ) will produce rectangulations that avoid all patterns from P, due to the zigzag property.
next C n (P) (R, j, d) (minimal jump oracle for pattern-avoiding permutations). N1. [Fast forward] While R contains a pattern from P repeat next C n (R, j, d).
We immediately obtain the following generic runtime bounds.
Theorem 7.7 Let P be a finite set of tame rectangulation patterns. If the zigzag set C n has a minimal jump oracle next C n that runs in time f n , and containment of any pattern from P in R can be tested in time t n , then next C n (P) is a minimal jump oracle for C n (P) that runs in time O(n( f n + t n )). In some cases the runtime bound for at most n consecutive calls of next C n (R, j, d) or several consecutive pattern containment tests can be improved upon the trivial bounds O(n f n ) and O(nt n ), respectively (see the proof of Theorem 7.9 below). Moreover, for some patterns further optimizations of the function next C n (P) (R, j, d) are possible. For example, the property of R to be guillotine is invariant under W-jumps and Sjumps, so if R is found to contain one of the windmill patterns, then we only need to check containment after the next T-jump performed by the call next C n (R, j, d).
Most importantly, when testing for containment of a pattern, we only need to check incidences of walls involving the rectangle r j . In the following, we provide functions contains(R, j, P) that test whether R contains one of the tame patterns P listed in Lemma 4.1 after a sequence of jumps of rectangle r j from a rectangulation that avoids P. We emphasize here that these functions only work under these assumptions, and are not suitable for general pattern containment testing of arbitrary rectangulations, but only for use within our algorithm M .
We first present an implementation of such a containment testing function contains(R, j, P) for the clockwise windmill P = ; see Fig. 17a. It uses the wall data structure w 1 , . . . , w n+3 to quickly move to the end vertex of a wall (without traversing the possibly many edges along the wall).
contains R, j, (check for clockwise windmill pattern after jump of rectangle r j ). C1.
[Prepare] Set a ← r j .nwest. If v a .type = , return false. Otherwise we have v a .type = and proceed with C2.
west. If e δ .right = j, return true, otherwise return false.
The function that tests for the counterclockwise windmill P = is symmetric, and is not shown here for simplicity.
The next two functions test for containment of the patterns P = and P = , respectively; see Fig. 17 Similarly to before, testing for the patterns P = and P = is symmetric to the previous two cases, so we omit those implementations.
It remains to provide containment testing for the patterns P = and P = . We only show the first case, as the other is symmetric; see Lines C2-C4 are essentially a triply nested loop that moves along the edges of the vertical wall x that contains the left side of r j (line C2), the edges of each horizontal wall y whose right end vertex lies on x (line C3), and the edges of each vertical wall z whose bottom end vertex lies on y, searching for a vertex of type on z (line C4); see Fig. 18. This is realized by repeatedly calling line C3 from within the while-loop in line C2, and upon completion returning to from where the call occurred. Similarly, line C4 is repeatedly called from within the while-loop in line C3, and upon completion it returns to from where it was called.
The aforementioned functions have the following runtime guarantees. Proof For the first six patterns the statement is obvious, as the specified functions only make constantly many changes to our data structures. For the pattern P = , note that each edge index of the rectangulation R is assigned to one of the variables β, γ , δ The next theorem combines all the observations from this section, thus establishing most of the runtime bounds stated in Table 1.

Theorem 7.9
Let P 1 := , , , , , and P 2 := , . Algorithm M with the minimal jump oracle next R n (P) or next D n (P) visits each rectangulation from R n (P) or D n (P), respectively, in time O(n) for any set of patterns P ⊆ P 1 and in time O(n 2 ) for any set of patterns P ⊆ P 1 ∪ P 2 .
All the bounds stated in Theorem 7.9 hold in the worst case (not just on average).

Proof
We first consider the minimal jump oracle next D n (P) , which repeatedly calls the function next D n described in Sect. 7.2. Applying Theorem 7.7 with the bound f n = O(1) from Lemma 7.4 and the bounds t n = O(1) for P ⊆ P 1 and t n = O(n) for P ⊆ P 1 ∪ P 2 from Lemma 7.8, the term n( f n + t n ) evaluates to O(n) or O(n 2 ), respectively, as claimed.
We now consider the minimal jump oracle next R n (P) , which repeatedly calls next R n described in Sect. 7.1. In this case applying Theorem 7.7 directly would not give the desired bounds, so we have to refine the analysis of the whileloop in the algorithm next R n (P) . Specifically, we consider the sequence of calls to next R n (R, j, d) from one rectangulation R ∈ R n avoiding all patterns from P until the next one. The length of this sequence is at most ν = ν(R [ j−1] ) ≤ n (recall Lemma 2.1), and by Lemma 7.1 the total time of all calls to next R n (R, j, d) is O(ν) = O(n). The total time of all pattern containment tests is at most νt n ≤ nt n , which is O(n) for P ⊆ P 1 and O(n 2 ) for P ⊆ P 1 ∪ P 2 by Lemma 7.8. This proves the claimed bounds, completing the proof of the theorem.

Remark 7.10
For P := , we have R n (P) = D n , so we could use, or rather 'misuse', the minimal jump oracle next R n (P) to generate D n . However, this would give a worse guarantee of O(n) time per visited diagonal rectangulation, rather than O(1) for next D n as guaranteed by Theorem 7.5.

Remark 7.11
We write c(C n−1 (P)) for the set of all rectangulations from C n that are obtained by inserting a rectangle into a rectangulation from C n−1 (P). To assess the runtime bounds stated in Theorem 7.9, one may try to investigate the quantity |c(C n−1 (P)|/|C n (P)|. This is a lower bound for the average number of iterations of the while-loop of the algorithm next C n (P) before it returns a rectangulation from C n (P). Experimentally, we found that this ratio grows with n in many cases, though maybe not linearly with n, hinting at the possibility that the time bounds stated in Theorem 7.9 are too pessimistic and can be improved in an average case analysis.

Proofs of Theorems 3.3 and 5.1
In this section we present the proofs of Theorems 3.3 and 5.1. For this purpose we first recap the exhaustive generation framework for permutation languages developed in [20,21]. Definitions and terminology intentionally parallel the corresponding definitions given for rectangulations before, and the connection between rectangulations and permutations will be made precise in Lemma 8.7 below.

Permutation Basics
For any two integers a ≤ b we define [a, b] := {a, a + 1, . . . , b}, and we refer to a set of this form as an interval. We also define [n] := [1, n] = {1, . . . , n}. We write S n for the set of permutations on [n], and we write π ∈ S n in one-line notation as π = π(1)π(2) · · · π(n) = a 1 a 2 · · · a n . Moreover, we use ε ∈ S 0 to denote the empty permutation, and id n = 12 · · · n ∈ S n to denote the identity permutation.
Given two permutations π and τ , we say that π contains the pattern τ , if there is a subsequence of π whose elements have the same relative order as in τ . Otherwise we say that π avoids τ . For example, π = 6 35 41 2 contains the pattern τ = 231, as the highlighted entries show, whereas π = 654123 avoids τ = 231. In a vincular pattern τ , there is exactly one underlined pair of consecutive entries, with the interpretation that the underlined entries must match adjacent positions in π . For instance, the permutation π = 3 1 4 2 contains the pattern τ = 231, but it avoids the vincular pattern τ = 231.

Deletion, Insertion, and Jumps in Permutations
For π ∈ S n , n ≥ 1, we write p(π ) ∈ S n−1 for the permutation obtained from π by deleting the largest entry n. We also define π [i] := p n−i (π ) for i = 1, . . . , n. Moreover, for any π ∈ S n−1 and any 1 ≤ i ≤ n, we write c i (π ) ∈ S n for the permutation obtained from π by inserting the new largest value n at position i of π , i.e., if π = a 1 · · · a n−1 then c i (π ) = a 1 · · · a i−1 n a i · · · a n−1 . For example, for π = 412563 we have p(π ) = 41253 and c 1 (π ) = 7412563, c 5 (π ) = 4125763, and c 7 (π ) = 4125637. Given a permutation π = a 1 · · · a n with a substring a i · · · a i+d with d > 0 and a i > a i+1 , . . . , a i+d , a right jump of the value a i by d steps is a cyclic left rotation of this substring by one position to a i+1 · · · a i+d a i . Similarly, given a substring a i−d · · · a i with d > 0 and a i > a i−d , . . . , a i−1 , a left jump of the value a i by d steps is a cyclic right rotation of this substring to a i a i−d · · · a i−1 . For example, a right jump of the value 5 in the permutation 265134 by two steps yields 261354.
We say that a jump is minimal w.r.t. a set of permutations L n ⊆ S n , if every jump of the same value in the same direction by fewer steps creates a permutation that is not in L n .

Generating Permutations by Minimal Jumps
Consider the following analogue of Algorithm J for greedily generating a set of permutations L n ⊆ S n using minimal jumps.

Algorithm J (greedy minimal jumps).
This algorithm attempts to greedily generate a set of permutations L n ⊆ S n using minimal jumps starting from an initial permutation π 0 ∈ L n . J1.
[Jump] Generate an unvisited permutation from L n by performing a minimal jump of the largest possible value in the most recently visited permutation. If no such jump exists, or the jump direction is ambiguous, then terminate. Otherwise visit this permutation and repeat J2.
The following results were proved in [21]. A set of permutations L n ⊆ S n is called a zigzag language, if either n = 0 and L 0 = {ε}, or if n ≥ 1 and L n−1 := { p(π ) | π ∈ L n } is a zigzag language and for every π ∈ L n−1 we have c 1 (π ) ∈ L n and c n (π ) ∈ L n . We now define a sequence J (L n ) of all permutations from a zigzag language L n ⊆ S n . For any π ∈ L n−1 we let #" c (π ) be the sequence of all c i (π ) ∈ L n for i = 1, 2, . . . , n, starting with c 1 (π ) and ending with c n (π ), and we let # " c (π ) denote the reverse sequence, i.e., it starts with c n (π ) and ends with c 1 (π ). In words, those sequences are obtained by inserting into π the new largest value n in all possible positions from left to right, or from right to left, respectively, in all possible positions that yield a permutation from L n , skipping the positions that yield a permutation that is not in L n . If n = 0 then we define J (L 0 ) := ε, and if n ≥ 1 then we consider the finite sequence J (L n−1 ) =: π 1 , π 2 , . . . and define i.e., this sequence is obtained from the previous sequence by inserting the new largest value n in all possible positions alternatingly from right to left, or from left to right.

Theorem 8.1 [21, Thm. 1 + Lem. 4]
Given any zigzag language of permutations L n and initial permutation π 0 = id n , Algorithm J visits every permutation from L n exactly once, in the order J (L n ) defined by (2). Moreover, if |L i | is even for all 2 ≤ i ≤ n − 1, then the sequence J (L n ) is cyclic, i.e., the first and last permutation differ in a minimal jump.
A permutation π is called 2-clumped if it avoids each of the vincular patterns 35124, 35142, 24513, and 42513. We write S n ⊆ S n for the set of 2-clumped permutations.
We also state the following observations for further reference.

, ρ be two consecutive permutations in J (L n ) such that ρ is obtained from π by a left jump of some value j, and let π , ρ be the next two consecutive permutations in J (L n ) that differ in a jump of j. If j is not at the first position in ρ and the value left of it is smaller than j, then ρ is obtained from π by a left jump. Conversely, if j is at the first position in ρ or the value left of it is bigger than j, then ρ is obtained from π by a right jump. An analogous statement holds with left and right interchanged.
The proof of Lemma 8.3 is deferred to Appendix A.
With any wall w of a generic rectangulation R ∈ R n we associate a wall shuffle σ (w), which is a permutation of a subset of the rectangles that share a side with w, defined as follows; see Fig. 20. If the wall w is horizontal, we move from the left endpoint of w to the right endpoint, and whenever we encounter a vertical wall w that is incident to w from the bottom, we record the rectangle whose top side lies on w and left side lies on w , and if we encounter a vertical wall w that is incident to w from the top, we record the rectangle whose bottom side lies on w and right side lies on w . Clearly, we record all rectangles whose bottom or top side lies on w, except the first rectangle below w and the last rectangle above w. On the other hand, if the wall w is vertical, we move from the bottom endpoint of w to the top endpoint, and whenever we encounter a horizontal wall w that is incident to w from the left, we record the rectangle whose right side lies on w and bottom side lies on w , and if we encounter a horizontal wall w that is incident to w from the right, we record the rectangle whose left side lies on w and top side lies on w . In this case we record all rectangles whose left or right side lies on w, except the first rectangle to the left of w and the last rectangle to the right of w. Observe that wall slides do not affect the rectangles that appear in a wall shuffle, but only their relative order in the shuffle.
We are now in position to define the mapping γ : S n → R n , n ≥ 1, from permutations to generic rectangulations; see Fig. 21. From π ∈ S n we first construct the diagonal rectangulation R := ρ(π) ∈ D n . Let w be a horizontal wall in R, and consider the rectangles in R whose bottom side lies on w from left to right. By con- struction of ρ, these rectangles form an increasing subsequence of π . Similarly, the rectangles in R whose top side lies on w from left to right form an increasing subsequence of π . Thus, we can specify a wall shuffle σ (w) by taking the subsequence of π that contains the appropriate rectangle numbers. On the other hand, for a vertical wall w in R, the rectangles in R whose left side lies on w from bottom to top form a decreasing subsequence of π , and the rectangles whose right side lies on w form a decreasing subsequence of π , so we can specify a wall shuffle σ (w) by taking the subsequence of π containing the appropriate rectangle numbers. The rectangulation γ (π) ∈ R n is obtained from R ∈ D n by applying wall slides to it, so as to obtain the wall shuffles specified by π .
Even though γ is not a bijection, Reading [36] showed that it becomes a bijection when restricting the domain to 2-clumped permutations.
Theorem 8.5 [36,Thm. 4.1] The map γ is a bijection when restricted to the set S n of 2-clumped permutations.

The Connection Between Permutations and Rectangulations
The key lemma of this section, Lemma 8.7 below, asserts that deletion, insertion and jumps in permutations as defined in Sect. 8.2 are in bijective correspondence under γ to deletion, insertion and jumps in generic rectangulations as defined in Sects. 2.3, 2.4, and 3.1. In order to prove it, we first establish a coarser version of this statement for the mapping ρ.

Lemma 8.6
Let π = a 1 · · · a n ∈ S n , n ≥ 1, and define P := ρ(π) ∈ D n . In the sequence I (P) = (q 1 , . . . , q ν ), consider the subsequence I (P) = (q j 1 , . . . , q j μ ) consisting of the first insertion point of every vertical group, and the last insertion point of every horizontal group. Then we have p(ρ(c i (π ))) = P for all i = 1, . . . , n + 1, and the sequence 1, . . . , n + 1 can be partitioned into consecutive nonempty intervals I 1 , . . . , I μ with the following properties: (a) for every k = 1, . . . , μ and every i ∈ I k we have ρ(c i (π )) = c j k (P); (b) for any interval I k = [î,ǐ], 1 < k < μ, such that the top-left vertex of r n+1 in ρ(c i (π )), i ∈ I k , has type , we have that the rectangle r aˆı −1 is the unique rectangle left of r n+1 , and the rectangle r aˇı is the leftmost rectangle above r n+1 ; (c) for any interval I k = [î,ǐ], 1 < k < μ, such that the top-left vertex of r n+1 in ρ(c i (π )), i ∈ I k , has type , we have that the rectangle r aˆı −1 is the topmost rectangle left of r n+1 , and the rectangle r aˇı is the unique rectangle above r n+1 ; (d) we have I 1 = {1} and I μ = {n + 1}.
Proof For the reader's convenience, the proof is illustrated in Fig. 22. Recall the definition of the mapping ρ via the process described in Sect. 8.4 and illustrated in Fig. 19. Using the definition of the rectangle insertion from Sect. 2.4, we first observe that ρ(c 1 (π )) = c 1 (P) and ρ(c n+1 (π )) = c ν (P). We consider the sequence of permutations c i (π ) for i = 1, . . . , n + 1 and their images under ρ. Observe that c i+1 (π ) is obtained from c i (π ) by the adjacent transposition (n + 1)a i → a i (n + 1). We consider the construction of R := ρ(c i (π )), specifically the two steps in which the rectangles r n+1 and r a i are added, and we analyze how the swapped insertion order of these two rectangles changes the resulting rectangulation R := ρ(c i+1 (π )). Clearly, in both R and R , the rectangle r n+1 is either left-extended and top-fixed, or left-fixed and top-extended, and we treat both cases separately. In particular, these two cases are not symmetric.

Case (i): r n+1 is left-extended and top-fixed in R.
This case is shown in the top and middle part of Fig. 22. We distinguish two subcases, namely a i = n and a i < n. Case (ia): a i = n. In this case the top side of r n+1 coincides with the bottom side of r a i = r n in R, as both rectangles left-extend to the same vertical line by the staircase property and the fact that every rectangle intersects the main diagonal; see Fig. 22a2. Consequently, inserting them in the swapped order, first r n and then r n+1 , produces a sub-rectangulation that differs in a simple flip of the wall between these two rectangles; see Fig. 22a3. As the height of the top side of r n is not determined by r n+1 , but only by previous rectangles r a 1 , . . . , r a i−1 , both insertion orders produce the same staircase r a 1 ∪ · · · ∪ r n ∪ r n+1 , which by the definition of ρ is all that matters Note that in R, the top-left vertex of r n+1 has type and r aˇı ,ǐ := i, is the leftmost rectangle above r n+1 . Furthermore, in R , the top-left vertex of r n+1 has type and r aˆı −1 = r a i ,î := i + 1, is the topmost rectangle left of r n+1 .
Case (ib): a i < n. Ifr a i is bottom-fixed in R, or if r n+1 does not left-extend beyond the vertical line through the right endpoint of the a i th interval on the main diagonal, then the rectangles r n+1 and r a i do not touch; see Fig. 22a1. Consequently, inserting them in the swapped order, first r a i and then r n+1 , produces the same sub-rectangulation. It follows that R = R , i.e., ρ(c i (π )) = ρ(c i+1 (π )), and therefore trivially p(R) = p(R ).
On the other hand, if r a i is bottom-extended and r n+1 left-extends beyond , then r a i must be right-fixed because of a i < n (otherwise r a i would reach into the (a i + 1)st line segment on the main diagonal). Moreover, because of the staircase property the top side of r n+1 contains the bottom side of r a i , and both rectangles left-extend to the same vertical line; see Fig. 22b2. Consequently, inserting them in the swapped order, first r a i and then r n+1 produces a sub-rectangulation that differs in a T-flip from ⊥ to around the top-right common vertex of these two rectangles; see Fig. 22b3. As the height of the top side of r a i is not determined by r n+1 , and as r a i is right-fixed and r n+1 is top-fixed in both insertion orders, we obtain that R and R differ in a T-flip around the top-right common vertex of the rectangles r n+1 and r a i . Moreover, by the definition of rectangle insertion and deletion and the definition of I (P), we have p(R) = p(R ) = P, and R = c j k (P) and R = c j k+1 (P) for some index k. Note that in R, the top-left vertex of r n+1 has type and r aˇı ,ǐ := i, is the leftmost rectangle above r n+1 . Furthermore, in R , the top-left vertex of r n+1 has type and r aˆı −1 = r a i , ı := i + 1, is the unique rectangle left of r n+1 .

Case (ii): r n+1 is left-fixed and top-extended in R.
This case is shown in the bottom part of Fig. 22. As r n+1 is top-extended, the staircase property implies that a i < n, as n must be among the first entries a 1 , . . . , a i−1 of π .
If r a i is right-fixed in R, or if r n+1 does not top-extend beyond the horizontal line through the right endpoint of the (a i + 1)st interval on the main diagonal, then the rectangles r n+1 and r a i do not touch; see Fig. 22c1. Consequently, inserting them in the swapped order, first r a i and then r n+1 , produces the same sub-rectangulation. It follows that R = R , i.e., ρ(c i (π )) = ρ(c i+1 (π )), and therefore trivially p(R) = p(R ).
On the other hand, if r a i is right-extended and r n+1 top-extends beyond , then r a i must be bottom-fixed because of a i < n (otherwise r a i would reach into the (a i + 1)st line segment on the main diagonal). Moreover, because of the staircase property the top side of r n+1 must lie on the horizontal line through the bottom side of r a i , and therefore r a i right-extends to the right outer boundary, i.e., the bottom side of r a i contains the top side of r n+1 ; see Fig. 22c2. Consequently, inserting them in the swapped order, first r a i and then r n+1 produces a sub-rectangulation that differs in a T-flip from to around the bottom-left common vertex of these two rectangles; see Fig. 22c3. As the height of the top side of r a i is not determined by r n+1 in the two insertion orders, we obtain that R and R differ in a T-flip around the bottom-left common vertex of the rectangles r n+1 and r a i . Moreover, by the definition of rectangle insertion and deletion and the definition of I (P), we have p(R) = p(R ) = P, and R = c j k (P) and R = c j k+1 (P) for some index k. Note that in R, the top-left vertex of r n+1 has type and r aˇı ,ǐ := i, is the unique rectangle above r n+1 . Furthermore, in R , the top-left vertex of r n+1 has type and r aˆı −1 = r a i ,î := i + 1, is the topmost rectangle left of r n+1 .
Proof For any i = 1, . . . , n + 1, consider the permutation c i (π ), and the two diagonal rectangulations P := ρ(π) ∈ D n and R := ρ(c i (π )) ∈ D n . From Lemma 8.6 we know that P = p(R ) and R = c j (P ) for some index j such that the jth insertion point in I (P ) is the first of a vertical group, or the last of a horizontal group. By the definitions from Sect. 8.4, γ consists of applying ρ plus wall slides that are determined by the wall shuffles of P and R and the relative order of the rectangle indices in those shuffles in π and c i (π ), i.e., P = γ (π) and R := γ (c i (π )) are obtained from P and R by wall slides. Observe that in R and R, the bottom-right rectangle r n+1 is contained in at most one wall shuffle. Specifically, if the top-left corner of r n+1 has type and does not lie on the left boundary of the rectangulation, then r n+1 participates in a single wall shuffle of the vertical wall that contains the left side of r n+1 , whereas if the top-left corner of r n+1 has type and does not lie on the upper boundary of the rectangulation, then r n+1 participates in a single wall shuffle of the horizontal wall that contains the top side of r n+1 . In particular, in the cases j = 1 and j = ν(P ) the rectangle r n+1 is not contained in any wall shuffle. As the elements of all subsequences of π and c i (π ) that do not contain n + 1 appear in the same relative order in both permutations, all wall shuffles of P and R are the same, except the wall shuffle of R containing n+1, which is obtained from a wall shuffle of P by inserting the value n+1. We conclude that p(R) = P and R = c k (P) for some index k.
The desired interval partition I 1 , . . . , I ν of the indices 1, . . . , n + 1 is obtained by refining the partition I 1 , . . . , I μ guaranteed by Lemma 8.6, where μ is the number of vertical and horizontal groups of P , which is the same for P, as wall slides do not affect it. As I 1 = {1} and I μ = {n + 1} by Lemma 8.6(d), these two intervals are not refined, so we have I 1 := I 1 = {1} and I ν := I μ = {n + 1}. It remains to consider the remaining intervals I k , 1 < k < μ.
Now consider an interval I k =: [î,ǐ], 1 < k < μ, such that in R := ρ(c i (π )) ∈ D n , i ∈ I k , the top-left vertex has type (recall Lemma 8.6(a)). By Lemma 8.6(c), in R the rectangle r aˆı −1 is the topmost rectangle left of r n+1 , and the rectangle r aˇı is the unique rectangle above r n+1 . Consider the wall shuffle σ (w) of the horizontal wall w between r aˆı −1 and r aˇı in P. It has the form σ (w) = (. . . , aˆı −1 , b 1 , . . . , b λ ), for some λ ≥ 0, i.e., the rectangles r b λ , . . . , r b 1 are stacked to the left of r aˇı and their right sides are incident with w to the right of the incidence of the left side of r aˆı −1 with w. It follows that π contains the subsequence aˆı −1 , b 1 , . . . , b λ , aˇı , and so the  permutations c i (π ) for i =î, . . . ,ǐ have the value n + 1 appear at every possible position within the subsequence b 1 , . . . , b λ . Consequently, the interval I k is refined into λ subintervals such that γ (c i (π )) = γ (c i+1 (π )) if i, i + 1 are in the same subinterval and γ (c i (π )) = c (P) and γ (c i+1 (π )) = c +1 (P) for some index if i, i + 1 are in consecutive subintervals.

Proof of Theorem 3.3
With Lemma 8.7 in hand, we are now in position to present the proof of Theorem 3.3.

Proof of Theorem 3.3
Consider a zigzag set of rectangulations C n ⊆ R n , and consider the zigzag sets C i−1 := { p(R) | R ∈ C i } for i = n, n − 1, . . . , 2. By Lemma 8.7, for all i = 1, . . . , n there is a set of 2-clumped permutations L i ⊆ S i such that γ restricted to L i is a bijection between L i and C i , and such that L i−1 = {p(π ) | π ∈ L i } for all i = 2, . . . , n. Moreover, as C i is a zigzag set, we know that for all R ∈ C i−1 we have c 1 (R) ∈ C i and c ν(R) (R) ∈ C i , for all i = 2, . . . , n. By Lemma 8.7, this implies that for all π ∈ L i−1 we have c 1 (π ) ∈ L i and c i (R) ∈ L i , for all i = 2, . . . , n, i.e., L n is a zigzag language of 2-clumped permutations (using that L 1 = {1} and L 0 := { p(π ) | π ∈ L 1 } = {ε} are zigzag languages).
By Theorem 8.1, Algorithm J visits every permutation from L n exactly once, in the order J (L n ) defined by (2). From Lemma 8.3(d) we obtain that if Algorithm J performs a jump of some value j in the current permutation π ∈ L n , then the corresponding rectangulations R [k] := γ (π [k] ) for k = j + 1, . . . , n are either bottom-based or right-based. Using the definition of jumps from Sect. 3.1 and Lemma 8.7, a minimal left/right jump of the value j in π ∈ L n , as performed by Algorithm J, corresponds to a minimal left/right jump of the rectangle r j in γ (π) ∈ γ (L n ) = C n , as performed by Algorithm J . This together with the observation that γ (id n ) = ... n proves the first part of the theorem. Specifically, the ordering of rectangulations generated by Algorithm J is To prove the second part of the theorem, by Theorem 8.1 it suffices to show that |C i | = |γ (L i )| is even for all 2 ≤ i ≤ n − 1. For any rectangulation R ∈ R n , we write λ(R) ∈ R n for the rectangulation obtained by reflection at the main diagonal. First observe that if R, R ∈ R n , n ≥ 2, satisfy R = λ(R), then we also have p(R ) = λ( p(R)). Consequently, the assumption that C n is symmetric implies that C i is symmetric for all i = 1, . . . , n. Consider a rectangulation R ∈ R n , n ≥ 2, and observe that if the top-left vertex of the bottom-right rectangle r n of R has type , then it has type in λ(R), and vice versa. It follows that λ is an involution without fixed points on C i for all i = 2, . . . , n, proving that |C i | is even. This completes the proof.

Memoryless Generation of Permutations
Consider Algorithm M below, which takes as input a zigzag language of permutations L n ⊆ S n and generates them exhaustively by minimal jumps in the same order as Algorithm J, i.e., in the order J (L n ).

Algorithm M (memoryless minimal jumps).
This algorithm generates all permutations of a zigzag language L n ⊆ S n by minimal jumps in the same order as The rest of this section is devoted to proving Theorem 8.8. For any π in the sequence J (L n ) we define a sequence s π n = (s π n,1 , . . . , s π n,n ) as follows: If n = 1 we have J (L 1 ) = π with π := 1 and we define s π 1 = (1). If n ≥ 2, we consider the permutation π := p(π ) ∈ S n−1 in the sequence J (L n−1 ), and we define c(π ) := # " c (π ) if π appears at an odd position in J (L n−1 ), or c(π ) := #" c (π ) if π appears at an even position. If π is not the last permutation in c(π ) we define s π n,i := for i = 1, . . . , n, and if π is the last permutation in c(π ) we define, for i = 1, . . . , n, The following lemma captures important properties of the sequences defined in this way.

Lemma 8.9
The sequences defined in (4) and (5) have the following properties: (a) For the first permutation π = id n in the sequence J (L n ), we have s π n = (1, 2, . . . , n). (b) For any two consecutive permutations π, ρ in the sequence J (L n ), ρ is obtained from π by a jump of the value s π n,n . (c) For the last permutation π in J (L n ) we have s π n,n = 1. Moreover, for any three consecutive permutations π, ρ, σ in J (L n ) we have:  = (s 1 , . . . , s n ) satisfy s = s π n with s π n as defined in (4) and (5).
By Lemma 8.3(a), the identity permutation π := id n is the first permutation in the sequence J (L n ). Moreover, by the initialization of π in line M1, π = id n is also the first permutation visited in line M2. Combining this with the above invariants, we obtain by induction on the length of J (L n ) that after visiting a permutation π ∈ L n , the next permutation visited by Algorithm M is the permutation that succeeds π in J (L n ).
Indeed, by the instructions in line M3 and M4, the next permutation ρ visited by the algorithm is obtained from π by a jump of the value j := s n that is minimal w.r.t. L n , and the jump direction is left if o j = and right if o j = . Applying (B) and Lemma 8.9(a), and (A) and Lemma 8.3(c), we obtain that ρ is indeed the permutation that succeeds π in J (L n ). Also, the algorithm terminates correctly after visiting the last permutation in the sequence J (L n ) by the condition in line M3 and Lemma 8.9(c).
We prove (A) + (B) by double induction on n and the number of iterations of Algorithm M. The induction basis n = 1 is trivial. For the induction step, let n ≥ 2, and assume that the invariants hold for the zigzag language L n−1 = {p(π ) | π ∈ L n }. We first verify that (A) + (B) hold in line M2 during the first iteration of the algorithm when π = id n . By line M1 we have o j = for j = 2, . . . , n, so (A) is satisfied by Lemma 8.3(b). By line M1 we also have s = (s 1 , . . . , s n ) = (1, . . . , n), which equals s π n = s id n n by Lemma 8.9(a). For the induction step, consider three consecutive permutationsπ,ρ,σ in the sequence J (L n ), and suppose that (A) + (B) are satisfied when Algorithm M visits π =π . We need to verify that (A) + (B) still hold after one iteration through lines M2-M5, after which the algorithm visits π =ρ by the instructions in lines M3 and M4, as argued before.
Case (i): We first consider the case thatπ,ρ satisfy p(π) = p(ρ) =:π ∈ L n−1 and therefore both are contained in the subsequence c(π ) of J (L n ). We only treat the case c(π ) = # " c (π ), as the other case c(π ) = #" c (π ) is symmetric. In this caseρ is obtained fromπ by a left jump of the value n. In particular, the variable j has the value j = s n = n and o n = in this iteration of the algorithm.
Case (ia): The value n is not at the first position inρ. Then by (2) the permutationσ is obtained fromρ by another left jump of the value n. In line M5, the value of s n is set to n, which was the previous value, but none of the conditions in line M5 holds for π =ρ, so overall none of the arrays s and o is modified. We conclude that (A) holds after this iteration for π =ρ. Moreover, (B) holds by Lemma 8.9(c) and (4b).
Case (ib): The value n is at the first position inρ, i.e., we haveρ = c 1 (π ) = nπ . Then by (2) we haveσ = c 1 (ρ ) = nρ whereρ ∈ L n−1 succeedsπ in the sequence J (L n−1 ). In line M5, the value of s n is set to n, which is the same as the previous value, but since the first if-condition is satisfied, s n is then overwritten by s n−1 , and s n−1 is set to n − 1. Consequently, the new values are s n−1 = n − 1 and s n = sπ n,n−1 = sπ n−1,n−1 by induction and (B) and (4a). Moreover, the value of o n is flipped to o n = . Using Lemma 8.3(e), we conclude that (A) holds after this iteration for π =ρ. Applying Lemma 8.9(d) and using that s π n,n = sπ n−1,n−1 by (5c), we obtain that (B) holds as well.
Case (ii): It remains to consider the case that p(π) = p(ρ), i.e., both permutations have n at the first or last position. By symmetry, it suffices to consider the case that n is at the first position, i.e.,π = c 1 (π ) = nπ andρ = c 1 (ρ ) = nρ , whereπ andρ are consecutive permutations in J (L n−1 ). They differ in a jump of the value j := s n < n by Lemma 8.9(b) and (B). Then by (2), the permutationσ is obtained fromρ by a right jump of n. We proceed to show that (A) and (B) hold for π =ρ, and for this we distinguish subcases.
Case (iia): The value j is not at a boundary position in p n− j (ρ). Then by Lemma 8.3(d) inρ the value j is surrounded by the same values as in p n− j (ρ), both smaller than j. In line M5, the value of s n is set to n, and no other entries of s and o are modified. Using Lemma 8.3(e), we conclude that (A) holds after this iteration for π =ρ. Moreover, (B) holds by Lemma 8.9(e), also using that sρ n,n = n by (4b).
Case (iib): The value j is at a boundary position in p n− j (ρ), and the value k next to it is smaller than j. Then by Lemma 8.3(d) inρ the value k is also next to j, and either j is at a boundary position (the right boundary, as n is at the first position inρ) or the other value next to in the direction o j of the jump is bigger than j. In line M5, the value of s n is set to n, the value of s j is set to s j−1 , and s j−1 is set to j − 1. Moreover, the value of o j is flipped. Using Lemma 8.3(e), we conclude that (A) holds after this iteration for π =ρ. Moreover, (B) holds by Lemma 8.9(f), also using that sρ n,n = n by (4b). This completes the proof of the theorem.

Proof of Theorem 5.1
Proof of Theorem 5. 1 In the proof of Theorem 3.3 we showed that the ordering of rectangulations generated by Algorithm J is given by (3) for some zigzag language L n of 2-clumped permutations. The theorem hence follows by applying Theorem 8.8.

Counting Pattern-Avoiding Rectangulations
In this section we report on computer experiments that count pattern-avoiding rectangulations C n (P) for all interesting subsets of patterns P ⊆ {P 1 , . . . , P 8 } where P 1 = , P 2 = , P 3 = , P 4 = , P 5 = , P 6 = , P 7 = , Clearly, we can omit sets of patterns that are equivalent to another set of patterns under D 4 actions (rotations and mirroring vertically or horizontally). Table 3 shows the results for generic rectangulations C n = R n as a base class. For counting results with block-aligned rectangulations as a base class, see Appendix C. The set of patterns used in each row of the table is denoted by the pattern indices, omitting curly brackets and commas. For example, the row 1478 refers to the set P = {P 1 , P 4 , P 7 , P 8 }.
Several of these counting sequences appear in the OEIS [46], and are related to pattern-avoiding permutations (see e.g. [8]). The matching OEIS entries marked with ? are observed through numerical experiments, but no formal bijective proof has been obtained yet, even though finding one should be straightforward in some cases. The last two rows in Table 3 with ? are interesting, as the correspondence to the objects mentioned in those OEIS entries is not obvious. This is true in particular for OEIS sequence A000984, which are the central binomial coefficients 2n n .
The subject of pattern-avoiding rectangulations deserves further systematic investigation, and may still hold many undiscovered gems; recall Table 3. Understanding the number of pattern-avoiding rectangulations that are obtained by rectangle insertion may also help to improve the runtime bounds for our generation algorithms (recall Remark 7.11). Moreover, does the avoidance of a rectangulation pattern always correspond to the avoidance of a particular permutation pattern, and what is this correspondence?
In our paper we considered R-equivalence and S-equivalence of generic rectangulations R n , and these equivalence relations are induced by wall slides, or by wall slides and simple flips, respectively. Considering all three basic flip operations F = {W , S, T }, namely wall slides, simple flips, and T-flips, there are 2 3 = 8 possible subsets of F to induce an equivalence relation on R n . Which of these equivalence relations are interesting (apart from ∅, {W }, and {W , S} considered here), and what are suitable representatives that can be generated efficiently?
We proceed with the induction step for (e). If π, ρ in J (L n ) differ in a jump of the value j = n, then (e) follows from the definition (e) and of the sequences # " c (π i ) and #" c (π i ). On the other hand, consider π, ρ in J (L n−1 ) that differ in a jump of some value j ∈ {2, . . . , n − 1}, and let π , ρ be the next two permutations in J (L n−1 ) that differ in a jump of j, satisfying (e) by induction. Then in J (L n ), after the jump of j from c 1 (π ) to c 1 (ρ) or from c n (π ) to c n (ρ), the next jump of the value j is from c 1 (π ) to c 1 (ρ ) or from c n (π ) to c n (ρ ). If j is not at the first position in ρ and the value left of it is smaller than j, then j is not at the first position and the value left of it is smaller in both c 1 (ρ) and c n (ρ), and c 1 (ρ ) and c n (ρ ) are obtained from c 1 (π ) and c n (π ), respectively, by a left jump. On the other hand, if j is at the first position in ρ or the value left of it is bigger than j, then j is at the first position or the value left of it is bigger than j in both c 1 (ρ) and c n (ρ), and c 1 (ρ ) and c n (ρ ) are obtained from c 1 (π ) and c n (π ), respectively, by a right jump. This completes the proof.
Proof of Lemma 8. 9 We prove these properties by induction on n. The induction basis n = 1 is trivial. For the induction step let n ≥ 2 and assume that all properties hold for the sequence J (L n−1 ). We first show the induction step for (a), (b), and (c). Consider a permutation π in J (L n ) and define π := p(π ) ∈ S n−1 .
To prove (a), let π = id n be the first permutation in J (L n ) (recall Lemma 8.3(a)). We have π = id n−1 and by induction and (a) we hence have s π n = (1, 2, . . . , n − 1). Using (4a) we obtain s π n = (1, 2, . . . , n), as claimed. To prove (b), let π be a permutation that is not the last in the sequence J (L n ), and let ρ be the permutation succeeding π in J (L n ). If π is not the last permutation in the subsequence c(π ) of J (L n ), then by (2) the permutation ρ is obtained from π by a jump of the value n, and then (b) follows directly from (4b). On the other hand, if π is the last permutation in the subsequence c(π ), then ρ is obtained from π by a jump of the value s π n−1,n−1 by induction and (b), and by (5c) we have s π n,n = s π n−1,n−1 , as desired.
To prove (c), let π be the last permutation in J (L n ). Then the permutation π is also the last permutation in J (L n−1 ), so by induction we have s π n−1,n−1 = 1. Using (5c) we see that s π n,n = s π n−1,n−1 = 1, as desired. To prove (d), note that p(π ) = p(ρ) = p(σ ) and therefore ρ is not the last permutation in the subsequence c( p(ρ)), so the claim follows directly from (4a).
If j < n − 1, then π and ρ differ in a jump of j < n − 1, and ρ and σ differ in a jump of n − 1 by (2). As j is not at a boundary position in p n− j (ρ) = p n−1− j (ρ ), we have s We now prove (g), and again we distinguish whether j = n − 1 or j < n − 1. If j = n − 1, then π and ρ differ in a jump of j = n − 1, in particular p(π ) = p(ρ ), and as j = n −1 is at a boundary position in p n− j (ρ) = p(ρ) = ρ , ρ and σ differ in a jump of some value smaller than n −1 by (2). Consequently, we have s n−2,n−2 = s π n−1,n−2 by (4a). Combining these observations shows that indeed (g) holds in this case.
If j < n − 1, then π and ρ differ in a jump of j < n − 1, and ρ and σ differ in a jump of n − 1 by (2). Clearly, j is at a boundary position in p n− j (ρ) = p n−1− j (ρ ), and by induction and (g) we have s

Appendix B: S-Equivalence of Rectangulations
Recall that R-equivalence is the equivalence relation on R n obtained from wall slides, i.e., any two generic rectangulations that differ in a sequence of wall slides are equivalent. It is well known that every equivalence class contains exactly one diagonal rectangulation, i.e., D n is a set of representatives for R-equivalence (see e.g. [9]).
We aim to do something analogous for S-equivalence, and to pick a suitable set of representatives for our generation algorithm. Recall that S-equivalence is the equivalence relation on R n obtained from wall slides and simple flips, i.e., any two generic rectangulations that differ in a sequence of wall slides or simple flips are equivalent. Figure 23 shows the equivalence classes of generic rectangulations under S-equivalence for n = 2, 3, 4. Unfortunately, one can check that there is no choice of representatives P 2 ⊆ R 2 , P 3 ⊆ R 3 , P 4 ⊆ R 4 for those equivalence classes (i.e., |P 2 | = 1, |P 3 | = 2, |P 3 | = 6) that is consistent with the operations of rectangle deletion and insertion, i.e., such that P 2 = {p(R) | R ∈ P 3 } and P 3 = {p(R) | R ∈ P 4 }. Consequently, for S-equivalence there is no set of unique representatives, one for each equivalence class, that would form a zigzag set, so our generation algorithms cannot be applied directly. However, we will show how to choose representatives for each equivalence class (highlighted in Fig. 23), such that those representatives and the rectangulations obtained from them by a simple flip of the rectangle r n admit a generation tree approach with our algorithms.
(a) (c) (b) (d) Fig. 24 Illustration of aligned rectangulations. Rectangulation a is V-aligned, b is AV-aligned, c is Valignable but neither V-aligned nor AV-aligned, d is V-aligned and AH-aligned aligned for short, if all of its walls except one at the right are vertical. Equivalently, it is obtained by gluing copies of on the left of . The rectangulation is H-aligned and V-aligned. The rectangulation is H-aligned and AV-aligned, and the rectangulation is V-aligned and AH-aligned. A rectangulation is H-or V-alignable, if we can apply a sequence of simple flips to make it Hor V-aligned, respectively. Clearly, a rectangulation is H-alignable if it is obtained by vertically gluing together copies of and , and it is V-alignable if it is obtained by horizontally gluing together copies of and . A block in a rectangulation is a subset of rectangles whose union is a rectangle. The size of a block is the number of rectangles of the block.

Lemma B.1 Every diagonal rectangulation can be partitioned uniquely into maximal alignable blocks.
Proof Suppose for the sake of contradiction that for some rectangulation R ∈ D n there were two distinct block partitions P, P of R. Consider a block B in P that is not a block in P . Consider one of the rectangles in B, and consider the block B of P containing this rectangle. As R does not have any points where four rectangles meet and B = B, the block B must be a proper subset or superset of B, contradicting the maximal choice of the blocks. Lemma B.1 holds more generally for generic rectangulations and for maximal blocks with any additional property (such as alignable), but this is not needed here.

Lemma B.2 For any diagonal rectangulation, the partition into maximal alignable blocks is invariant under simple flips.
Proof Consider a wall that can be simple-flipped, and observe that the two rectangles to both sides of the wall must belong to the same alignable block due to the maximal choice of the blocks.
From now on, whenever we refer to a block in a rectangulation, we mean a maximal alignable block. A block is a base block, if it contains the bottom boundary of the rectangulation.
Based on the partition of a diagonal rectangulation R ∈ D n into blocks, which is unique by Lemma B.1, we introduce the following definitions; see Fig. 25. We refer to each block of R as an H-block or V-block, if it is H-alignable or V-alignable, respectively. We consider an H-block B of size at least 2 with rectangle r i at the bottomright. If i = n or if rectangle r i+1 of R is below r i we say that B is free, whereas if (a) We say that R ∈ D n is block-aligned if for every block B of size at least 2 in R the following conditions hold: if B is a free H-block then B is H-aligned, if B is a free V-block then B is V-aligned, if B is a locked H-block then B is AH-aligned, and if B is a locked V-block then B is AV-aligned. A special rule applies if the rectangle r n is contained in a block of size 2 (which is free and both H-alignable and V-alignable), and then we require this block to be V-aligned, unless it is a base block, in which case it must be H-aligned. Note that a block B of size exactly 2 that does not contain r n is both an H-block and a V-block, however, if B is a locked/free H-block then B is a free/locked V-block, respectively, so this definition is consistent (as AH-aligned equals V-aligned and H-aligned equals AV-aligned for a block of size 2).
We write B n ⊆ D n for the set of diagonal rectangulations that are block-aligned. We partition this set into B n and B n , respectively, according to whether the rectangle r n is contained in a block of size 1 or at least 2, respectively. Note that if R ∈ B n , then the wall between r n and r n−1 does not admit a simple flip, whereas if R ∈ B n , then this wall admits a simple flip. For any R ∈ B n we write s(R) ∈ B n for the rectangulation obtained from r n by a simple flip of this wall. The set B n is partitioned into B n and B n according to whether this wall is horizontal or vertical, respectively.
As a consequence of Lemma B.2, every equivalence class of generic rectangulations under S-equivalence contains exactly one block-aligned diagonal rectangulation; see Fig. 23. Consequently, we will use the block-aligned rectangulations B n ⊆ D n as representatives for S-equivalence.

B.2 Insertion in Block-Aligned Rectangulations
The next two lemmas describe how to construct block-aligned rectangulations by rectangle insertion; see Fig. 27. For any diagonal rectangulation R ∈ D n , we let I v (R) denote the subsequence of I (R) of the first insertion point of each vertical group. Similarly, we let I h (R) denote the subsequence of I (R) of the last insertion point of each horizontal group. Lemma B.3 Let P ∈ B n−1 , I v (P) =: (q i 1 , . . . , q i λ ), and I h (P) =: (q j 1 , . . . , q j μ ). Then we have the following: • For any 1 ≤ k < λ we have c i k (P) ∈ B n , and every R ∈ B n for which the top-left vertex of r n has type and r n−1 forms its own block is obtained by insertion from some P ∈ B n−1 in this way. • For any 1 < k ≤ μ we have c j k (P) ∈ B n , and every R ∈ B n for which the topleft vertex of r n has type and r n−1 forms its own block is obtained by insertion from some P ∈ B n−1 in this way. • If λ > 1 we have c j 1 (P) ∈ B n , and every R ∈ B n for which r n−1 and r n form a V-aligned block of size 2 is obtained by insertion from some P ∈ B n−1 in this way. • If λ = 1 we have c i 1 (P) ∈ B n , and every R ∈ B n for which r n−1 and r n form an H-aligned base block of size 2 is obtained by insertion from some P ∈ B n−1 in this way.
Proof The first and second part of the lemma are symmetric, so it suffices to prove the first one. For this we analyze how the blocks of R := c i k (P) differ from the blocks of P, and prove that they are all aligned as required. The rectangle r n−1 forms a block of size 1 in P, and as k < λ this is also true in R. Similarly, as k < λ the rectangle r n forms a block of size 1 in R. Consequently, we only need to verify whether blocks of R not containing r n−1 or r n in P are aligned as required. If k = 1, then the blocks of R are the same as those of P, plus the block containing r n , so we are done; see Fig. 26a. If k > 1, we let r a and r b be the rectangles in P to the left and right of the edge that contains the insertion point q i k . If r a and r b belong to two distinct blocks in P, then the blocks of R are the same as those of P, plus the block containing r n , so we are done; see Fig. 26b. On the other hand, if r a and r b belong to the same block B in P, then it must be a free V-block that is V-aligned or a locked H-block that AH-aligned, and we have b = a + 1. If B is a free V-block in P, then in R this block is split into two free V-blocks B and B , one containing r a and the other one containing r b = r a+1 , and both B and B are V-aligned; see Fig. 26c. If B is a locked H-block in P, then in R this block is split into the H-block B \{r a , r a+1 }, and two blocks of size 1 containing r a or r a+1 , respectively; see Fig. 26d. Moreover, if |B| = 3 then |B \ {r a , r a+1 }| = 1, and otherwise B \ {r a , r a+1 } is a free H-block that is H-aligned in R. In all cases we obtain R ∈ B n , as claimed.
We continue to prove the third part of the lemma about the rectangulation R := c j 1 (P). The rectangle r n−1 forms a block of size 1 in P, and together with r n it forms a block of size 2 in R; see Fig. 26e. This block is V-aligned in R, so we have R ∈ B n , as claimed.
It remains to prove the fourth part of the lemma about the rectangulation R := c i 1 (P).The rectangle r n−1 forms a block of size 1 in P, and together with r n it forms a block of size 2 in R; see Fig. 26f. This block is a base block and H-aligned in R, so we have R ∈ B n , as claimed. Lemma B.4 Let P ∈ B n−1 and P := s(P), or let P ∈ B n−1 and P := s(P ), and define I v (P) =: (q i 1 , . . . , q i λ ) and I h (P ) =: (q j 1 , . . . , q j μ ). Then we have the following: • For any 1 ≤ k < λ we have c i k (P) ∈ B n , and every R ∈ B n for which the top-left vertex of r n has type and r n−1 is contained in a block of size at least 2 is obtained by insertion from some P ∈ B n−1 in this way. • For any 1 < k ≤ μ we have c j k (P ) ∈ B n , and every R ∈ B n for which the top-left vertex of r n has type and r n−1 is contained in a block of size at least 2 is obtained by insertion from some P ∈ B n−1 in this way. • We have c i λ (P) ∈ B n , and every R ∈ B n for which r n−1 and r n are contained in an H-aligned block of size at least 3 is obtained by insertion from some P ∈ B n−1 in this way. • We have c j 1 (P ) ∈ B n , and every R ∈ B n for which r n−1 and r n are contained in a V-aligned block of size at least 3 is obtained by insertion from some P ∈ B n−1 in this way.

Proof
The proof for the first part in the case P ∈ B n−1 and for the second part in the case P ∈ B n−1 is analogous to the proof of Lemma B.3. Therefore, by symmetry, to complete the proof of the first two parts, it suffices to argue about the case P ∈ B n−1 , P := s(P ) and the rectangulation R := c i k (P) for 1 ≤ k < λ; see Fig. 26g. The V-block B in P containing r n−1 , which is free and V-aligned in P , is AV-aligned and free in P. Consequently, in R the block B is either split into two blocks, a free V-block B that is V-aligned to the left of a locked V-block B (Fig. 26g1) that is AV-aligned, or B remains a single locked V-block that is AV-aligned in R (Fig. 26g2), where the locking is due to the insertion of r n . The remaining blocks of P are treated as in the proof of Lemma B.3. In all cases we obtain that R ∈ B n , as claimed.
The third and fourth part of the lemma are symmetric, so it suffices to prove the third one about the rectangulation R := c i λ (P). In this case {r n−2 , r n−1 , r n } is an H-block that is free and H-aligned in R, and either |B \ {r n−2 , r n−1 }| = 1 or B \ {r n−2 , r n−1 } is a V-block that is free and V-aligned in R; see Fig. 26h. It follows that R ∈ B n , as claimed.

B.3 Tree of Block-Aligned Rectangulations
By Lemmas B.3 and B.4, all block-aligned rectangulations B n can be obtained by suitable rectangle insertions into all block-aligned rectangulations B n−1 and s(B n−1 ). We consider the subtree of the tree of rectangulations discussed in Sect. 3.4 induced by the rectangulations B n and s(B n ) for all n ≥ 1. By gluing together pairs of nodes (R, s(R)) for all R ∈ B n , we obtain the tree shown in Fig. 27.
For any P ∈ B n−1 ∪ s(B n−1 ) and P := s(P), using the notation from Lemma B.4 we define c(P) := (c i 1 (P), . . . , c i λ−1 (P), c i λ (P), c j 1 (P ), c j 2 (P ), . . . , c j μ (P )). (6b) These sequences define an ordering among the children of each node in the aforementioned (unordered) tree of block-aligned rectangulations. Note that any two consecutive rectangulations in the sequence (6a) differ in a Tflip, except c i λ−1 (P) and c j 1 (P), and c i 1 (P) and c j 2 (P), which differ in a T-flip plus a simple flip. Similarly, any two consecutive rectangulations in the sequence (6b) differ in a T-flip, except c i λ (P) and c j 1 (P ), which differ in a simultaneous flip of the two walls between r n , r n−1 , and r n−2 . We refer to this operation as a D-flip (D like 'double').

B.4 Next Oracle for Block-Aligned Rectangulations
Using (6), we may modify the minimal jump oracle next D n for diagonal rectangulations described in Sect. 7.2 for the generation of block-aligned rectangulations within Lines N2-N4 are symmetric to lines N5-N7, so we only consider N2-N4; see the illustrations in Fig. 28. Lines N2 and N4 perform a T-flip, possibly followed by a simple flip. Line N3 performs a simple flip followed by a T-flip, possibly followed by a simple flip, and in this case the combination of three flips, simple flip plus T-flip plus simple flip, yields a D-flip overall. The function lock(R, j, dir), dir ∈ { , }, called at the end of each of the lines N2-N7 checks whether rectangle r j participates in an H-aligned block (if dir = ) or V-aligned block (if dir = ) that is locked and must be transformed to an AH-aligned block or AV-aligned block by a simple flip. The function unlock(R, j, d), d ∈ { , }, called at the beginning in line N1 does the converse, namely checking whether r j participates in an AH-aligned block or AV-aligned block that must be made H-aligned or V-aligned, respectively, before performing a jump of rectangle r j in direction d. The implementation of these functions is shown below for the cases dir = and d = . The other variants dir = and d = are omitted for simplicity.  ] or R [ j] are one simple flip away from such a configuration. Similarly, to use this oracle in conjunction with the oracle next B n (P) defined in Sect. 7.3, we need to test containment of a pattern P in the rectangulation R after a jump of rectangle r j not only via contains(R, j, P), but also using contains(R, j − 1, P) and contains(R, j + 1, P), as all three rectangles r j−1 , r j , and r j+1 may be modified through one call of next B n (R, j, d). For details see our C++ implementation [45].
We obtain the following analogue of Theorems 4.2 and 5.1. Proof The oracle next B n (P) repeatedly calls the function next B n . Applying Theorem 7.7 with the bound f n = O(1) from Lemma B.6 and the bound t n = O(1) from Lemma 7.8, the term n( f n + t n ) evaluates to O(n), as claimed. Table 4 is the counterpart of Table 3 shown in Sect. 9 for block-aligned rectangulations C n = B n as a base class. Note that the patterns P 3 , . . . , P 8 cannot be used, as they do not satisfy the conditions of Theorem B.5.

Appendix D: Visualization of Gray Codes
In this section we visualize the Gray codes obtained from our algorithms for generic rectangulations, diagonal rectangulations and block-aligned rectangulations (without any forbidden patterns). The corresponding 2-clumped permutations are shown below each rectangulation.