1 Introduction

The term flip is commonly used in combinatorics to refer to an elementary, local, reversible operation that transforms one combinatorial object into another. Such flip operations naturally yield a flip graph, whose vertices are the considered combinatorial objects, and two of them are adjacent if they differ by a single flip. A classical example is the flip graph of triangulations of a convex polygon [46, 57]; see Fig. 1. The vertex set of this graph are all triangulations of the polygon, and two triangulations are adjacent if one can be obtained from the other by replacing the diagonal of a quadrilateral formed by two triangles by the other diagonal. Similar flip graphs have also been investigated for triangulations of general point sets in the plane [16], triangulations of topological surfaces [41], and planar graphs [6, 10]. The flip distance between two combinatorial objects is the minimum number of flips needed to transform one into the other. It is known that computing the flip distance between two triangulations of a simple polygon [4] or of a point set [37] is NP-hard. The latter is known to be fixed-parameter tractable [33]. On the other hand, the NP-hardness of computing the flip distance between two triangulations of a convex polygon is a well-known open question [12, 13, 17, 34, 38, 54]. Flip graphs involving other geometric configurations have also been studied, such as flip graphs of non-crossing perfect matchings of a point set in the plane, where flips are with respect to alternating 4-cycles [11], or alternating cycles of arbitrary length [29]. Other flip graphs include the flip graph on plane spanning trees [2], the flip graph of non-crossing partitions of a point set or dissections of a polygon [28], the mutation graph of simple pseudoline arrangements [53], the Eulerian tour graph of an Eulerian graph [59], and many others. There is also a vast collection of interesting flip graphs for non-geometric objects, such as bitstrings, permutations, combinations, and partitions [22].

Fig. 1
figure 1

The flip graph of triangulations of a convex polygon

In essence, a flip graph provides the considered family of combinatorial objects with an underlying structure that reveals interesting properties about the objects. It can also be a useful tool for proving that a property holds for all objects, by proving that one particularly nice object has the property, and that the property is preserved under flips. Flip graphs are also an essential tool for solving fundamental algorithmic tasks such as random and exhaustive generation, see e.g. [3, 7, 50].

The focus of the present paper is on flip graphs for orientations of graphs satisfying some constraints. First, we consider so-called \(\alpha\)-orientations, in which the outdegree of every vertex is specified by a function \(\alpha\), and the flip operation consists of reversing the orientation of all edges in a directed cycle. We study the complexity of computing the flip distance between two such orientations. An interesting special case of \(\alpha\)-orientations corresponds to perfect matchings in bipartite graphs, where flips involve alternating cycles. We also consider the dual notion of c-orientations, in which the number of forward edges along each cycle is specified by a function c. Here a flip consists of reversing all edges in a directed cut. We also analyze the computational complexity of the flip distance problem in c-orientations.

There are several deep connections between flip graphs and polytopes. Specifically, many interesting flip graphs arise as the (1-)skeleton of a polytope. For instance, flip graphs of triangulations of a convex polygon are skeletons of associahedra [15], and flip graphs of regular triangulations of a point set in the plane are skeletons of secondary polytopes (see [16, Chapter 5]). Associahedra are generalized by quotientopes [48], whose skeletons yield flip graphs on rectangulations [14], bitstrings, permutations, and other combinatorial objects. Moreover, flip graphs of acyclic orientations or strongly connected orientations of a graph are skeletons of graphical and co-graphical zonotopes, respectively (see [45, Sect. 2]). Similarly, as we show below, flip graphs on \(\alpha\)-orientations are skeletons of matroid intersection polytopes. We also consider vertex flips in c-orientations, inducing flip graphs that are distributive lattices and in particular subgraphs of skeletons of certain distributive polytopes. These polytopes specialize to flip polytopes of planar \(\alpha\)-orientations, are generalized by the polytope of tensions of a digraph, and form part of the family of alcoved polytopes (see [21]).

In the next section, we give the precise statements of the computational problems we consider, connections with previous work, and the statements of our main results. In Sect. 4, we give the proof of our first main result, showing that computing the flip distance between \(\alpha\)-orientations and between perfect matchings is NP-hard even for planar graphs. Section 5 presents the proof of our second main result, where we give a polynomial time algorithm to compute the vertex flip distance between c-orientations. Finally, in Sect. 6 we show that computing the distance between c-orientations, when double vertex flips are also allowed, is NP-hard.

2 Problems and Main Results

2.1 Flip Distance Between \(\alpha\)-Orientations

Given a graph G and some \(\alpha :V(G) \rightarrow {\mathbb {N}}_0\), an \(\alpha\)-orientation of G is an orientation of the edges of G in which every vertex v has outdegree \(\alpha (v)\). An example for a graph and two \(\alpha\)-orientations for this graph is given in Fig. 2. A flip of a directed cycle C in some \(\alpha\)-orientation X consists of the reversal of the orientation of all edges of C, as shown in the figure. Edges with distinct orientations in two given \(\alpha\)-orientations X and Y induce an Eulerian subdigraph of both X and Y. They can therefore be partitioned into an edge-disjoint union of cycles in G which are directed in both X and Y. Hence the reversal of each such cycle in X gives rise to a flip sequence transforming X into Y and vice versa. We may thus define the flip distance between two \(\alpha\)-orientations X and Y to be the minimum number of cycles in a flip sequence transforming X into Y. We are interested in the computational complexity of determining the flip distance between two given \(\alpha\)-orientations.

Fig. 2
figure 2

Two \(\alpha\)-orientations of a graph and a flip between them, where the values of \(\alpha\) are depicted on the vertices

Problem 1

Given a graph G, some \(\alpha :V(G) \rightarrow {\mathbb {N}}_0\), a pair XY of \(\alpha\)-orientations of G and an integer \(k \ge 0\), decide whether the flip distance between X and Y is at most k.

The crucial difficulty of this problem is that a shortest flip sequence transforming X into Y may flip edges that are oriented the same in X and Y an even number of times, to reach Y with fewer flips compared to only flipping edges that are oriented differently in X and Y; see the example in Fig. 3. This motivates the following variant of the previous problem:

Problem 2

Given \(G,\alpha ,X,Y,k\) as in Problem 1, decide whether the flip distance between X and Y is at most k, where we only allow flipping edges that are oriented differently in X and Y.

Fig. 3
figure 3

An \(\alpha\)-orientation X of a graph. The \(\alpha\)-orientation Y obtained by flipping the four directed facial cycles \(C_1,\ldots ,C_4\) can be reached with fewer flips by flipping only the three directed facial cycles \(D_1,D_2,D_3\) in this order

2.2 From \(\alpha\)-Orientations to Perfect Matchings

The flexibility in choosing a function \(\alpha\) for a set of \(\alpha\)-orientations on a graph allows us to capture numerous relevant combinatorial structures, some of which are listed below:

  • domino and lozenge tilings of a plane region [52, 58],

  • planar spanning trees [26],

  • (planar) bipartite perfect matchings [39],

  • (planar) bipartite d-factors [18, 47],

  • Schnyder woods of a planar triangulation [8],

  • Eulerian orientations of a (planar) graph [18],

  • k-fractional orientations of a planar graph with specified outdegrees [5],

  • contact representations of planar graphs with homothetic triangles, rectangles, and k-gons [19, 23, 24, 27].

In the following, we focus on perfect matchings of bipartite graphs. Consider any bipartite graph G with bipartition \((V_1,V_2)\) equipped with

$$\begin{aligned} \alpha :V(G) \rightarrow {\mathbb {N}}_0, \quad \alpha (x):= {\left\{ \begin{array}{ll} 1 &{} \quad {\text { if }} x \in V_1, \\ d_G(x)-1 &{} \quad {\text { if }} x \in V_2. \end{array}\right. } \end{aligned}$$

With this definition, in each \(\alpha\)-orientation of G, the edges directed from \(V_1\) to \(V_2\) form a perfect matching. This is illustrated in Fig. 4. Conversely, given a perfect matching M of G, orienting all edges of M from \(V_1\) to \(V_2\) and all the other edges from \(V_2\) to \(V_1\) yields an \(\alpha\)-orientation of the above type. Furthermore, the directed cycles in any \(\alpha\)-orientation of G correspond to the alternating cycles in the associated perfect matching. Flipping an alternating cycle in a perfect matching corresponds to exchanging matching and non-matching edges. An example of the flip graph of perfect matchings of a graph is given in Fig. 5. In this special case, Problem 1 boils down to:

Fig. 4
figure 4

An \(\alpha\)-orientation of a bipartite graph and the corresponding perfect matching

Problem 3

Given a bipartite graph G, a pair XY of perfect matchings in G and an integer \(k \ge 0\), decide whether the flip distance between X and Y is at most k.

Fig. 5
figure 5

The flip graph of perfect matchings of a graph. The solid edges indicate flips along facial cycles, and the dashed edges indicate flips along non-facial cycles

Fig. 6
figure 6

A perfect matching X in a graph. The perfect matching Y obtained by flipping the four alternating facial cycles \(C_1,\ldots ,C_4\) can be reached with fewer flips by flipping only the three alternating facial cycles \(D_1,D_2,D_3\) in this order

The example from Fig. 3 can be easily modified to show that when transforming X into Y using the fewest number of flips, we may have to flip alternating cycles that are not in the symmetric difference of X and Y; see the example in Fig. 6. If we restrict the flips to only use cycles in the symmetric difference of X and Y, then the problem of finding the flip distance becomes trivial, as the symmetric difference is a collection of disjoint cycles, and each of them has to be flipped, so Problem 2 is trivial for perfect matchings.

2.3 Flip Graphs and Matroid Intersection Polytopes

We proceed to give a geometric interpretation of the flip distance between \(\alpha\)-orientations as the distance in the skeleton of a 0/1-polytope.

Recall that a matroid is an abstract simplicial complex \((E,{\mathcal {I}})\), where \({\mathcal {I}}\subseteq 2^E\) satisfies the independent set augmentation property. The elements of \({\mathcal {I}}\) are called independent sets. A base of the matroid is an inclusionwise maximal independent set.

It is well-known that perfect matchings in a bipartite graph \(G=(V_1\cup V_2,E)\) are common bases of two partition matroids \((E,{\mathcal {I}}_1)\) and \((E,{\mathcal {I}}_2)\), in which a set of edges is independent if no two share an endpoint in \(V_1\), or, respectively, in \(V_2\).

Similarly, \(\alpha\)-orientations can be defined as common bases of two partition matroids. In this case, every edge of the graph G is replaced by a pair of parallel arcs, one for each possible orientation of the edge. One matroid ensures that in a basis, for every edge exactly one orientation is chosen. The second matroid encodes the constraint that in a basis, each vertex v has exactly \(\alpha (v)\) outgoing arcs.

The common base polytope of two matroids is a 0/1-polytope obtained as the convex hull of the characteristic vectors of the common bases. Adjacency of two vertices of this polytope has been characterized by Frank and Tardos [25]. A shorter proof was given by Iwata [30]. We briefly recall their result in the next theorem. To state the theorem, consider a matroid \(M=(E,{\mathcal {I}})\), a base \(B\in {\mathcal {I}}\), and a subset \(F\subseteq E\). The exchangeability graph G(BF) of M is a bipartite graph with \(B\setminus F\) and \(F\setminus B\) as vertex bipartition, and edge set \(\{ ij \mid B\setminus \{i\}\cup \{j\} \text { is a basis}\}\). This definition and the theorem are illustrated in Fig. 7 for the two partition matroids whose common bases are perfect matchings of a graph.

Theorem 1

([25, 30]) For two matroids \(M^+ = (E,{\mathcal {I}}^+)\) and \(M^- = (E,{\mathcal {I}}^-)\), two common bases \(A,\!B\in {\mathcal {I}}^+\cap {\mathcal {I}}^-\) are adjacent on the common base polytope if and only if all the following conditions hold:

  1. (i)

    the exchangeability graph G(AB) of \(M^+\) has a unique perfect matching \(P^+\),

  2. (ii)

    the exchangeability graph G(BA) of \(M^-\) has a unique perfect matching \(P^-\),

  3. (iii)

    \(P^+ \cup P^-\) is a single cycle.

From this theorem we can conclude that the flip graphs we consider on perfect matchings and \(\alpha\)-orientations are precisely the skeletons of the corresponding polytopes of common bases.

It is interesting to compare Problems 1 and 3 with the analogous problems for other families of matroid polytopes. For instance, it is known that for two bases AB of a matroid, the exchangeability graph G(AB) has a perfect matching [9]. Hence A can be transformed into B by performing \(|A\Delta B|/2\) exchanges of elements (where \(A\Delta B\) is the symmetric difference of A and B), which is also the distance in the skeleton of the base polytope of the matroid. On the other hand, the problem of computing the flip distance between two triangulations of a convex polygon amounts to computing distances in skeletons of associahedra, which are known to be polymatroids (see [1] and references therein). This problem is neither known to be in ¶ nor known to be NP-hard. Also note that for other families of combinatorial polytopes, testing adjacency is already intractable. This is the case for instance for the polytope of the Traveling Salesman Problem (TSP) [42], whose skeleton is known to have diameter at most 4 [51]. On the other hand, the corresponding polytope is known to be the common base polytope of three matroids.

Another important class of combinatorial polytopes are alcoved polytopes, see [36]. It is known that the flip graphs of planar \(\alpha\)-orientations are skeletons of alcoved polytopes, see [21]. Thus, by our results below, flip distances in this class are also NP-hard to compute.

Fig. 7
figure 7

Two common bases A and B (left and middle) of the matroids \(M^+\) and \(M^-\), where \(M^+\) and \(M^-\) have as independent sets all subsets of edges of the graph where no two share an endpoint in the set of circled vertices, or the set of squared vertices, respectively. The right hand side shows the exchangeability graphs G(AB) of \(M^+\) (solid edges) and G(BA) of \(M^-\) (dashed edges). As the conditions of Theorem 1 are met, the two bases are adjacent in the common base polytope, and adjacent in the flip graph shown in Fig. 5

2.4 Hardness of Flip Distance Between Perfect Matchings and \(\alpha\)-Orientations

We prove that Problem 3 is NP-complete, even for 2-connected bipartite subcubic planar graphs and \(k=2\). This clearly implies that Problem 1 is NP-complete as well.

Theorem 2

Given a 2-connected bipartite subcubic planar graph G and a pair XY of perfect matchings in G, deciding whether the flip distance between X and Y is at most two is NP-complete.

As direct consequences of the proof of Theorem 2 we get:

Corollary 1

Unless \({\textsf P} ={\textsf {NP}}\), deciding whether the flip distance between two perfect matchings is at most k is not fixed-parameter tractable with respect to parameter k.

Corollary 2

Unless \({\textsf{P}} ={\textsf {NP}}\), the flip distance between two perfect matchings is not approximable within a multiplicative factor \(3/2-\epsilon\) in polynomial time, for any \(\epsilon >0\).

We also prove that Problem 2 is NP-complete, even for 4-regular graphs and \(k=2\).

Theorem 3

Given a 4-regular graph G and a pair XY of \(\alpha\)-orientations of G, deciding whether the flip distance between X and Y is at most two is NP-complete. Moreover, the problem remains NP-complete if we only allow flipping edges that are oriented differently in X and Y

The proofs of Theorems 2 and 3 are presented in Sect. 4.

2.5 From \(\alpha\)-Orientations in Planar Graphs to c-Orientations

In what follows, we generalize the problem, via planar duality, to flip distances in so-called c-orientations.

Consider an arbitrary 2-connected plane graph G and its planar dual \(G^*\). Then for any orientation D of the edges of G, the directed dual \(D^*\) of D is obtained by orienting any dual edge forward if it crosses a left-to-right arc in D in a simultaneous plane embedding of G and \(G^*\), and backward otherwise; see Fig. 8. Edge sets of directed cycles in D correspond to edge sets of minimal directed cuts in \(D^*\) and vice-versa. Hence D is acyclic (respectively, strongly connected) if and only if \(D^*\) is strongly connected (respectively, acyclic). A directed vertex cut is a cut consisting of all edges incident to a sink or a source vertex. Directed facial cycles in D are in bijection with the directed vertex cuts in \(D^*\), and vice versa. The unbounded face in the plane embedding of D can be chosen such that it corresponds to a fixed vertex \(\top\) in \(D^*\).

Let D be an \(\alpha\)-orientation of G. Given a minimal cut in D separating \(U \subseteq V(D)\) from \(\overline{U}:=V(D) \setminus U\), we denote by \(\delta ^+(U)\) the edges pointing from U to \(\overline{U}\) in D. We also let \(d_D^+(v)\) denote the outdegree of vertex v in D. We have

$$\begin{aligned} |\delta ^+(U)|=\sum _{v \in U}{d_D^+(v)}-|E(G[U])|=\sum _{v \in U}{\alpha (v)}-|E(G[U])|, \end{aligned}$$

which only depends on \(\alpha\) and G. Consequently, the set of orientations of \(G^*\) which are directed duals of \(\alpha\)-orientations of G can be characterized by the property that for every cycle C in \(G^*\), the number of edges in clockwise direction is fixed by a certain value c(C) independent of the orientation. The flip operation between \(\alpha\)-orientations of D consists of the reversal of a directed cycle. In the corresponding set of dual orientations of \(D^*\), this translates to the reversal of the orientations of the edges in a minimal directed cut, as shown on Fig. 8.

Fig. 8
figure 8

Duality between flips in \(\alpha\)-orientations (solid edges) and in c-orientations (dashed edges)

The same notion has been investigated more generally without planarity conditions under the name of c-orientations by Propp [47] and Knauer [31]. Given a graph G, we can fix an arbitrary direction of traversal for each cycle C. Given a graph and an assignment \(c(C) \in {\mathbb {N}}_0\) to each cycle in G, one may define a c-orientation of G to be an orientation having exactly c(C) edges in forward direction for every cycle C in G. Note that it is sufficient to define the function c on a cycle basis of G, which consists of no more than |E(G)| cycles. The flip operation on the set \({\mathcal {R}}_c\) of such c-orientations of a graph is defined as the reversal of all edges in a minimal directed cut. It is not difficult to see that flips make the set of c-orientations of a graph connected (this will be noted in Sect. 5).

From the duality between planar \(\alpha\)-orientations and planar c-orientations, determining flip distances between \(\alpha\)-orientations of 2-connected planar graphs reduces to determining flip distances between the dual c-orientations. Note that planar duals of bipartite graphs are exactly the Eulerian planar graphs. Theorem 2 therefore directly yields:

Corollary 3

Given an Eulerian planar graph G and a pair XY of c-orientations of G, deciding whether the flip distance between X and Y is at most two is NP-complete.

2.6 c-Orientations and Distributive Lattices

A more local operation consists of flipping only directed vertex cuts, induced by sources and sinks, excluding a fixed vertex \(\top\). We will refer to this special case as a vertex flip. Specifically, given a pair of c-orientations XY of a graph G with a fixed vertex \(\top\), we aim to transform X into Y using only vertex flips at vertices distinct from \(\top\).

A c-orientation X of G might contain a cycle C in G which is directed in X. According to the definition of a c-orientation, this means that C keeps the same orientation in every c-orientation of G. Consequently, any (minimal) directed cut in a c-orientation of G is disjoint from E(C). Contracting the cycle C in G, we end up with a smaller graph \(G'\) containing the same (minimal) directed cuts, such that the c-orientations of G are determined by their corresponding orientations on \(G'\). We can therefore safely assume that the c-orientations that we consider are all acyclic. Similarly, G will be assumed to be connected.

Problem 4

Given a connected graph G with a fixed vertex \(\top\) and a pair XY of acyclic c-orientations, what is the length of a shortest vertex flip sequence transforming X into Y?

We should convince ourselves that under the assumptions made above, every pair of c-orientations is reachable from each other by vertex flips. This property is provided in a much stronger way by a distributive lattice structure on the set \({\mathcal {R}}_c\); see Fig. 9. The next theorem is a special case of Theorem  1 in Propp [47] where the c-orientations are acyclic.

Theorem 4

([31, 47]) Let G be a graph with fixed vertex \(\top\) and \({\mathcal {R}}_c\) a set of acyclic c-orientations of G. Then the partial order \(\le _c\) on \({\mathcal {R}}_c\) in which Y covers X if and only if Y can be obtained from X by flipping a source defines a distributive lattice on \({\mathcal {R}}_c\).

Hence Problem 4 consists of finding shortest paths in the cover graph of a distributive lattice, where the size of the lattice can be exponential in the size of the input G.

Fig. 9
figure 9

The distributive lattice induced by vertex flips in c-orientations. The reference orientation at the bottom is the directed dual \(D^*\) of the orientation D of the graph G used in Figs. 4 and  5, where some parallel arcs incident with \(\top\) are grouped together for simplicity. The numbers depicted at the vertices indicate the number of times that each vertex is flipped with respect to the reference orientation

2.7 Every Distributive Lattice is a Lattice of c-Orientations

We next point out that every distributive lattice is isomorphic to the distributive lattice induced by a set of c-orientations of a graph. This relationship was described by Knauer [32].

In order to represent a given distributive lattice L by an isomorphic lattice of c-orientations, we need to construct a corresponding digraph D(L). For this purpose, we shortly recall a classical result from lattice theory, Birkhoff’s Theorem (see [17]).

For any distributive lattice L, \({\mathcal {J}}(L)\) is the subposet of L induced by the set of join-irreducible elements, these are the elements of L covering exactly one element. On the other hand, given any poset P we may look at the distributive lattice \({\mathcal {O}}(P)\) formed by the downsets of P ordered by inclusion. Birkhoff’s Theorem in our setting asserts that those two operations are inverse in the sense that \(P \cong {\mathcal {J}}({\mathcal {O}}(P))\) for any finite poset P and \({\mathcal {O}}({\mathcal {J}}(L)) \cong L\) for any finite distributive lattice.

The idea is to define a digraph D(L) whose vertex set consists of the elements of \({\mathcal {J}}(L)\) with an additional vertex \(\top\). The digraph is obtained from the natural upward-orientation of \({\mathcal {J}}(L)\) plus additional arcs from all the sinks and sources to \(\top\). Let G(L) be the underlying graph of D(L), and for every cycle C of G(L), fix c(C) to be the number of forward-edges on c in the orientation D(L). Let \({\mathcal {D}}_c\) be the set of c-orientations of G(L). Fix \(\top\) as the unique non-flippable vertex. We now define \(L_c(D(L))\) as the distributive lattice induced on \({\mathcal {D}}\) according to Theorem 4. An example of this construction is provided in Fig. 10.

Fig. 10
figure 10

A distributive lattice L represented by its Hasse diagram (left), the corresponding subposet of join-irreducible elements \({\mathcal {J}}(L)\) (middle), and the digraph D(L) associated with the lattice (right)

The following theorem is an easy consequence of Birkhoff’s Theorem.

Theorem 5

([32]) Let L be any distributive lattice and D(L) be the corresponding digraph as defined above. Then \(L \cong L_c(D(L))\).

Theorem 9 below gives a natural geometric embedding of the lattice L depending on the digraph D(L). This embedding is such that all values \(z_X(x)\) are 0 or 1, and the vectors \(z_X(.)\) are exactly the characteristic vectors of the downsets of \({\mathcal {J}}(L)\). The convex hull of those vectors is known as the order polytope of \({\mathcal {J}}(L)\) [56], which is a particular case of the above-mentioned alcoved polytopes. The problem of computing vertex flip distances between elements of L encoded by c-orientations of G(L) therefore boils down to computing the distance between two downsets of \({\mathcal {J}}(L)\) in their inclusion lattice, which is a simple special case of Problem 4.

2.8 Facial Flips in Planar Graphs

When we consider Problem 4 on planar graphs, restricting to vertex flips and considering the dual plane graph amounts to considering only flips of directed facial cycles, excluding the outer face whose dual vertex is \(\top\). We refer to these as facial flips. Felsner [18] considered distributive lattices induced by facial flips. The following computational problem is a special case of Problem 4.

Problem 5

Given a 2-connected plane graph G and a pair XY of strongly connected \(\alpha\)-orientations, what is the length of a shortest facial flip sequence transforming X into Y?

Zhang et al. [60] recently provided a closed formula for this flip distance, which can be turned into a polynomial-time algorithm. We prove the analogous stronger statement for Problem 4.

Theorem 6

There is an algorithm that, given a graph G with a fixed vertex \(\top\) and a pair XY of c-orientations of G, outputs a shortest vertex flip sequence between X and Y, and runs in time \({\mathcal {O}}(m^3)\) where m is the number of edges.

In the planar case, this directly translates to a polynomial-time algorithm for Problem 5. The proof of Theorem 6 is presented in Sect. 5. In [20], the distributive lattice structure on c-orientations is generalized to so-called \(\Delta\)-bonds, also known as tensions. We believe that our proof of Theorem 6 can be generalized to these objects.

2.9 Flip Distance with Larger Cut Sets

While computing the cut flip distance between c-orientations is an NP-hard problem in general (Theorem 2), there is a polynomial-time-algorithm for computing the distance when only using vertex flips (Theorem 6). It is natural to ask for a threshold between the hard and easy cases of flip distance problems. Our hardness reduction in Sect. 4 involves very long directed cycles, which correspond to flips of directed cuts in the dual c-orientations with cut sets of large size. Consequently, one may hope that the problem gets easier when restricting the sizes of the cut sets involved in a flip sequence. Our last result destroys this hope:

Theorem 7

Let XY be c-orientations of a connected graph G with fixed vertex \(\top\). It is NP-hard to determine the length of a shortest cut flip sequence transforming X into Y, which consists only of minimal directed cuts with interiors of order at most two.

We will present the proof of Theorem 7 in Sect. 6.

3 Preliminaries

In this section we recall some standard terminology concerning digraphs and posets that will be used repeatedly in the paper.

3.1 Cuts and Cut Sets

Given a directed graph D and a subset \(U \subseteq V(D)\) of vertices, we denote by \(\delta (U)\) the set of all arcs in E(D) having one end in U and the other in \(\overline{U}:=V(D) \setminus U\). By \(\delta ^+(U)\), we denote the set of all arcs in E(D) directed from U to \(\overline{U}\). If \(\delta (U)=\delta ^+(U)\), we call \(S=\delta (U)\) a directed cut or dicut induced by U, and U is referred to as a cut set of S. In the case that D is weakly connected, the cut set is uniquely determined by the dicut.

3.2 Posets and Lattices

A partially ordered set, or poset for short, is a pair \((P,\prec )\), where P is a set and \(\prec\) is a reflexive, antisymmetric and transitive binary relation on P. Posets can be represented more compactly by their minimal comparabilities: We say that \(x\prec y\) is a cover relation, or y covers x, if there is no z in the poset with \(x \prec z \prec y\). This defines the cover graph of P, which has the elements of P as vertices, and an edge for every cover relation. The Hasse diagram of P is a drawing of the cover graph in the plane, where vertices are represented by distinct points and for every cover relation \(x\prec y\), the edge between x and y is drawn as a straight line going upwards from x to y.

The downset of an element y in P is the set of all x with \(x\prec y\). A poset P is called a lattice, if for any two elements x and y in P there is a unique smallest element z such that \(x\prec z\) and \(y\prec z\), and a unique largest element z such that \(z\prec x\) and \(z\prec y\). These elements are called the join and the meet of x and y, respectively. A lattice is called distributive, if the join and meet operations distribute over each other.

4 Flip Distance Between Perfect Matchings and Between \(\alpha\)-Orientations

The proof of Theorem 2 is by reduction from the following NP-complete problem.

Theorem 8

(Plesńik [44]) Deciding directed Hamiltonicity of orientations of cubic planar graphs is NP-complete.

The above problem remains NP-complete if we additionally assume 2-connectivity of the cubic graph and that the orientation does not have sinks or sources (otherwise, there is no directed Hamiltonian cycle).

Proof of Theorem 2

As each flip sequence of length at most two can be used as a polynomially verifiable certificate, the problem is clearly in NP.

We now provide a reduction of the decision problem in Theorem 8 to Problem 3. So suppose we are given an orientation D of a 2-connected cubic planar graph without sinks and sources, and assume without loss of generality that \(|V(D)|\ge 3\). Given D, we define an undirected graph \(G=G(D)\) as follows; see Fig. 11: For each vertex \(v\in V(D)\) we create a vertex \(x_v\) in G, and for each arc \(e \in E(D)\) we create a pair of vertices \(x^+_e,x^-_e\) in G. The edges of G are defined as follows: For each arc \(e\in E(D)\), we connect \(x^+_e\) and \(x^-_e\) with an edge in G. Furthermore, we denote by \(V_1\) and \(V_2\) the vertices of D with outdegree 1 or 2, respectively. For each \(v\in V_1\), if \(e,f\in E(D)\) are the two incoming arcs at v and g is the outgoing arc, then we add the edges \(x^+_e x_v\), \(x^+_f x_v\), \(x^+_e x^-_g\), and \(x^+_f x^-_g\) to G. Similarly, for each \(v\in V_2\), if \(e,f\in E(D)\) are the two outgoing arcs at v and g is the incoming arc, then we add the edges \(x^-_ex_v\), \(x^-_f x_v\), \(x^-_e x^+_g\), and \(x^-_f x^+_g\) to G. We refer to the 4-cycles in G formed by these edges as \(C_4\)-gadgets. Note that G is subcubic, planar, 2-connected, and bipartite. Specifically, the bipartition is given by \(\{x_v\mid v\in V_1\}\cup \{x^-_e\mid e\in E(D)\}\) and \(\{x_v\mid v\in V_2\}\cup \{x^+_e\mid e\in E(D)\}\).

Fig. 11
figure 11

\(C_4\)-gadgets to construct the undirected graph \(G=G(D)\) (right) from the digraph D (left) in the proof of Theorem 2. The edges of the matchings X and Y in G are indicated by bold solid and dashed lines, respectively

We construct a pair of perfect matchings XY on G as follows. The first matching X is defined by fixing a particular perfect matching on each \(C_4\)-gadget, and the second matching Y is obtained from X by flipping all cycles formed by the \(C_4\)-gadgets; see Fig. 11. We claim that X and Y have flip distance at most two in G if and only if D has a directed Hamiltonian cycle. From this the theorem follows.

First, assume there is a directed Hamiltonian cycle H in D. We define a pair of cycles \(C_1,C_2\) in G, where \(C_1\) and \(C_2\) both contain all the edges \(\{x^+_e x^-_e\mid e \in E(H)\}\), plus additional edges defined as follows. For each vertex \(v \in V(D)\), consider the corresponding \(C_4\)-gadget in G with the two incident edges corresponding to the edges incident with v on H. The endpoints of those edges on the gadget divide it into two alternating paths in X, one with matching edges at both ends and one with non-matching edges at both ends. We add the edges on those two types of paths to \(C_1\) or \(C_2\), respectively. Note that \(C_1\) is an alternating cycle in X. Moreover, after flipping \(C_1\), the cycle \(C_2\) is alternating, and flipping \(C_2\) yields Y, as each edge in a \(C_4\)-gadget gets flipped once while the remaining edges are flipped an even number of times and thus remain unchanged.

For the reverse implication, assume that X and Y are transformable into each other by flipping at most two alternating cycles. As the symmetric difference \(X\Delta Y\) contains at least three disjoint cycles (recall the assumption \(|V(D)| \ge 3\)), exactly two cycles \(C_1,C_2\) are flipped to transform X into Y, and neither \(C_1\) nor \(C_2\) is one of the 4-cycles formed by the \(C_4\)-gadgets. As the edges outside the gadgets remain unchanged, they are covered by both \(C_1,C_2\) or by neither of them. We claim that \(H:=\{e \in E(D)\mid x^+_e x^-_e \in E(C_1)\}\) is the arc set of a directed Hamiltonian cycle in D. Since up to isomorphism, H is obtained from \(E(C_1)\) by contraction of the \(C_4\)-gadgets, H forms a cycle in D (here we need that D is cubic). If the cycle H is not a directed cycle in D, there would be some \(v \in V_1\) with two incoming incident edges from H. However, in this case, the path in the corresponding \(C_4\)-gadget contained in \(C_1\) consists of two edges, one of which is not in X, contradicting that \(C_1\) is an alternating cycle in X. Finally, the directed cycle H has to be spanning. Indeed, if there is a \(C_4\)-gadget not traversed by \(C_1\), then \(C_2\) would be equal to the 4-cycle in the corresponding gadget, a contradiction. \(\square\)

Proof of Theorem 3

We use the following hardness result of Peroche [43]. Given a digraph D, where each vertex has indegree and outdegree equal to 2, it is NP-complete to decide if E(D) is the union of two directed Hamiltonian cycles. Given such a digraph D, let \(\overleftarrow{D}\) be the digraph obtained from D by reversing the direction of every arc. We regard D and \(\overleftarrow{D}\) as \(\alpha\)-orientations X and Y of the same underlying graph G, where \(\alpha (v)=2\) for all \(v \in V(G)\). The theorem follows by observing that the flip distance between X and Y is at most 2 if and only if E(D) is the union of two directed Hamiltonian cycles. Moreover, the same statement holds when we only allow flipping edges that are oriented differently in X and Y. \(\square\)

5 Vertex Flip Distance Between c-Orientations

In this section we prove Theorem 6.

Recall that, given a graph G with a fixed vertex \(\top\), we only allow vertex flips at vertices distinct from \(\top\). In the case that G is connected, we distinguish between two types of dicuts as follows: we say that a dicut S in an orientation of G is positive with respect to \(\top\) if and only if the uniquely determined cut set U of S does not contain \(\top\). Otherwise the dicut is called negative. We also define the interior of S, denoted \({{\,\mathrm{Int}\,}}(S)\), as the cut set U of S if S is positive and as its complement \(\overline{U}\) if S is negative. That is, \({{\,\mathrm{Int}\,}}(S)\) is the set of vertices on the side of the cut opposite to \(\top\).

The following lemma is needed to decompose the edges of certain digraphs into dicuts with nested cut sets. Formally, for a digraph D and dicuts \(S_1=\delta (U_1)\) and \(S_2=\delta (U_2)\), the pair \(S_1,S_2\) is called laminar if either \(U_1 \subseteq U_2\), \(U_2 \subseteq U_1\), \(U_1 \cap U_2=\emptyset\), or \(U_1 \cup U_2=V(D)\) ; see Fig. 12. A family of dicuts in D is called laminar if all of its pairs are laminar. A balanced digraph is a digraph in which every cycle of the underlying graph has the same number of forward and backward edges.

Lemma 1

Let D be a balanced digraph. Then E(D) can be decomposed into a laminar family of disjoint minimal dicuts.

Proof

We prove the statement by induction on |E(D)|. It is clearly true if \(E(D)=\emptyset\). Assume for the induction step that \(|E(D)|=k \ge 1\) and the statement holds for all digraphs with less than k arcs.

As D is balanced, it is obviously acyclic and therefore contains a source \(s \in V(D)\). Each cycle in the underlying graph of D that contains s has exactly one forward and one backward edge incident to s. Therefore, the digraph \(D'\) obtained from D by contracting the set \(\delta ^+(\{s\})\) of arcs incident to s is still balanced and has less than k edges. By the induction hypothesis, there exists a laminar decomposition of \(E(D')=E(D) \setminus \delta ^+(\{s\})\) into disjoint dicuts in \(D'\) and thus in D. Note that the dicuts in \(D'\) are exactly those of D disjoint from \(\delta ^+(\{s\})\), and laminarity is preserved. Hence adding a decomposition of the directed vertex cut \(\delta ^+(\{s\})\) into minimal dicuts to the collection gives rise to a decomposition of E(D) into disjoint minimal dicuts. This resulting decomposition is also laminar. To see this, let \(V_1,\ldots ,V_l\) denote the vertex sets of the weak components of \(D-s\) (\(l=1\) is possible). The new minimal cuts added to the decomposition are induced by the cut sets \(U_i:=V(D) \setminus V_i\) for \(i \in [l]\). We clearly have \(U_i \cup U_j=V(D)\) for \(i \ne j \in [l]\). Moreover, for any minimal dicut S in the laminar decomposition of \(D'\), the cut set corresponding to S in D fully contains \(U_i\) or is disjoint from \(U_i\) for some \(i \in [l]\) (otherwise S would not be minimal). This finally implies that each pair of cuts in the new decomposition is laminar, as desired. \(\square\)

For every pair XY of c-orientations on a graph G, the difference \(X \setminus Y\) denotes the set of arcs in X whose orientation is reversed in Y. Because X and Y are c-orientations, every cycle in G has the same number of forward- and backward-edges in \(X \setminus Y\). The digraph \(\text {trans}(X,Y)\) obtained from X by contracting \(\overline{X \setminus Y}\) therefore forms a balanced digraph. Consequently, Lemma 1 provides another proof that c-orientations can be reached from one another by flipping minimal dicuts.

We now consider the partial order defined on acyclic c-orientations of an n-vertex graph such that the covering relation corresponds to flipping a source vertex. Recall that by Theorem 4, this partial order is a distributive lattice. We now reuse a result from Propp [47] and Felsner and Knauer [20] that gives an embedding of this distributive lattice into \({\mathbb {N}}^{n-1}\), which led to the introduction of distributive polytopes by Felsner and Knauer [21]. This theorem is illustrated in Fig. 8, where the values of the functions \(z_X\) are depicted in the vertices of the graph G.

Theorem 9

([20, 47]) Let G be a graph on n vertices with a fixed vertex \(\top\), X an acyclic c-orientation of G, and denote by \(X_{\min }\) the minimal element of the associated distributive lattice. Then the number of times \(z_X(x)\) a vertex \(x \in V(G) \setminus \{\top \}\) is flipped in an upward lattice path from \(X_{\min }\) to X is independent of the sequence. The resulting function \(z_X:{\mathcal {R}}_c\rightarrow {\mathbb {N}}^{n-1}\) is a lattice embedding. That is, for every \(x,y\in {\mathbb {N}}^{n-1}\) corresponding to c-orientations of G, the join and meet correspond to \(\min (x,y)\) and \(\max (x,y)\), respectively.

In other words, the distributive lattice on \({\mathcal {R}}_c\) is isomorphic to an induced sublattice of the componentwise dominance order on \({\mathbb {N}}^{n-1}\). We call a vertex flip sequence monotone if every flipped vertex is either only flipped as a source or only as a sink. With this definition, Theorem 9 yields the following:

Corollary 4

Let G be a graph with fixed vertex \(\top\) and XY a pair of acyclic c-orientations on G. Then every monotone vertex flip sequence transforming X into Y has minimal length.

Consider two c-orientations XY of G. Our goal is to construct a monotone flip sequence from X to Y. By Lemma 1, there is a laminar decomposition of the edges in \(\text {trans}(X,Y)\) into minimal dicuts. The latter also form a laminar collection \({\mathcal {S}}={\mathcal {S}}(X,Y)\) of minimal dicuts in X which partition \(X \setminus Y\). Therefore reversing these dicuts yields Y.

We construct a poset P on \({\mathcal {S}}\) by the inclusion order of the interiors of the minimal dicuts. That is, for \(S,T\in {\mathcal {S}}\), S is ordered before T in P if and only if \({{\,\mathrm{Int}\,}}(S) \subseteq {{\,\mathrm{Int}\,}}(T)\); see Fig. 12. Since \({\mathcal {S}}\) is laminar, the cover graph of P is a forest, with the additional property that every non-maximal element S is covered by a unique other element, which we denote by \({{\,\mathrm{cov}\,}}(S)\). Moreover, for each vertex \(x \in V(G)\) in the interior of at least one of the cuts in \({\mathcal {S}}\), we let \(S_x\) be the (unique) minimal element of the poset P such that \(x\in {{\,\mathrm{Int}\,}}(S_x)\). Also, for each \(S \in {\mathcal {S}}\) we denote by \(\underline{{{\,\mathrm{Int}\,}}}(S):=\{x \in V(G)\mid S_x=S\} \subseteq {{\,\mathrm{Int}\,}}(S)\) the set of vertices in the interior of S but in none of the interiors of the cuts covered by S in the poset.

For each dicut \(S\in {\mathcal {S}}\) we define an integer weight w(S) and a sign \({{\,\mathrm{sgn}\,}}(S)\in \{+,0,-\}\) as follows; see Fig. 12. If \(S\in {\mathcal {S}}\) is a maximal element in P then we define \(w(S):=1\), and \({{\,\mathrm{sgn}\,}}(S):=+\) if S is positive and \({{\,\mathrm{sgn}\,}}(S):=-\) otherwise. For every sign \(s \in \{+,0,-\}\) and dicut \(S \in {\mathcal {S}}\), we say that S agrees with s, if either \(s=0\), or if \(s=+\) and S is positive, or \(s=-\) and S is negative. For every non-maximal \(S \in {\mathcal {S}}\), we inductively define

$$\begin{aligned} w(S):={\left\{ \begin{array}{ll} w({{\,\mathrm{cov}\,}}(S))+1 &{} \quad {\text { if }}S \text { agrees with }{{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S)), \\ w({{\,\mathrm{cov}\,}}(S))-1 &{} \quad {\text { otherwise}}, \end{array}\right. } \end{aligned}$$

and

$$\begin{aligned} {{\,\mathrm{sgn}\,}}(S):={\left\{ \begin{array}{ll} {{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S)) &{} \quad {\text {if }} {{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S)) \ne 0 \text { and } w(S) \ne 0, \\ + &{} \quad {\text {if }} {{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S)) = 0, w(S) \ne 0 \text { and }S \text { is positive}, \\ - &{} \quad {\text {if }} {{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S)) = 0, w(S) \ne 0 \text { and }S \text { is negative}, \\ 0 &{} \quad {\text {if }}w(S)=0. \end{array}\right. } \end{aligned}$$
Fig. 12
figure 12

A laminar collection \({\mathcal {S}}\) of disjoint minimal dicuts of \(X\setminus Y\) (left), where the positive ones are dashed, and the negative ones are dotted, and the corresponding poset P of dicuts in \({\mathcal {S}}\) ordered by inclusion (right) with its associated signed weights \({{\,\mathrm{sgn}\,}}(S)\cdot w(S)\), \(S\in {\mathcal {S}}\)

It follows from this definition that the weights are non-negative and that \({{\,\mathrm{sgn}\,}}(S)=0\) if and only if \(w(S)=0\) for every \(S \in {\mathcal {S}}\). We will see that given a minimal dicut S in \({\mathcal {S}}\), the weight w(S) describes the number of times each vertex which lies in \(\underline{{{\,\mathrm{Int}\,}}}(S)\) will be flipped, whereas \({{\,\mathrm{sgn}\,}}(S)\) captures the direction in which (all) these vertices are flipped. That is, a positive sign means that vertices are flipped from sources to sinks, while a negative sign means that vertices are flipped from sinks to sources. We will need the following auxiliary statement.

Lemma 2

Let XY be acyclic c-orientations of a connected graph G with fixed vertex \(\top\). If \(S=X\setminus Y\) is a positive dicut, then there is a vertex flip sequence transforming X into Y such that only vertices in \({{\,\mathrm{Int}\,}}(S)\) are flipped, each exactly once from source to sink.

The analogous statement for negative dicuts holds with sources and sinks exchanged.

Proof

We prove the statement by induction on \(|{{\,\mathrm{Int}\,}}(S)|\). If \({{\,\mathrm{Int}\,}}(S)\) is a single vertex, then S corresponds to the arcs incident to a source, and the statement holds.

For the induction step assume \(|{{\,\mathrm{Int}\,}}(S)|=k \ge 2\) and that the claim holds for all positive cuts in c-orientations of G whose interiors have order less than k. Since X is acyclic, the induced subdigraph \(X[{{\,\mathrm{Int}\,}}(S)]\) is also acyclic and thus contains a source \(x \in {{\,\mathrm{Int}\,}}(S)\). Since \({{\,\mathrm{Int}\,}}(S)\) is the cut set of S, x is a source in X as well. Let Z be the c-orientation obtained from X by a vertex flip at x. It follows that the cut \(\delta ({{\,\mathrm{Int}\,}}(S) \setminus \{x\})\) in Z is positive with interior of order \(k-1\). By induction, there is a vertex flip sequence from Z to Y such that only vertices in \({{\,\mathrm{Int}\,}}(S) \setminus \{x\}\) are flipped, each exactly once from source to sink. Starting with a vertex flip at x and continuing with this flip sequence yields a flip sequence from X via Z to Y with the desired properties. \(\square\)

We are now in position to prove the main result of this section.

Theorem 10

Let XY be acyclic c-orientations of a connected graph G. There is a monotone vertex flip sequence transforming X into Y which can be computed in cubic time in |E(G)|.

Proof

Consider the following strengthening of the theorem:

Claim Let XY be acyclic c-orientations of a connected graph G and \({\mathcal {S}}={\mathcal {S}}(X,Y)\) a laminar decomposition of \(X \setminus Y\) into disjoint minimal dicuts. Then there is a monotone vertex flip sequence from X to Y, such that every flipped vertex x is contained in the interior of the dicut \(S_x \in {\mathcal {S}}\), and x is flipped \(w(S_x)\) times from source to sink if \({{\,\mathrm{sgn}\,}}(S_x)=+\), and from sink to source otherwise.

We prove this claim by induction on the size of \({\mathcal {S}}\). The statement is clearly true if \(X=Y\) (which means that \(|{\mathcal {S}}|=0\)), settling the base case of the induction. Assume for the induction step that we are given a pair \(X \ne Y\) of c-orientations and a laminar decomposition \({\mathcal {S}}\) of \(X \setminus Y\) of size \(k \ge 1\). Assume that the claim holds for all pairs of c-orientations with a laminar decomposition of size less than k.

In the poset P on \({\mathcal {S}}\) we consider a minimal element corresponding to a cut \(S\in {\mathcal {S}}\), i.e., we have \(\underline{{{\,\mathrm{Int}\,}}}(S)={{\,\mathrm{Int}\,}}(S)\) and all vertices \(x\in {{\,\mathrm{Int}\,}}(S)\) satisfy \(S_x=S\). Lemma 2 gives a vertex flip sequence \(F_1\) that flips only vertices in \({{\,\mathrm{Int}\,}}(S)\), each exactly once from source to sink if S is positive and from sink to source if S is negative. Applying this flip sequence to X, we obtain an intermediate c-orientation Z that differs from X only by the reversal of all edges in S. Consequently, \({\mathcal {S}}\setminus \{S\}\) is a laminar decomposition of \(Z \setminus Y\) into minimal dicuts in Z of size \(k-1\). By induction, we also have a vertex flip sequence \(F_2\) transforming Z into Y with the aforementioned properties.

Note that the weights and signs of all dicuts \(T\in {\mathcal {S}}\setminus \{S\}\) defined with respect to \({\mathcal {S}}\) or \({\mathcal {S}}\setminus \{S\}\) are the same, so we may simply write w(T) and \({{\,\mathrm{sgn}\,}}(T)\). Furthermore, the set \(\underline{{{\,\mathrm{Int}\,}}}(T)\) defined with respect to \({\mathcal {S}}\) is a subset of the same set defined with respect to \({\mathcal {S}}\setminus \{S\}\). To complete the induction step, we distinguish two cases.

The first case is that S is a maximal element in P, or that S agrees with \({{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))\). In this case, we claim that the concatenation F of \(F_1\) and \(F_2\) is a flip sequence transforming X via Z into Y with the desired properties. It suffices to check this for the vertices in \(\underline{{{\,\mathrm{Int}\,}}}(S)={{\,\mathrm{Int}\,}}(S)\), since for all other vertices, the claimed properties follow inductively (they are never flipped in \(F_1\), so their behavior in F will be the same as in \(F_2\)). If S is a maximal element in P, then \(w(S)=1\) and every vertex \(x\in {{\,\mathrm{Int}\,}}(S)\) will be flipped exactly once. Moreover, according to Lemma 2, if S is positive, i.e., \({{\,\mathrm{sgn}\,}}(S)=+\), then x is flipped from source to sink, and if S is negative and \({{\,\mathrm{sgn}\,}}(S)=-\), then x is flipped sink to source. It remains to consider the subcase that S is not maximal, i.e., \({{\,\mathrm{cov}\,}}(S)\) exists. Consider any vertex \(x\in {{\,\mathrm{Int}\,}}(S)\). During the flip sequence F, the vertex x is flipped once in \(F_1\) and \(w({{\,\mathrm{cov}\,}}(S))\) times in \(F_2\), so \(w(S)=w({{\,\mathrm{cov}\,}}(S))+1\) times in total, as required. Moreover, the assumption that S agrees with \({{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))\) means that either \({{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))=+\) and S is positive or \({{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))=-\) and S is negative, or \(w({{\,\mathrm{cov}\,}}(S))={{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))=0\). We conclude from the inductive assumption that in those three cases, x is only flipped from source to sink in both \(F_1\) and \(F_2\), or only sink to source in both, or only once in \(F_1\) but not in \(F_2\), respectively. Consequently, x satisfies the inductive claim in all cases.

The second case is that S is not maximal, i.e., \({{\,\mathrm{cov}\,}}(S)\) exists, and that S does not agree with \({{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))\). This means that \(w(S)=w({{\,\mathrm{cov}\,}}(S))-1\). Without loss of generality, assume that S is positive and consequently \({{\,\mathrm{sgn}\,}}({{\,\mathrm{cov}\,}}(S))=-\) (the other case is symmetric). Consider again the vertex flip sequence F obtained by concatenating \(F_1\) and \(F_2\). This flip sequence would transform X via Z into Y, however, we will not actually apply F, but modify the sequence as follows. By Lemma 2, \(F_1\) flips each vertex in \({{\,\mathrm{Int}\,}}(S)\) exactly once from source to sink. By induction, in \(F_2\), each vertex in \({{\,\mathrm{Int}\,}}(S)\) contained in the interior of \({{\,\mathrm{cov}\,}}(S)\) (defined with respect to \({\mathcal {S}}\setminus \{S\}\)) is flipped from sink to source. Let x be the last element of \(F_1\) and consider the subsequence \(x,x_1,\ldots ,x_k,x\) of F starting with x and ending with the first occurrence of x in \(F_2\). None of the vertices \(x_1,\ldots ,x_k\) is adjacent to x in G, because after the first vertex flip at x (from source to sink) all edges incident with x are incoming, and in \(F_2\) we only flip sinks to sources. This shows that deleting the first two occurrences of x from F preserves the number of and direction of all flips at vertices distinct from x, and still transforms X into Y. Repeated application of this argument produces a reduced vertex flip sequence \(F'\) transforming X into Y such that each vertex \(x \in V(G) \setminus {{\,\mathrm{Int}\,}}(S)\) is flipped the same number of times and in the same direction as in \(F_2\). By the inductive assumption, this means that x is flipped \(w(S_x)\) times from source to sink if \({{\,\mathrm{sgn}\,}}(S_x)=+\), and \(w(S_x)\) times from sink to source if \({{\,\mathrm{sgn}\,}}(S_x)=-\). On the other hand, every \(x \in {{\,\mathrm{Int}\,}}(S)\) is missing its first occurrence in \(F_2\) but is flipped in the same way from sink to source for all remaining occurrences. This implies that x is flipped \(w(S)=w({{\,\mathrm{cov}\,}}(S))-1\) times from sink to source, as it should. This proves that \(F'\) is a vertex flip sequence from X to Y satisfying the conditions in our claim, completing its proof.

It remains to verify that the recursive algorithm obtained from this inductive argument runs in cubic time in \(m:=|E(G)|\). First of all, the number of dicuts in any laminar decomposition, which corresponds to the number of induction steps, is bounded by the number of edges m. Consequently, it suffices to bound the number of operations needed in one induction step in terms of m. Specifically, we need to compute the cover relations of P, the weights and signs of the dicuts, find a minimal element of the poset P, test its properties for the case distinction and construct the resulting flip sequence by concatenation and possibly deletion of double occurrences, all of which can be done in time \({\mathcal {O}}(m^2)\). This proves an upper bound of \({\mathcal {O}}(m^3)\) for the total number of steps performed for the construction of the monotone flip sequence to transform X into Y. Finally, a laminar decomposition \({\mathcal {S}}\) of \(X\setminus Y\) as guaranteed by Lemma 1 can be computed in time \({\mathcal {O}}(m^3)\) as well, by following the recursive strategy explained in the proof of the lemma. This completes the proof. \(\square\)

Combining Corollary 4 and Theorem 10 yields Theorem 6.

6 Flip Distance with Larger Cut Sets

In this section we prove Theorem 7 by reduction from the following NP-hard problem.

Given a (finite) poset \((P,\prec )\), its height is the maximum size k of a chain \(x_1\prec x_2\prec \cdots \prec x_k\) in P. A linear extension of P is a sequence \((x_1,\ldots ,x_n)\) of all elements of P such that \(x_i\prec x_j\) implies that \(i<j\). Given a linear extension \(L=(x_1,\ldots ,x_n)\) of P, a jump is a pair \(x_i,x_{i+1}\) in L for which \(x_i \not \prec x_{i+1}\) in P. Conversely, a bump is a pair \(x_i,x_{i+1}\) such that \(x_i \prec x_{i+1}\). The jump number s(P) of P is the minimum number of jumps among all linear extensions of P. The Jump Number Problem is the algorithmic problem of computing the jump number of a poset given by its comparabilities.

Theorem 11

([40, 49]) Determining the jump number of a poset of height two is NP-hard.

Proof of Theorem 7

We provide a Turing-reduction of the Jump Number Problem for posets of height two to the problem stated in the theorem. For this purpose, assume we are given a poset \((P,\prec )\) of height two with bipartite Hasse diagram \(G=(P_1\cup P_2, E)\) as an instance for the Jump Number Problem. We may assume that P has no isolated elements and that \(P_1\) contains all minimal elements and \(P_2\) all maximal elements of the poset. We construct an auxiliary graph \(G'\) from G by adding an additional unique maximal element \(\top\), and connecting it with edges to all vertices of G. We construct two orientations XY of \(G'\) as follows: In both orientations all edges are oriented from \(P_1\) to \(P_2\). Moreover, in X all edges incident with \(\top\) are oriented towards \(\top\), while in Y all these edges are oriented away from \(\top\). As XY are obtained from each other by flipping all edges incident with \(\top\) (this flip is not allowed, though, as \(\top\) is the fixed vertex), they are c-orientations with respect to the same c.

Let d denote the minimal flip distance between these c-orientations according to the conditions of the theorem. We will complete the proof by showing that \(s(P)=d-1\).

We first show that \(s(P)\ge d-1\). For this argument, let \(L=(x_1,\ldots ,x_n)\) be an arbitrary linear extension of P. As P has height two, the elements \(\{x_1,\ldots ,x_n\}\) of P are partitioned into subsets \(B_1,\ldots ,B_m\) of size one or two, such that for all \(B_i,B_j\) with \(i<j\), the elements from \(B_i\) appear before the elements from \(B_j\) in L, and such that the two-element sets \(B_i\) contain exactly all bump pairs. We define a flip sequence that starts with the orientation X and consecutively flips the cuts induced by \(B_1,\ldots B_m\). Since for all \(1\le i\le m\), each of \(B_i\) and \(\overline{B_i}:=(P\cup \{\top \})\setminus B_i\) induces a connected subgraph of \(G'\), these are indeed minimal cuts. Moreover, each of these cuts is flippable. This is obviously true for \(B_1\), as \(B_1\) induces a dicut in X. Now assume inductively that the cuts induced by \(B_1,\ldots ,B_{k-1}\) for some \(k \ge 2\) have been flipped. As L is a linear extension of P, all elements in the downset of \(B_k\) in P but not in \(B_k\) are in one of the \(B_i\) with \(i<k\). This implies that every arc between some \(x \in B_k\) and \(y \notin B_k\) is oriented from x to y in the current orientation, and thus \(B_i\) is indeed flippable.

In this flip sequence, every arc in X not incident to \(\top\) will be flipped zero or two times and thus maintains its original orientation, while all the edges incident to \(\top\) get reversed, as they are incident to exactly one set \(B_i\). Consequently, the flip sequence transforms X into Y, proving that \(d\le m\). As m equals the number of jumps in L plus 1 (every non-jump is a bump within one of the \(B_i\)), this yields \(d-1\le s(P)\).

We now show that \(s(P)\le d-1\). Assume that \(B_1,\ldots ,B_d \subseteq P\) are the cut sets of size one or two appearing (in this order) in a shortest flip sequence transforming X into Y. We may assume that among all shortest flip sequences, this sequence also minimizes \(|B_1|+|B_2|+\ldots +|B_d|\). Since each vertex \(x \in P\) has an outgoing arc to \(\top\) in X which must be reversed during the flip sequence, x must be contained in at least one of the \(B_i\). We claim that x is contained in at most one of the \(B_i\). That is, the \(B_i\) are pairwise disjoint. Assume to the contrary that \(x \in B_i \cap B_j\) for some \(i<j\) and that \(B_i,B_j\) is the only intersecting pair among \(B_i,B_{i+1},\ldots ,B_j\) (by minimizing \(j-i\)). In particular, none of the cut sets \(B_{i+1},\ldots ,B_{j-1}\) contains x, and x is the only vertex flipped multiple times in this subsequence. We are then in one of the four cases \(B_i=B_j=\{x\}\), or \(B_i=\{x,y\}\) and \(B_j=\{x\}\), or \(B_i=\{x\}\) and \(B_j=\{x,z\}\), or \(B_i=\{x,y\}\) and \(B_j=\{x,z\}\) for some elements \(y,z\in P\) distinct from x. Since no vertex adjacent to x in \(G'\) can be flipped by \(B_{i+1},\ldots ,B_{j-1}\), it follows that in each of these cases, the sequence

$$\begin{aligned} B_1,\ldots ,B_{i-1},B_i\setminus \{x\},B_{i+1},\ldots ,B_{j-1},B_j\setminus \{x\},B_{j+1},\ldots ,B_d \end{aligned}$$

is a valid flip sequence from X to Y of length at most d and with decreased sum \(|B_1|+|B_2|+\ldots +|B_d|\), a contradiction. This proves that the cut sets \(B_i\) are pairwise disjoint.

The \(B_i\) are flipped one after the other and by definition of X, the dicut induced by \(B_i\) is flippable if and only if all the elements in the downset of \(B_i\) with respect to P but not in \(B_i\) were flipped before. Therefore, by listing the elements in the sets \(B_1,\ldots ,B_d\) in this relative order, and ordering the elements within each \(B_i\) according to their order in P, we obtain a linear extension L of P whose jumps are exactly those pairs having elements in two consecutive sets \(B_i\). It follows that there are \(d-1\) jumps in L, proving that \(s(P) \le d-1\).

Combining these arguments shows that \(s(P)=d-1\), and using Theorem 11 we obtain the claimed hardness result. \(\square\)

7 Open Problems

Recall that Problem 2 asks for a shortest flip sequence of directed cycles transforming one \(\alpha\)-orientation X into another one Y, where we only allow flipping edges that are oriented differently in X and Y. Since the set of edges that are oriented differently in X and Y form an Eulerian subdigraph D of both X and Y, we have the following natural question:

Question 1

What is the smallest number of directed cycles into which an Eulerian digraph can be decomposed?

We have seen in Theorem 3 that from a computational point of view, this problem is hard for general digraphs, but we wonder what happens when adding planarity constraints. The aforementioned question can also be studied in terms of upper bounds as a function of the number of vertices, which is related to the famous Hajós conjecture on undirected Eulerian graphs, see [35]. Another interesting undirected variant of Question 1 is the following:

Question 2

Given a graph G with an Eulerian subgraph H, what is the smallest number of cycles of G such that their symmetric difference is H?

Concerning our proof of Theorem 7, we believe that for any bound on the size of the cuts, the corresponding flip distance will be NP-hard to compute. On the other hand, we use very particular graphs as gadgets, and we do not know the complexity of the corresponding problem for planar \(\alpha\)-orientations. We think the following is an interesting special case:

Question 3

Let XY be perfect matchings of a planar bipartite 3-connected graph G. What is the complexity of determining the distance of X and Y with respect to alternating cycles that are either a face or the symmetric difference of two incident faces?

The feeling that this problem might be tractable is supported by the following observation. It is not difficult to show that every height two poset with bipartite planar Hasse diagram has dimension at most two. It then follows from [55] that the restriction of the Jump Number Problem to such posets is solvable in polynomial time, and thus, the hardness reduction presented in the previous section fails.