1 Introduction

Local search and data reduction are two widely successful strategies for coping with hard computational problems. Local search, which applies most naturally to optimization problems, aims at computing good heuristic solutions by using the following generic approach: Define a local neighborhood relation on the set of feasible solutions. Then, compute some feasible solution S. Now check whether there is a better solution \(S'\) in the local neighborhood of S. If this is the case, then replace S by \(S'\). Otherwise, output the locally optimal solution S and stop.

Local search algorithms have been explored thoroughly from a practical and theoretical point of view [1,2,3,4,5,6,7,8]. The theoretical framework most closely related to our investigations is parameterized local search. Here, the local search neighborhood comes equipped with an operational parameter k that bounds the radius of the local search neighborhood. For example, in Independent Set one is given a graph G and asks for a largest independent set in G, that is, a vertex set S such that no two vertices in S are adjacent. A natural neighborhood with a radius k is the k-swap neighborhood: Two vertex sets S and \(S'\) are in their respective k-swap neighborhoods if \(|S\oplus S'|\le k\), where \(\oplus \) denotes the symmetric difference of two sets. To apply the above-mentioned generic approach, one has to solve the following problem called LS-Independent Set: one is given a graph G, an independent set S, and an integer k and asks whether the k-swap neighborhood of S contains a larger independent set \(S'\). LS-Independent Set can be solved in \(\Delta ^{\mathcal {O}(k)}\cdot n\) time [7, 9]; the currently best fixed-parameter algorithm for LS-Independent Set is efficient in practice, solving the parameterized local search problem for \(k\approx 20\) even on large real-world graphs [7]. Summarizing, for moderate values of k, a k-swap-optimal independent set can be computed faster than an optimal one.

In data reduction, the idea is to preprocess any instance of a hard problem by identifying those parts of the instance that are easy to solve. Usually, data reduction algorithms are stated as a collection of data reduction rules which can be applied if a certain precondition is fulfilled and reduce the instance size whenever they apply. Two classic trivial reduction rules for Independent Set are as follows: First, remove any vertex v that has no neighbors in G and add v to the independent set that is computed for the remaining instance. Second, remove any vertex v that has two degree-one neighbors.

In this work, we aim to explore the usefulness of local search or, more precisely, of local optimality, in the context of data reduction for hard problems. The correctness of the first reduction rule above is rooted in the observation that v is contained in every maximum independent set. Similarly, the correctness of the second rule is rooted in the fact that v is contained in no maximum independent set. Most of the known data reduction rules employ this principle and the crux of proving the correctness of a data reduction rule lies in proving that v is contained in all optimal solutions or in no optimal solution. In general, given a vertex v and computing whether v is contained in a largest independent set is just as hard as computing an optimal solution in the first place. This is why data reduction rules use specific preconditions that allow proving optimality of including or excluding v without computing an optimal solution.

One may avoid such specific preconditions by relying on locally optimal solutions instead of optimal solutions: If we could compute efficiently that a vertex v is not contained in a locally optimal solution for some local search neighborhood, then we could remove v from the graph. Conversely, if we could compute efficiently that some vertex v is contained in every locally optimal solution, then we could remove v and its neighborhood from the graph as described above. The hope is that, since computing locally optimal solutions is easier for suitable local search neighborhoods, this approach could help in circumventing the previous dilemma: to say something about the optimal solution, one more or less needs to compute it. Going back to the Independent Set problem, we would like to determine whether a given vertex is in some k-swap-optimal independent set.

Some Locally Optimal Independent Set (\(\exists \)-LO-IS) Input: An undirected graph \(G=(V,E)\), a vertex \(v \in V\), and \(k\in \mathbb {N}\). Question: Is v contained in some k-swap-optimal independent set in G?

If the answer is no, then v can be removed from G without destroying any optimal solution. Note that we can compute some k-swap-optimal independent set in \(\Delta ^{\mathcal {O}(k)}n^2\) time by using local search with the known algorithms for searching the k-swap neighborhood of the current solution. This locally optimal solution, however, may not contain v even if there is another locally optimal solution that does so.

We may also ask whether v is in every locally optimal independent set.

Every Locally Optimal Independent Set (\({\forall }\)-LO-IS) Input: An undirected graph \(G=(V,E)\), a vertex \(v\in V\), and \(k\in \mathbb {N}\). Question: Is v contained in every k-swap-optimal independent set in G?

If the answer is yes, then v belongs to every optimal independent set and we can apply a data reduction rule that removes v and its neighbors and adds v to the independent set that is computed for the remaining graph. Motivated by the usefulness of efficient algorithms for these two problems in data reduction for Independent Set, we study their complexity. We consider related problems for two further classic NP-hard problems: Max Cut and Longest Path.

Our Results

For Independent Set our results are decidedly negative. \(\exists \)-LO-IS and \(\forall \)-LO-IS are NP-complete and coNP-complete, respectively, even if \(k=3\) and \(\Delta =4\) and also if \(k=5\) and \(\Delta =3\). These results are tightFootnote 1 in the following sense: when \(k=1\) or when \(\Delta =2\), then both problems can be solved in polynomial time. Moreover, when k is not constant, we show that the problems are even \(\Sigma ^{\text {P}}_{2}\)-complete and \(\Pi ^{\text {P}}_{2}\)-complete, respectively. Thus, both problems are substantially harder than LS-Independent Set. For Max Cut the situation is similar: Deciding whether some edge is contained in a k-swap-optimal cut or in every k-swap-optimal cut is NP-complete and coNP-complete even if \(k=1\) and \(\Delta =5\). Moreover, if k is not constant, then the problems are \(\Sigma ^{\text {P}}_{2}\)-complete and \(\Pi ^{\text {P}}_{2}\)-complete, respectively.

Finally, we consider Longest Path with a certain edge-swap neighborhood. We show that for this neighborhood we can determine in \(f(\Delta +k)\cdot n^{\mathcal {O}(1)}\) time whether some edge is contained in a k-optimal path. If the answer is no, then this edge can be safely removed from the input graph. Since Longest Path is NP-hard on cubic graphs, our results indicate that there are scenarios in which testing for the containment of edges and vertices in locally optimal solutions is a viable approach to obtain data reduction rules for NP-hard problems.

Related Work

A related problem is to determine if there is a maximal (and, thus, 1-swap-optimal) independent set S containing only vertices of a given vertex set \(U\subseteq V\) [10, 11]. In other words, this problem asks for a 1-swap-optimal independent set containing no vertex of \(V\setminus U\), a generalization of the complement problem of \(\exists \)-LO-IS for \(k=1\). This problem is \(\textrm{NP}\)-hard even on graphs where Independent Set can be solved in polynomial time, like bipartite graphs [10].

In the scope of 1-swaps, the Independent Set Reconfiguration problem was analyzed extensively [12,13,14,15]. Here, we are given two independent sets X and Y of a graph G and an integer k and we want to determine if there is a sequence \(S_1, \dots , S_r\) of independent sets such that \(S_1 = X\)\(S_r = Y\),  \(|S_j|\ge k\) for all \(j\in [1,r]\), and \(|S_j \oplus S_{j+1}| = 1\) for all \(j\in [1, r-1]\). In other words , one wants to add or remove a single vertex at a time and transform X into Y without decreasing the size of the current independent set below k. This problem is \(\textrm{PSPACE}\)-complete even on bipartite graphs [15].

2 Preliminaries

Sets and Graphs

For a set A, we denote with \({{A}\atopwithdelims (){2}}:= \{\{a,b\}\mid a \in A, b\in A\}\) the collection of all size-two subsets of A. For two sets A and B, we denote with \(A \oplus B:= (A \setminus B) \cup (B \setminus A)\) the symmetric difference of A and B.

An (undirected) graph \(G=(V,E)\) consists of a set of vertices V and a set of edges \(E \subseteq {{V}\atopwithdelims (){2}}\). For vertex sets \(S\subseteq V\) and \(T\subseteq V\) we denote with \(E_G(S,T):= \{\{s,t\}\in E \mid s\in S, t\in T\}\) the edges between S and T. Moreover, we define \(E_G(S):= E_G(S,S)\). For a vertex \(v\in V\), we denote with \(N_G(v):= \{w\in V\mid \{v,w\}\in E\}\) the open neighborhood of v in G and with \(N_G[v]:= N_G(v) \cup \{v\}\) the closed neighborhood of v in G. Analogously, for a vertex set \(S\subseteq V\), we define \(N_G[S]:= \bigcup _{v\in S} N_G[v]\) and \(N_G(S):= N_G[S]\setminus S\). If G is clear from the context, we may omit the subscript. Moreover, we denote with \(\Delta (G):= \max \{|N_G(v)|\mid v\in V\}\) the maximum degree of G.

A sequence of distinct vertices \(P=(v_0, \dots , v_k)\) is a path or \((v_0,v_k)\)-path of length k in G if \(\{v_{i-1}, v_{i}\}\in E(G)\) for all \(i \in [1,k]\). We denote with V(P) the vertices of P and with E(P) the edges of P.

Satisfiability

For variable set Z, we define the set of literals \(\mathcal {L}(Z):= Z \cup \{\lnot z \mid z \in Z\}\). A literal set \(\widetilde{Z} \subseteq \mathcal {L}(Z)\) is an assignment of Z if for each variable \(z \in Z\)\(\widetilde{Z}\) contains either z or \(\lnot z\). For a subset \(X \subseteq Z\) of the variables we denote with \(\tau _Z(X):= X \cup \{\lnot z \mid z \in Z\setminus X\}\), the assignment of Z where all variables of X occur positively and all variables of \(Z \setminus X\) occur negatively. An (or)-clause \(\phi \) is a subset of the literals \({\mathcal {L}(Z)}\) and is satisfied by an assignment \(\tau \) of Z if \(\tau \) contains at least one literal of \(\phi \), that is, if \(\phi \cap \tau \ne \emptyset \), and we write \(\tau \models \phi \). Analogously, a set \(\Phi \) of clauses is satisfied by \(\tau \) if \(\tau \) satisfies each clause of \(\Phi \), and we write \(\tau \models \Phi \). We say that an assignment \(\tau \) of Z not-all-equal satisfies (nae-satisfies for short) a clause \(\phi \) if \(\tau \) satisfies \(\phi \) and the complement assignment of \(\tau \), that is, \((\mathcal {L}(Z)\setminus \tau )\) satisfies \(\phi \), and we write \(\tau \models _{\text {NAE}}\phi \). Analogously, a set \(\Phi \) of clauses is not-all-equal satisfied by \(\tau \) if each clause of \(\Phi \) is not-all-equal satisfied by \(\tau \), and we write \(\tau \models _{\text {NAE}}\Phi \).

In some of our reductions, we reduce from the following \(\textrm{NP}\)-complete [16] problem.

2P2N 3-SAT Input: A set \(\Phi \) of size-3 CNF-clauses over a variable set Z, such that each variable occurs twice positively and twice negatively and at most once per clause. Question: Is there an assignment \(\tau \) of the variables of Z that satisfies \(\Phi \)?

We will use the following family of graphs in several constructions throughout this paper.

Definition 1

For a variable z and a positive integer q we define a variable cycle of length 2q for z as the graph \(G_z=(V_z, E_z)\) where

  • \(V_z:= \{\top ^i_z, \bot ^i_z\mid 1 \le i \le q\}\), and

  • \(E_z:= \{\{\bot ^i_z, \top ^i_z\}\mid 1 \le i \le q\} \cup \{\{\top ^i_z, \bot ^{i+1}_z\}\mid 1 \le i \le q\} \cup \{\{\top ^q_z, \bot ^1_z\}\}.\)

Further, we denote with \(C(z):= \{\top ^i_z\mid 1 \le i \le q\}\) the true positions of z and with \(C(\lnot z):= V_z \setminus C(z) = \{\bot ^i_z\mid 1 \le i \le q\}\) the false positions of z.

Moreover, for a set of variable cycles for the variable set Z and every assignment \(\tau \subseteq \mathcal {L}(Z)\) of Z we denote with \(C(\tau ):= \bigcup _{\ell \in \tau }C(\ell )\) the positions corresponding to the assignment \(\tau \).

Let S and \(S'\) be vertex sets. We say that a variable cycle \(G_z\) switched from true positions to false positions between S and S’ if \(S \cap V_z = C(z)\) and \(S'\cap V_z = C(\lnot z)\). Analogously, we say that \(G_z\) switched from false positions to true positions between S and S’ if \(S \cap V_z = C(\lnot z)\) and \(S'\cap V_z = C(z)\).

3 Independent Set

In this section, we analyze the complexity of \(\exists \)-LO-IS and \(\forall \)-LO-IS. First, let us set the following notation. Let \(G=(V,E)\) be a graph and let k be an integer. We call a subset \(W \subseteq V\)k-swap in G if \(|W|\le k\). A set \(S\subseteq V\) is an independent set if \(\{v,w\}\not \in E\) for all \(v,w\in S\). Further, an independent set S is k-swap-optimal in G if there is no k-swap W in G such that \(S \oplus W\) is an independent set and \(|S| < |S \oplus W|\). We will make use of the following observation on improving k-swaps.

Observation 1

([7, Lemma 2]) Let S be an independent set for a graph \(G=(V,E)\) and let k be an integer. Then, S is k-swap-optimal if and only if there is no swap \(W\subseteq V\) of size at most k such that G[W] is connected and \(|S\oplus W| = |S| + 1\).

We may also observe the following relation between the two problems under consideration.

Observation 2

The instance (Gvk) is a yes-instance of \(\forall \)-LO-IS if and only if for each \(w\in N(v)\), (Gwk) is a no-instance of \(\exists \)-LO-IS.

3.1 Polynomial-Time Solvable Cases

First, we observe that we can solve \(\exists \)-LO-IS and \(\forall \)-LO-IS in polynomial time for the following almost trivial cases. Note that for \(k=1\), we ask whether a vertex is contained in some maximal independent set or in every maximal independent set.

Proposition 3

\(\exists \)-LO-IS and \(\forall \)-LO-IS can be solved in linear time if \(k=1\) or \(\Delta \le 2\).

Proof

We start by showing the statement for \(\exists \)-LO-IS. Let \(I=(G=(V,E), v_\exists , k)\) be an instance of \(\exists \)-LO-IS. If \(k=1\), then we are asking if there is an inclusion-wise maximal independent set S with \(v_\exists \in S\). Surely, this is always the case.

If \(\Delta (G)\le 2\) and the connected component containing \(v_\exists \) is a path with an even number of vertices or a cycle, then I is a yes-instance. If \(\Delta (G)\le 2\) and the connected component containing \(v_\exists \) is a path \((v_1,v_2, v_3,\dots , v_r)\) for some odd r, then I is a yes-instance if \(v_\exists = v_j\) for some odd \(j\in [1,r]\). If \(v_\exists = v_j\) for some even \(j\in [1,r]\), then I is a no-instance if \(k \ge r\) since an independent set S containing \(v_\exists \) is not k-swap-optimal due to the fact that \(S':= S \setminus \{v_i\mid \text { even } i \in [1,r]\} \cup \{v_i\mid \text { odd } i \in [1,r]\}\) is a larger independent set and the symmetric difference between S and \(S'\) has size at most k. Otherwise, if \(r < k\), then the set \(\{v_i\mid \text { even } i \in [1,r]\}\) is k-swap-optimal for the connected component containing \(v_\exists \). Consequently, if \(v_\exists = v_j\) for some even \(j\in [1,r]\), then I is a yes-instance of \(\exists \)-LO-IS if and only if \(k < r\). Summarizing, \(\exists \)-LO-IS can be solved in polynomial time if \(\Delta \le 2\) or \(k=1\).

Next, we show the statement for \(\forall \)-LO-IS. Let \(I=(G=(V,E), v_\forall , k)\) be an instance of \(\forall \)-LO-IS. Due to Observation 2, I is a yes-instance of \(\forall \)-LO-IS if and only if for each \(w\in N(v_\forall )\)\(I'=(G=(V,E), w, k)\) is a no-instance of \(\exists \)-LO-IS. As a consequence, \(\forall \)-LO-IS can also be solved in polynomial time if \(\Delta \le 2\) or \(k=1\). \(\square \)

3.2 NP-Hardness for Swaps of Constant Size

We now show that we cannot improve upon Proposition 3, neither in terms of k nor in terms of \(\Delta \).

For every constant value of k, we can decide in polynomial time if a given independent set is k-swap-optimal. This directly implies the following.

Observation 4

If k is constant, then \(\forall \)-LO-IS is contained in coNP and \(\exists \)-LO-IS is contained in \(\textrm{NP}\).

Recall that this fact for constant values of k is interesting to observe, since we will show later that both problems become hard for complexity classes of the second level of the polynomial hierarchy when k is not a constant. Next, we show that the considered problems are presumably not polynomial-time solvable even for constant values of k.

Theorem 5

\(\exists \)-LO-IS is \(\textrm{NP}\)-complete and \(\forall \)-LO-IS is \(\textrm{coNP}\)-complete if \(k=3\) and \(\Delta = 4\).

Proof

First, we show the statement for \(\exists \)-LO-IS. To this end, we reduce the \(\textrm{NP}\)-complete 2P2N 3-SAT problem to \(\exists \)-LO-IS.

Given an instance \(I=(Z, \Phi )\) of 2P2N 3-SAT, we construct in polynomial time an equivalent instance \(I'=(G=(V,E), v_\exists , k)\) of \(\exists \)-LO-IS where \(k = 3\) and where G has a maximum degree of 4. This assumption is required to obtain the maximum degree of four in the \(\exists \)-LO-IS-instance. An example of the graph G is depicted in Fig. 1.

We start with an empty graph G and add for every variable \(z \in Z\) the vertices z and \(\lnot z\) and connect both vertices with an edge.

Let \(\psi \) denote the number of clauses of \(\Phi \) and let \(\Phi := \{\phi _1, \dots , \phi _\psi \}\). Next, for each clause \(\phi _i\) in \(\Phi \), we add a vertex \(p_i\) to G and an edge between \(p_i\) and each vertex representing a literal \(\ell \) which is contained in \(\phi _i\). That is, we add the edge \(\{\ell ,p_i\}\) for each \(\ell \in \phi _i\). Further, we add a path \(P=(v_1, u_1, v_2, u_2, \dots , v_{\psi })\) with new vertices to G and edges \(\{v_i, p_i\}\) for each \(i\in [1,\psi ]\). Finally, we add vertices \(w_i\) and edges \(\{w_i, v_i\}\) for all \(i\in [1,\psi ]\) and set \(v_\exists := v_1\).

This completes the construction of \(I'\). Next, we show that I is a yes-instance of 2P2N 3-SAT if and only if \(I'\) is a yes-instance of \(\exists \)-LO-IS.

\((\Rightarrow )\) Let \(\tau \) be an assignment of Z that satisfies \(\Phi \). We set \(S:= \tau \cup \{v_i\mid 1 \le i \le \psi \}\) and show that S is a 3-swap-optimal independent set in G. By construction, S is an independent set. Moreover, since the closed neighborhood of S is exactly V,  S is a maximal independent set in G and, thus, 1-swap-optimal in G. Hence, to show that S is a 3-swap-optimal independent set in G it is sufficient to show that there is no \(s\in S\) and \(x,y \in N(s)\) with  \(N(x) \cap S = N(y) \cap S = \{s\}\) since an improving 3-swap has to remove one vertex s from S and add two vertices x and y to S, where both x and y have only s as their single neighbor in S. Let \(i\in [1,\psi -1]\). Since \(v_i\in S\) and \(v_{i+1}\in S\)\(u_i\) has two neighbors in S. Moreover, since \(\tau \) satisfies \(\Phi \), for each  \(\phi _i \in \Phi \)\(\tau \cap \phi _i \ne \emptyset \). Hence, \(p_i\) has at least two neighbors in S, namely \(v_i\) and at least one vertex of \(\phi _i \cap \tau \). Thus, the only vertices in G with only one neighbor in S are in \(V':= \{w_i\mid 1 \le i \le \psi \} \cup (\mathcal {L}(Z) \setminus \tau )\). By construction, no two vertices of \(V'\) have a common neighbor in S. Hence, S is a 3-swap-optimal independent set in G which contains \(v_\exists \).

\((\Leftarrow )\) Let S be a 3-swap-optimal independent set in G which contains \(v_\exists \). Before we show that there is a satisfying assignment \(\tau \) for \(\Phi \), we make some observations on the structure of S.

We first show that \(\{v_i\mid 1 \le i \le \psi \} \subseteq S\). To this end, assume towards a contradiction, that \(v_\exists \in S\) and there is some \(i \in [2, \psi ]\) such that \(v_i\not \in S\). Consequently, there is some \(j\in [1, \psi - 1]\) such that \(v_j \in S\) and \(v_{j+1}\not \in S\). Thus, \(v_j\) is the only neighbor of \(u_j\) in S. Hence, \(S':= (S \cup \{u_j, w_j\}) \setminus \{v_j\}\) is an independent set in G since \(w_j\notin S\) and \(w_j\) is adjacent only to \(v_j\). This contradicts the fact that S is 3-swap-optimal in G.

Thus, \(\{v_i\mid 1 \le i \le \psi \} \subseteq S\). Hence, for each \(i \in [1, \psi ]\)\(p_i\) is not contained in S. Consequently, for each variable z of ZS contains either z or \(\lnot z\) since, otherwise, S would not be 1-swap-optimal. Consequently, \(\tau := S \cap \mathcal {L}(Z)\) is an assignment of Z.

We now show that \(\tau \) satisfies \(\Phi \). To this end, we show that for each clause \(\phi _i \in \Phi \) is satisfied by \(\tau \). Assume towards a contradiction that there is a clause \(\phi _i \in \Phi \) which is not satisfied by \(\tau \), that is, \(\phi _i\cap \tau = \emptyset \). Thus, \(v_i\) is the only neighbor of \(p_i\) in S. Hence, \(S':= (S \cup \{p_i, w_i\}) \setminus \{v_i\}\) is an independent set in G since \(w_i\notin S\) and \(w_i\) is adjacent only to \(v_i\). This contradicts the fact that S is a 3-swap-optimal independent set in G. As a consequence, \(\tau \) satisfies \(\Phi \) and, therefore, I is a yes-instance of 2P2N 3-SAT.

Hence, \(\exists \)-LO-IS is \(\textrm{NP}\)-hard even if \(k=3\) and if the input graph has a maximum degree of four. Due to Observation 2 and the fact that \(v_\exists \) is the only neighbor of \(w_1\) it follows that \((G, w_1, k)\) is a yes-instance of \(\forall \)-LO-IS if and only if \(I'\) is a no-instance of \(\exists \)-LO-IS. Consequently, \(\forall \)-LO-IS is \(\textrm{coNP}\)-hard even if \(k=3\) and if the input graph has a maximum degree of 4. \(\square \)

Fig. 1
figure 1

An illustration of the reduction described in the proof of Theorem 5 for a formula with four clauses. On top, three variable cycles are shown. Assume that the blue vertices of these variable cycles indicate the true positions and that the red vertices of these variable cycles indicate the false positions. Then, the first clause consists of: the positive literal of the first variable, the negative literal of the second variable, and the positive literal of the last variable. Moreover, the second clause contains the positive literal of the first variable and the last clause contains the negative literal of the first clause

Next, we show that the complexity of \(\exists \)-LO-IS and \(\forall \)-LO-IS remains the same on graphs of degree 3 even for every fixed values of \(k\ge 5\). To this end, we first consider the case of \(k=5\).

Theorem 6

\(\exists \)-LO-IS is \(\textrm{NP}\)-complete and \(\forall \)-LO-IS is \(\textrm{coNP}\)-complete if \(k=5\) and \(\Delta = 3\).

Proof

First, we show the statement for \(\exists \)-LO-IS via a reduction from 2P2N 3-SAT. Given an instance \(I=(Z, \Phi )\) of 2P2N 3-SAT, we construct in polynomial time an equivalent instance \(I'=(G=(V,E), v_\exists , k)\) of \(\exists \)-LO-IS where \(k = 5\) and where G has maximum degree 3.

Let \(\psi \) denote the number of clauses of \(\Phi \) and let \(\Phi := \{\phi _1, \dots , \phi _\psi \}\). We start with an empty graph G and add a cycle \((z^1,\lnot z^1,z^2,\lnot z^2, z^1)\) for each variable \(z \in Z\). We add for every clause \(\phi _i=\{\ell _1, \ell _2, \ell _3\}\in \Phi \) the subgraph \(G_{\phi _i} = (V_{\phi _i},E_{\phi _i})\) shown in Fig. 2a. The graph \(G_{\phi _i}\) is a tree on the vertex set \(\{u_i\} \cup \{a_j^i, b_j^i, c_j^i, d_j^i, e_j^i \mid j \in \{1, 2, 3, \vee \}\}\). For each \(j \in \{1, 2, 3, \vee \}\) , \(G_{\phi _i}\) contains the path \((a_j^i, b_j^i, c_j^i, d_j^i, e_j^i)\). These paths and the vertex \(u_i\) are connected by the additional edges \(\{b_1^i, a_{\vee }^i\}, \{b_2^i, a_{\vee }^i\}, \{b_{\vee }^i, u_i\}\) and \(\{b_3^i, u_i\}\). This completes the construction of \(G_{\phi _i}\). Next, we connect a gadget \(G_{\phi _i}\) with the cycles of the variables of \({\phi _i}\) as follows: for every \(j\in [1,3]\), we add an edge between \(a^i_j\) and any free vertex \(\{\ell ^1_j,\ell ^2_j\}\) of degree two. Since every variable occurs twice positively and twice negatively in \(\Phi \), the vertices \(\ell ^1_j\) and \(\ell ^2_j\) are each connected to exactly one subgraph \(G_{\phi _i}\) at the end of the construction. The idea behind \(G_{\phi _i}\) is that there is no 5-swap-optimal independent set for G containing all the vertices of \(a^i_j\)\(j\in \{1,2,3\}\) or none of the vertices of \(\{u_i, b^i_2, b^i_\vee \}\).

Next, we add for each \(i\in [1,\psi -1]\) a vertex \(r_i\) to G. For each such vertex \(p\in \{r_i \mid i\in [1,\psi -1]\}\), we add the subgraph \(G_p=(V_p,E_p)\) shown in Figure 2b. This subgraph contains the vertices  \(p, c_1\) and \(c_2,\) the vertices \(p',q,q^1_3,q^2_3,\) and a cycle \((p_0, p^1_1, p^1_2, p^1_3, p^1_4, p_5, p^2_4, p^2_3, p^2_2, p^2_1, p_0)\). In addition, the set \(E_p\) contains the edges \(\{p^1_3,q^1_3\},\{p^2_3,q^2_3\},\{p^1_1,c_1\},\{p^2_1,c_2\},\{p,p'\},\{p',q\},\) and \(\{p',p_0\}\). These subgraphs are connected to the remaining graph as follows: For each \(i\in [1,\psi -2]\), the vertex \(c_1\) of \(G_{r_i}\) is identified with \(u_i\) (the vertex representing the ith clause) and the vertex \(c_2\) of \(G_{r_i}\) is identified with \(r_{i+1}\). Moreover, for \(i=\psi -1\), the vertex \(c_1\) of \(G_{r_i}\) is identified with \(u_i\) and the vertex \(c_2\) of \(G_{r_i}\) is identified with \(u_{i+1}\).

Finally, we add a path \((v_0, v_1, v_2, v_3,r_1)\) to G and set \(v_\exists := v_1\). This completes the construction of \(I'\). An example of this reduction is shown in Fig. 3. Note that the constructed graph has a maximum degree of 3. We show that I is a yes-instance of 2P2N 3-SAT if and only if \(I'\) is a yes-instance of \(\exists \)-LO-IS.

\((\Rightarrow )\) Let \(\tau \) be an assignment of Z that satisfies \(\Phi \). Let \(\phi _i = \{\ell _1, \ell _2, \ell _3\}\) be a clause of \(\Phi \) and let \(\tau \) be an assignment of Z. We set 

$$\begin{aligned} V_{\phi _i}(\tau ) := \{b^i_j, d^i_j\mid \ell _j\in \tau \} \cup \{a^i_j, c^i_j, e^i_j\mid \ell _j \not \in \tau \} \cup \left\{ \begin{array}{ll} \{b^i_\vee , d^i_\vee \} & \tau \models \{\ell _1, \ell _2\} \\ \{a^i_\vee , c^i_\vee , e^i_\vee \} & \, \text {otherwise} \\ \end{array} \right. . \end{aligned}$$
Fig. 2
figure 2

The gadgets of the reduction of Theorem 6

An example for \(\tau \cap \phi _i = \{\ell _2\}\) is illustrated in Figure 2b, where the black vertices are the vertices of \(V_{\phi _i}(\tau )\). Note that \(V_{\phi _i}(\tau )\) is an independent set. Next, we define a set S based on the assignment \(\tau \). The set S contains the vertices representing the literals of \(\tau \), the vertices of the clause gadgets according to \(\tau \), the black vertices of \(V_p\) shown in Figure 2b for every  \(p\in \{r_i\mid i\in [1,\psi -1]\}\) , and the vertices \(v_3\) and \(v_1=v_\exists \). Formally,

$$\begin{aligned} S:=\{\ell ^1,\ell ^2\mid \ell \in \tau \}\bigcup _{{\phi _i} \in \Phi }V_{\phi _i}(\tau ) \cup \{p', p^1_1, p^1_3, p_5, p^2_3, p^2_1 \mid p {= r_i \mid i } \in [{1,\psi -1}]\} \cup \{v_1, v_3\}. \end{aligned}$$

By construction, S is an independent set. It remains to show that S is 5-swap-optimal. To this end, we observe the following.

Fig. 3
figure 3

An illustration of the reduction described in the proof of Theorem 6 for a formula with four clauses. On top, three variable cycles are shown. Assume that the blue vertices of these variable cycles indicate the true positions and that the red vertices of these variable cycles indicate the false positions. Then, the first clause consists of: the positive literal of the first variable, the negative literal of the second variable, and the positive literal of the last variable. Moreover, the second clause contains the positive literal of the first variable and the last clause contains the negative literal of the first clause

Claim 7

Each vertex \(w\in V\setminus S\) has at least one neighbor in S and if w has degree at least two, w has at least two neighbors in S.

Proof

One can easily check that this holds for all vertices that are not contained in any of the subgraphs \(V_{\phi _i}\) with \(\phi _i\in \Phi \) and, further, for all vertices \(\{b^i_j,c^i_j,d^i_j,e^i_j\mid \phi _i\in \Phi , j\in \{1,2,3,\vee \}\}\). Thus, we only show the claim for \(w\in \{u_i, a^i_1, a^i_2, a^i_3, a^i_\vee \mid \phi _i\in \Phi \}\). Let \(\phi _i=\{\ell _1, \ell _2, \ell _3\}\) be a clause of \(\Phi \). By definition of \(V_{\phi _i}(\tau )\), for all \(j\in \{1,2,3\}\)\(a^i_j \not \in S\) if and only if \(\ell _j \in \tau \). Thus, if \(a^i_j \not \in S\), then \(\ell _j^1 \in S\)\(\ell _j^2 \in S\), and \(b^i_j\in S\). Consequently, \(a^i_j\) has two neighbors in S. If \(a^i_\vee \not \in S\), then \(\tau \) satisfies \(\{\ell _1, \ell _2\}\). Hence, S contains at least one of the vertices of \(\{b^i_1, b^i_2\}\) and, thus, \(a^i_\vee \) has at least two neighbors in S since \(b^i_\vee \in S\).

It remains to show that \(u_i\) has at least two neighbors in S. Since \(u_i\) is identified with either the vertex\(c_1\) or \(c_2\) of some graph \(G_p\), it follows by construction of S that the single neighbor of \(u_i\) in \(V_p\) (\(p^1_1\) or \(p^2_1\)) is contained in S. By definition of \(V_{\phi _i}(\tau )\) and the fact that \(\tau \) satisfies \(\phi _i\), it follows that \(b^i_\vee \in S\) or \(b^i_3 \in S\). Consequently, \(u_i\) has at least two neighbors in S. \(\square \)

Let W be a connected vertex set of size at most 5 in G. We show that \(S\oplus W\) is not an independent set or that \(|S\oplus W| \le |S|\). Note that the only cycles of length at most 4 in G are the variable cycles.This implies that each connected subgraph of G with at most five vertices is either a path or contains all four vertices of a variable cycle.

Case 1: \(V_z \subseteq W\) for some variable \(z\in Z\). If \(W = V_z\), then \(|S\oplus W| = |S|\). Otherwise, let \(v'\) be the unique vertex of \(W\setminus V_z\). By construction, \(v'\) is a vertex of \(\{a^i_1,a^i_2, a^i_3\}\) for some clause \(\phi _i\in \Phi \). Moreover, \(v'\) has only one neighbor in \(V_z\) and a unique neighbor \(v''\) outside of \(V_z\). If \(v'\) is in S, then \(|S\oplus W| = |S| - 1\). Otherwise, due to Claim 7\(v''\) is in S. Hence, \(S\oplus W\) is not an independent set.

Case 2: W is the vertex set of an induced path. Let \(w_1\) and \(w_2\) be the endpoints of this path. If \(|S\oplus W| > |S|\), then S avoids \(w_1\) and \(w_2\). Since degree-one vertices in G have pairwise distance at least six, there is some \(i\in \{1,2\}\) such that \(w_i\) has at least two in G. By Claim 7 there is some neighbor \(v'\) of \(w_i\) outside of W with \(v'\in S\). Hence, \(S\oplus W\) is not an independent set.

Thus, there is no vertex set W of size at most 5 such that \(S\oplus W\) is a larger independent set than S. Consequently, S is a 5-swap-optimal independent set in G containing \(v_\exists = v_1\in S\).

\((\Leftarrow )\) Let S be a 5-swap-optimal independent set in G containing \(v_\exists = v_1\in S\). We show that there is an assignment \(\tau \) of Z that satisfies \(\Phi \). First observe the following.

Claim 8

Let \(p\in \{r_i\mid i\in [1,\psi -1]\}\). If S avoids p but contains \(p'\), then the vertices \(c_1\) and \(c_2\) of \(G_p\) have each at least two neighbors in S.

Note that this also implies, that \(c_1\) and \(c_2\) are not in S.

Proof

We first show that if \(p^1_1\) is not in S or \(p^2_1\) is not in S, then S is not 5-swap-optimal. Since S is an independent set, q is not in S and \(p_0\) is not in S. If \(p^1_1\) is not in S and \(p^2_1\) is not in S, then \((S\cup \{q, p_0\}) \setminus \{p'\}\) is a larger independent set and, thus, S is not 5-swap-optimal. Hence, there is exactly one \(j\in \{1,2\}\) such that \(p^j_1\) is in S and, thus, \(p^j_2\) is not in S. Assume without loss of generality that \(j=1\). If \(p^1_3\) is not in S, then \((S \cup \{q,p_0,p^1_2\})\setminus \{p',p^1_1\}\) is a larger independent set and, thus, S is not 5-swap-optimal. Hence, assume that S contains \(p^1_3\). Consequently, \(q^1_3\) is not in S and \(p^1_4\) is not in S. If S does not contain \(p_5\), then \((S \cup \{q^1_3,p^1_4\}) \setminus \{p^1_3\}\) is a larger independent set and, thus, S is not 5-swap-optimal. Hence, assume that S contains \(p_5\). Consequently, \(p^2_4\) is not in S. If \(p^2_3\) is not in S, then \((S \cup \{q^1_3,p^1_4, p^2_4\})\setminus \{p^1_3,p_5\}\) is a larger independent set and, thus, S is not 5-swap-optimal. Hence, assume that S contains \(p^2_3\). Consequently, \(q^2_3\) is not in S and \(p^2_2\) is not in S. Since we assumed that \(p^2_1\) is not in S\((S \cup \{q^2_3,p^2_2\}) \setminus \{p^2_3\}\) is a larger independent set and, thus, S is not 5-swap-optimal. Consequently, S contains both \(p^1_1\) and \(p^2_1\) and both \(p^1_2\) and \(p^2_2\) are not in S.

Next, we show that if for some \(j\in \{1,2\}\)\(c_j\) has no other neighbor in S besides \(p^j_1\), then S is not 5-swap-optimal. If \(p^j_3\) is not in S, then \((S \cup \{c_j, p^j_2\})\setminus \{p^j_1\}\) is a larger independent set. Otherwise, \(q^j_3\) is not in S and, thus, \((S\cup \{c_j, p^j_2, q^j_3\}) \setminus \{p^j_1, p^j_3\}\) is a larger independent set. In both cases, S is not 5-swap-optimal. \(\square \)

We will use this claim to show that each vertex of\(\{u_i\mid \phi _i\in \Phi \}\) has at least two neighbors in S (for which one has to be from \(G_{\phi _i}\)).

Now, observe that for \(p=r_1\), \(\{v_\exists , v_3,p'\}\subseteq S\) and \(\{v_0, v_2, p\} \subseteq V \setminus S\) as, otherwise, S is not a 5-swap-optimal independent set in G. Hence, S does not contain \(r_1\). With this base case, by Claim 8 one can show inductively, that each vertex of\(\{r_i\mid i\in [2,\psi -1]\} \cup \{u_i\mid \phi _i\in \Phi \}\) is not contained in S and has at least two neighbors in S. This is true, since each such vertex is either the vertex \(c_1\) or the vertex \(c_2\) of some subgraph \(G_p\). Hence, for each clause \(\phi _i\) of \(\Phi \), \(u_i\) is not in S and S contains \(b^i_\vee \) or \(b^i_3\).

We set \(\tau = \{\ell \in \mathcal {L}(Z)\mid \{\ell ^1, \ell ^2\}\cap S \ne \emptyset \}\) and show that \(\tau \) satisfies \(\Phi \). Note that for each variable z of Z\(\tau \) contains at most one of z and \(\lnot z\) since S is an independent set. Let \(\phi _i=\{\ell _1, \ell _2, \ell _3\}\) be a clause of \(\Phi \), we show that \(\tau \) satisfies \(\phi _i\). First, we show that if there is some \(j\in \{1,2,3,\vee \}\) such that \(b^i_j\) is the only neighbor of \(a^i_j\) in S, then S is not 5-swap-optimal. Since S is an independent set, \(c^i_j\) is not in S. If \(d^i_j\) is not in S, then \((S \cup \{a^i_j,c^i_j\})\setminus \{b^i_j\}\) is a larger independent set and, thus, S is not 5-swap-optimal. Otherwise, S contains \(d^i_j\) and, thus, \(e^i_j\) is not in S. Hence, \((S \cup \{a^i_j,c^i_j,e^i_j\})\setminus \{b^i_j,d^i_j\}\) is a larger independent set and, thus, S is not 5-swap-optimal.

We may thus assume that if \(a^i_j\) is not in S for some \(j\in \{1,2,3\}\), then all neighbors of \(a^i_j\) are in S which implies that S contains \(\ell _j^1\) or \(\ell _j^2\). We now use this fact to argue that at least one literal vertex adjacent to any vertex \(a^i_j\) is contained in S and, thus, \(\phi _i\) is satisfied by \(\tau \). Recall that due to Claim 8S contains at least one neighbor of \(u_i\) in \(G_{\phi _i}\), that is, S contains \(b^i_\vee \) or \(b^i_3\). Consequently, if S contains \(b^i_\vee \), then since S is 5-swap-optimal, \(a^i_\vee \) has at least two neighbors in S. Thus, S contains \(b^i_1\) or \(b^i_2\). Hence, there is some \(j\in \{1,2,3\}\) such that S contains \(b^i_j\) and, since S is 5-swap-optimal, all neighbors of \(a^i_j\) are in S. As a consequence, S  contains \(\ell ^1_j\) or \(\ell ^2_j\) which implies that \(\ell _j\) is a literal in \(\tau \). Hence, \(\tau \) satisfies \(\phi _i\). Consequently, I is a yes-instance of 2P2N 3-SAT.

Hence, \(\exists \)-LO-IS is \(\textrm{NP}\)-hard even if \(k=5\) and where the input graph has a maximum degree of 3. Next, we describe how to also obtain \(\textrm{coNP}\)-hardness for \(\forall \)-LO-IS. Due to Observation 2 and the fact that \(v_\exists \) is the only neighbor of \(v_0\) it follows that \((G, v_0, k)\) is a yes-instance of \(\forall \)-LO-IS if and only if \(I'\) is a no-instance of \(\exists \)-LO-IS. Consequently, \(\forall \)-LO-IS is \(\textrm{coNP}\)-hard even if \(k=5\) and where the input graph has a maximum degree of 3.

Corollary 9

For every fixed odd \(k \ge 5\)\(\forall \)-LO-IS is \(\textrm{coNP}\)-complete and \(\exists \)-LO-IS is \(\textrm{NP}\)-complete if \(\Delta = 3\).

Proof

Let \(k \ge 7\) and let \(I=(G=(V,E),v_\exists ,5)\) be an instance of \(\exists \)-LO-IS constructed as in the proof of Theorem 6. By adding for every degree-one vertex w in G a path \(P_w\) with \(k-5\) vertices to G and connecting w with one endpoint of \(P_w\), we obtain an equivalent instance \(I'=(G', v_\exists , k)\) of \(\exists \)-LO-IS. \(\square \)

Hence, except for \(k=3\) and \(\Delta = 3\), we determined the complexity of \(\exists \)-LO-IS and \(\forall \)-LO-IS for each pair of fixed values for k and \(\Delta \).

3.3 Stronger Hardness Results for Unbounded Swap Size

Next, we analyze the case where the swap distance k is unbounded. In this case, the considered problems are complete for complexity classes of the second level of the polynomial hierarchy.

Lemma 10

\(\forall \)-LO-IS is contained in \({\Pi ^{\text {P}}_{2}}\) and \(\exists \)-LO-IS is contained in \(\Sigma ^{\text {P}}_{2}\).

Proof

Deciding whether a given independent set S is k-swap-optimal in a graph G is contained in \(\textrm{coNP}\). Hence, there is a nondeterministic Turing machine which guesses an independent set S with \(v_\exists \in S\) (\(v_\forall \not \in S\), respectively) and afterwards uses the \(\textrm{coNP}\)-algorithm to check if S is a k-swap-optimal independent set in G. Consequently, both \(\exists \)-LO-IS and the complement problem of \(\forall \)-LO-IS are contained in \(\Sigma ^{\text {P}}_{2}\) and, thus, \(\forall \)-LO-IS is contained in \({\Pi ^{\text {P}}_{2}}\). \(\square \)

Theorem 11

\(\forall \)-LO-IS is \({\Pi ^{\text {P}}_{2}}\)-complete (\(\exists \)-LO-IS is \(\Sigma ^{\text {P}}_{2}\)-complete) if \(\Delta = 3\).

Proof

We reduce the \({\Pi ^{\text {P}}_{2}}\)-complete \({\forall \exists }\)-SAT  problem to \(\forall \)-LO-IS.

\({\forall \exists }\)-SATInput: Two disjoint sets of variables X and Y and a set of CNF-clauses \(\Phi \) over the variables \(Z:= X \cup Y\). Question: Is there for each assignment \(\tau _X\) of X an assignment \(\tau _Y\) of Y, such that \(\tau _X \cup \tau _Y\) satisfies \(\Phi \)?

Given an instance \(I=(X,Y,\Phi )\) of \({\forall \exists }\)-SAT, we compute in polynomial time an equivalent instance \(I_2\) of \(\forall \)-LO-IS. We can assume without loss of generality that every clause has size 3, every variable of X occurs two times, every variable of Y occurs four times, and every variable occurs only once per clause since \({\forall \exists }\)-SAT remains \({\Pi ^{\text {P}}_{2}}\)-complete under these restrictions [17]. Let \(\psi \) denote the number of clauses in \(\Phi \) and let \(\Phi = \{\phi _i\mid i\in [1, \psi ]\}\).

Before we start the construction of \(I_2\) we transform I into an equivalent instance \(I'=(X',Y',\Phi ')\) of \({\forall \exists }\)-SAT where for every assignment of \(X'\) there is an assignment of \(Y'\) such that all except one clause of \(\Phi '\) are satisfied.

We set \(X':= X\) and \(Y':= Y \cup \{w_i\mid i\in [1,\psi ]\} \cup \{v\}\). Next, we start with an empty set \(\Phi '\) and add for each clause \(\phi _i = \{\ell _1, \ell _2, \ell _3\} \in \Phi \) two new clauses \(\phi '_i:=\{\ell _1, \ell _2,w_i\}\) and \(\phi '_{\psi +i}:=\{\lnot w_i, \ell _3, \lnot v\}\). Finally, we add the clause \(\phi '_{2\psi + 1}:= \{v\}\) to \(\Phi '\). Let \(\psi ':= |\Phi '| = 2\psi +1\) and let \(Z':= X' \cup Y'\). The idea is that \(\{\lnot v, w_i\mid i\in [1, \psi ]\}\) satisfies all clauses except \(\phi '_{2\psi + 1}=\{v\}\). Thus, for every assignment on the variables of \(X'\), there is an assignment of the variables of \(Y'\) such that all but one clauses are satisfied.

Claim 12

The instance I is a yes-instance of \({\forall \exists }\)-SAT if and only if \(I'\) is a yes-instance of \({\forall \exists }\)-SAT.

Proof

\((\Rightarrow )\) Suppose that I is a yes-instance of \({\forall \exists }\)-SAT. Let \(\tau _X\) be an assignment of X. Since I is a yes-instance of \({\forall \exists }\)-SAT, there is an assignment \(\tau _Y\) of Y such that \(\tau _Z:= \tau _X \cup \tau _Y\) satisfies \(\Phi \). We set

$$\tau _{Y'} = \tau _{Y} \cup \{v\} \cup \{w_i\mid \phi _i=\{\ell _1, \ell _2, \ell _3\} \in \Phi , \ell _3 \in \tau _Z\}$$

and show that \(\tau '\) satisfies \(\Phi '\) where \(\tau ' = \tau _X \cup \tau _{Y'}\). Note that, \(\tau '\) satisfies \(\{v\}\). Let \(\phi _i=\{\ell _1, \ell _2, \ell _3\}\) be a clause of \(\Phi \). Since \(\tau _Z\) satisfies \(\phi _i\), it follows that \(\ell _3\) is a literal of \(\tau _Z\) or \(\tau _Z\) contains \(\ell _1\) or \(\ell _2\).

Case 1: \(\ell _3\) is a literal of \(\tau _Z\). Hence, \(\tau '\) satisfies \(\phi '_{\psi + i} =\{\lnot w_i, \ell _3, \lnot v\}\). Further, by construction \(w_i\) is a literal of \(\tau _{Y'}\) and, therefore, \(\tau '\) satisfies \(\phi '_{i} =\{\ell _1, \ell _2, w_i\}\).

Case 2: \(\ell _3\) is not a literal of \(\tau _Z\). Hence, \(\tau _Z\) contains \(\ell _1\) or \(\ell _2\) which implies that, \(\tau '\) satisfies \(\phi '_{i} = \{\ell _1, \ell _2, w_i\}\). Further, by construction, \(w_i\) is not a literal of \(\tau _{Y'}\) and, therefore, \(\tau '\) satisfies \(\phi '_{\psi + i}= \{\lnot w_i, \ell _3, \lnot v\}\). Consequently, \(\tau '\) satisfies \(\Phi '\).

\((\Leftarrow )\) Suppose that \(I'\) is a yes-instance of \({\forall \exists }\)-SAT. Let \(\tau _X\) be an assignment of X. Since \(I'\) is a yes-instance of \({\forall \exists }\)-SAT, there is some assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau '\models \Phi '\) where \(\tau ' = \tau _{X} \cup \tau _{Y'}\). We set \(\tau _{Y}:= \tau _{Y'} \cap \mathcal {L}(Y)\) and show that \(\tau _Z\) satisfies \(\Phi \) where \(\tau _Z:= \tau _{X} \cup \tau _Y\). Let \(\phi _i = \{\ell _1, \ell _2, \ell _3\}\) be a clause of \(\Phi \). Since \(\tau ' \models \{v\}\)v is a literal of \(\tau '\). Moreover, since \(\tau '\) satisfies both \(\phi '_{i} = \{\ell _1, \ell _2, w_i\}\) and \(\phi '_{\psi + i} = \{\lnot w_i, \ell _3, \lnot v\}\) and contains either \(w_i\) or \(\lnot w_i\)\(\tau '\) satisfies \(\phi _i = \{\ell _1, \ell _2, \ell _3\}\). Hence, \(\tau _Z\) satisfies \(\tau \models \phi _i\). Consequently, \(\tau \) satisfies \(\Phi \). \(\square \)

Further, we denote with c(z) the occurrence number of a variable z of \(Z'\), that is, the number of clauses of \(\Phi '\) containing z or \(\lnot z\). By construction it holds that \(c(v):= \psi + 1, c(y):= 4\) if \(y\in Y\), and \(c(z):= 2\) otherwise. Moreover, for every variable \(z\in Z'\) and every \(i\in [1, c(z)]\) we set \(\#(z, i):= j\) if z occurs in \(\phi '_j\) and z occurs in exactly \(i-1\) clauses in \(\{\phi '_r\mid 1 \le r < j\}\). Hence, \(\#(z, i)\) denotes the index of the clause in which the ith occurrence of z is contained.

Next, we describe how to construct the equivalent \(\forall \)-LO-IS-instance \(I_2=(G, v, k)\). We start with an empty graph and add for every clause \(\phi '_i = \{\ell _1, \ell _2, \ell _3\}~\) of \(\Phi ' \setminus \{\{v\}\}\) a clique \(\Gamma _i:= \{\ell ^i_1, \ell ^i_2, \ell ^i_3\}\) to G. Moreover, we add a vertex \(v^{\psi '}\) to represent the single literal in the clause \(\{v\}\in \Phi '\).

We add for every \(y \in Y\) a variable cycle \(G_y=(V_y, E_y)\) of length 8 and for every \(z \in X \cup \{v\}\) a variable cycle \(G_z=(V_z, E_z)\) of length \(4 \psi + 8\cdot |Y|\). Recall that for every variable cycle \(G_z\)C(z) denotes the true positions of \(G_z\) and \(C(\lnot z)\) denotes the false positions of \(G_z\). Further, we add for each variable \(z\in Z \cup \{v\}\) and each occurrence \(i\in [1,c(z)]\) an edge between \(\top ^i_z\) and \(\lnot z^{\#(z,i)}\) to G if z occurs negatively in \(\phi '_{\#(z,i)}\) and an edge between \(\bot ^i_z\) and \(z^{\#(z,i)}\) to G, otherwise. Moreover, we add for each \(i\in [1,\psi ]\) an edge between \(w_i^i\) and \(\lnot w_i^{\psi + i}\) to G. Thus, no independent set can contain \(w_i^i\) and \(\lnot w_i^{\psi + i}\) for any \(i\in [1,\psi ]\).

Note that every independent set S can contain at most one vertex of \(\Gamma _i\) for every \(i\in [1,\psi '-1]\) and for every variable cycle of length 2q at most q vertices. Thus, the maximum independent set in G has size at most \(k^*:=\psi ' + 4\cdot |Y| + (|X|+1)(2\psi + 4\cdot |Y|)\).

Finally, we set \(v_\forall := v^{\psi '}\) and \(k:= 2(4\psi + 8|Y|) + 1\), that is, twice the length of the variable cycle of v plus one. This completes the construction of \(I_2\). We show that G has a maximum degree of 3. Note that each vertex in any variable cycle has two neighbors inside the variable cycle and at most one vertex outside the variable cycle. Moreover, each vertex representing a literal in a clause \(\phi \) is only adjacent to the two vertices representing the other literals of the clause \(\phi \) and to exactly one vertex in a variable cycle. Hence, each vertex in G has at most three neighbors.

The idea of this construction is that for every assignment \(\tau _X\) for X there is an independent set S of size \(k^*-1\) in G such that \(v_\forall \not \in S\), S  contains all vertices of \(C(\lnot v)\), and S contains all vertices of \(C(\ell )\) for all \(\ell \in \tau _X\). We will show that this independent set is k-swap-optimal in G if and only if there is no assignment \(\tau _Y\) for \(Y'\) such that \(\tau _X \cup \tau _Y\) satisfies \(\Phi '\). Next, we formally prove this intuition, that is, we show that \(I'\) is a yes-instance of \({\forall \exists }\)-SAT if and only if \(I_2\) is a yes-instance of \(\forall \)-LO-IS.

\((\Rightarrow )\) We show that if \(I'\) is a yes-instance of \({\forall \exists }\)-SAT, then \(I_2\) is a yes-instance of \(\forall \)-LO-IS. To this end we first show the following claim. Informally, it states that every k-swap-optimal independent set S in G which does not contain \(v_\forall \), has to contain the false positions of \(G_v\) and for every variable z of ZS has to contain either the true or the false positions of \(G_z\).

Claim 13

Let S be a k-swap-optimal independent set in G which does not contain \(v_\forall \). Then, \(C(\lnot v) \subseteq S\) and for each variable z of Z, either \(C(z)\subseteq S\) or \(C(\lnot z)\subseteq S\).

Proof

First, we show that if \(v_\forall \) is not in S and not all vertices of \(C(\lnot v)\) are in S, then S is not k-swap-optimal. Suppose that \(v_\forall \) is not in S and not all vertices of \(C(\lnot v)\) are in S. Recall that \(\bot _v^{\psi + 1}\) is a vertex of \(C(\lnot v)\) and the unique neighbor of \(v_\forall \) in G. If \(\bot _v^{\psi + 1}\) is not in S then S is not maximal since we can add \(v_\forall \) to S and obtain a larger independent set. Thus, assume that \(\bot _v^{\psi + 1}\) is in S. Hence, S does not contain all vertices of C(v) and, therefore, S contains less than \(|C(\lnot v)|\) vertices of \(V_v = C(v) \cup C(\lnot v)\). Since \(C(\lnot v)\) is an independent set and \(N(C(\lnot v)) = C(v) \cup \{v_\forall \}\), the set \(S':= (S \setminus V_v) \cup C(\lnot v)\) is a larger independent set in G and has symmetric difference of size at most \(|V_v| < k\) with S. As a consequence, S is not k-swap-optimal.

Next, we show that if \(v_\forall \) is not in S and there is a variable z of Z such that S does not contain all vertices of C(z) and S does not contain all vertices of \(C(\lnot z)\), then S is not k-swap-optimal. Assume towards a contradiction, that S is a k-swap-optimal independent set in G and that there is a variable z of Z such that S does not contain all vertices of C(z) and S does not contain all vertices of \(C(\lnot z)\). Hence, S contains less than |C(z)| vertices of \(V_z = C(z) \cup C(\lnot z)\). We show that we can obtain a larger independent set \(S'\) with a symmetric difference of size at most k with S by removing all vertices of \(V_z\) and all vertices of the clause gadgets and replacing them by the true positions C(z) and the vertices representing the assignment of \(\Phi '\) that satisfies all but one clause. Formally, we set

$$S':= \left( S \setminus \left( V_z \cup \bigcup _{i=1}^{2\psi }\Gamma _i\right) \right) \cup C(z) \cup \left\{ w_i^i, \lnot v^{\psi + i} \mid 1 \le i \le \psi \right\} .$$

First, we show that \(S'\) is an independent set in G which is larger than S. To this end, note that since for each \(i\in [1,2\psi ]\)\(\Gamma _i\) is a clique in G. Hence, S contains at most \(2\psi \) vertices of \(\bigcup _{i=1}^{2\psi }\Gamma _i\) and \(S'\) contains exactly the \(2\psi \) vertices \(\left\{ w_i^i, \lnot v^{\psi + i} \mid 1 \le i \le \psi \right\} \) of \(\bigcup _{i=1}^{2\psi }\Gamma _i\). Since S contains less than |C(z)| vertices of \(V_z\) and \(S'\) contains all vertices of C(z), we conclude that \(S'\) is larger than S. By construction, C(z) is an independent set in G and each vertex of C(z) is adjacent only to vertices of \(\bigcup _{i=1}^{2\psi }\Gamma _i\). Moreover, \(\left\{ w_i^i, \lnot v^{\psi + i} \mid 1 \le i \le \psi \right\} \) is an independent set in G with neighbors only in \(C(v)\cup \bigcup _{i=1}^{2\psi }\Gamma _i\). This implies that \(S'\setminus S\) is an independent set. Moreover, since by the above, \(C(\lnot v)\subseteq S\)S avoids all vertices of C(v). Hence, no vertex of \(S\cap S'\) is adjacent to any vertex of \(S'\setminus S\). Since S is an independent set in G\(S\cap S'\) is an independent set in G, which then implies that \(S' = (S'\setminus S) \cup (S\cap S') \) is an independent set in G.

It remains to show that the symmetric difference between S and \(S'\) has size at most k. By construction, \(V_z\) has size at most \(4\psi + 8|Y|\) which implies that the symmetric difference of S and \(S'\) has size at most \(4\psi + 8|Y| + 4\psi < k\). This contradicts the fact that S is k-swap-optimal.

Hence, if S is a k-swap-optimal independent set in G such that \(v_\forall \) is not in S, then S contains all vertices of \(C(\lnot v)\) and for each variable z of Z either all vertices of C(z) or all vertices of \(C(\lnot z)\). \(\square \)

We now show that if \(I'\) is a yes-instance of \({\forall \exists }\)-SAT, then \(I_2\) is a yes-instance of \(\forall \)-LO-IS. Assume towards a contradiction that \(I_2\) is a no-instance of \(\forall \)-LO-IS, that is, there is a k-swap-optimal independent set S in G not containing \(v_\forall \). Note that this S has size at most \(k^*-1 = \psi ' + 4\cdot |Y| + (|X|+1)(2\psi + 4\cdot |Y|) - 1\), since S does not contain \(v_\forall \). Due to Claim 13S contains all vertices of \(C(\lnot v)\) and there is an assignment \(\tau _Z\) of Z such that S contains all vertices of \(C(\tau _Z)\), that is, for each literal \(\ell \) of \(\tau _Z\)S contains all vertices of \(C(\ell )\).

Let \(\tau _X:= \tau _Z \cap \mathcal {L}(X)\) be the subset of \(\tau _Z\) which is an assignment of X. Since \(I'\) is a yes-instance of \({\forall \exists }\)-SAT, there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{Z'}:= \tau _X \cup \tau _{Y'}\) satisfies \(\Phi '\). By definition, for each clause \(\phi '\) of \(\Phi '\)\(\tau _{Z'}\) contains at least one literal of \(\phi '\). For each clause \(\phi _i'\) of \(\Phi '\), take an arbitrary vertex \(\ell ^i\) such that \(\ell \) is a literal both of \(\tau _{Z'}\) and \(\phi _i'\). We show that we can obtain a larger independent set \(S'\) of symmetric difference at most k with S by taking the vertices of \(C(\tau _{Z'})\) and for each clause \(\phi _i'\) the vertex \(\ell ^i\) of \(\Gamma _i\). Formally, we set

$$S':= \bigcup \{C(\ell ')\mid \ell ' \in \tau _{Z'}\cap \mathcal {L}(Z)\} \cup C(v) \cup \{\ell ^i\mid 1\le i \le \psi '\}{.}$$

Note that \(S'\) has size \(k^* = \psi ' + 4\cdot |Y| + (|X|+1)(2\psi + 4\cdot |Y|) > |S|\). Moreover, we define W as the symmetric difference between S and \(S'\). That is, W switches the variable cycle of v to true positions via swapping at most \(|V_v| = 4\psi + 8|Y|\) vertices, removes at most one vertex for every \(\Gamma _i, i\in [1,2\psi ]\) via swapping at most \(2\psi \) vertices, adds at most one vertex for every \(\Gamma _i, i\in [1,\psi ']\) via swapping at most \(\psi ' = 2\psi + 1\) vertices, and switches—in the extreme case—every variable cycle for any variable y of Y from true positions to false positions or vice versa via swapping at most \(8\cdot |Y|\) vertices in total. Thus, W has size at most \(4\psi + 8|Y| + 2\psi + 2\psi + 1 + 8|Y| = k.\) It remains to show that \(S'\) is an independent set. Let \(\tau _Z:= \tau _{Z'}\cap \mathcal {L}(Z)\). By construction, \(C(\tau _Z) \cup C(v)\) is an independent set. Thus, it is sufficient to show that for no clause \(\phi _i'\) of \(\Phi '\), \(\ell ^i\) is adjacent to any other vertex of \(S'\). Since \(S'\) contains only one vertex of \(\Gamma _i\) and each vertex of \(\Gamma _i\) has only one neighbor outside of \(\Gamma _i\), we only have to show that the unique neighbor \(u_i\) of \(\ell ^i\) outside of \(\Gamma _i\) is not contained in \(S'\). This holds for \(\ell ^{\psi '} = v^{\psi '}\) since \(u_{\psi '} = \bot ^{\psi +1}\) is not contained in \(S'\) since \(S'\) contains all vertices of C(v). If \(\ell ^i = w_i^i\), then \(u_i = w_{i+\psi }^i\) is not contained in \(S'\) since \(\tau _{Z'}\) is an assignment and thus contains either \(w_i\) or \(\lnot w_{i}\). Due to symmetry, the same holds for \(\ell ^i = \lnot w_{i-\psi }^i\), that is, if \(\ell ^i = \lnot w_{i-\psi }^i\), then \(u_i = w_{i}^{i-\psi }\) is not contained in \(S'\). If \(\ell ^i = z^i\) for some variable z of Z, then \(u_i = \bot _z^j\) where \(i = \#(z,j)\). Since \(z^i \in S'\), we know that z is a literal of \(\tau _{Z'}\). By construction, \(S'\) contains all vertices of C(z) and, therefore, \(u_i = \bot _z^j\) is not in \(S'\). The case \(\ell ^i = \lnot z^i\) can be shown analogously.

As a consequence, \(S'\) is an independent set of size \(k^* > |S|\) in G and has a symmetric difference of size at most k with S. Thus, S is not k-swap-optimal, a contradiction.

\((\Leftarrow )\) We show that if \(I_2\) is a yes-instance of \(\forall \)-LO-IS, then \(I'\) is a yes-instance of \({\forall \exists }\)-SAT.

To this end we first show the following claim. Informally, it states that if an independent set of size \(k^* - 1\) encodes an assignment \(\tau _X\) for X that satisfies all clauses except \(\{v\}\) and is not k-swap-optimal, then there is an assignment \(\tau _{Y'}\) for \(Y'\) such that \(\tau _X \cup \tau _{Y'}\) satisfies \(\Phi '\).

Claim 14

Let \(\tau _X\) be an assignment of X. If 

$$S(\tau _X):= C(\tau _X) \cup C(Y) \cup C(\lnot v) \cup \{\lnot v^{\psi + i}, w^i_i\mid 1 \le i \le \psi \}$$

is not a k-swap-optimal independent set in G, then there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X}\cup \tau _{Y'}\) satisfies \(\Phi '\).

Proof

By construction, \(S(\tau _{X})\) is an independent set of size \(k^*-1\) in G. Thus, if \(S(\tau _{X})\) is not k-swap-optimal in G, then there is an independent set \(S'\) of size \(k^*\) such that the symmetric difference W of S and \(S'\) has size at most k. Hence, \(S'\) contains for each clause \(\phi _i'\) of \(\Phi '\) exactly one vertex of \(\Gamma _i\)\(S'\) contains all vertices of C(v), and for each variable z of ZS contains either all vertices of C(z) or all vertices of \(C(\lnot z)\).

First, we show that the true and false positions of the variable cycles in \(S'\) imply an assignment \(\tau '\) of \(Z'\) which satisfies \(\Phi '\). We set

$$\begin{aligned} \tau ' := \{\ell \in \mathcal {L}(Z)\mid C(\ell ) \subseteq S'\} \cup \{v\} \cup \{ w_i&\mid 1 \le i \le \psi , w^i_i \in S'\}\\ \cup \{\lnot w_i&\mid 1 \le i \le \psi , w^i_i \not \in S' \}. \end{aligned}$$

Let \(\phi '_i\) be a clause of \(\Phi '\). We show that \(\tau '\) satisfies \(\phi '_i\). Since \(S'\) has size \(k^*\), there is a literal \(\ell \) of \(\phi _i'\) such that the vertex \(\ell ^i\) of \(\Gamma _i\) is in \(S'\). It remains to show that \(\ell \in \tau '\).

Case 1: \(\ell = w_i\) By definition \(w_i\) is a literal of \(\tau '\).

Case 2: \(\ell = \lnot w_{i - \psi }\). Hence, \(w_{i - \psi }^{i - \psi }\) is not in \(S'\) since \(S'\) is an independent set. Thus, by construction, \(w_{i - \psi }\) is not in \(\tau '\) and, therefore, \(\lnot w_{i - \psi }\) is a literal of \(\tau '\).

Case 3: \(\ell = z\) for some variable z of \(Z \cup \{v\}\). Since \(S'\) is an independent set, \(\ell ^i = z^i\) is a vertex of \(S'\), and \(z^i\) is adjacent to a vertex of \(C(\lnot z)\)\(S'\) contains all vertices of C(z) which implies that z is a literal of \(\tau '\).

Case 4: \(\ell = \lnot z\) for some variable z of \(Z \cup \{v\}\). Since \(S'\) is an independent set, \(\ell ^i = \lnot z^i\) is a vertex of \(S'\), and \(\lnot z^i\) is adjacent to a vertex of C(z), \(S'\) contains all vertices of \(C(\lnot z)\) which implies that \(\lnot z\) is a literal of \(\tau '\).

Next, we show that the assignment \(\tau ' \cap \mathcal {L}(X)\) of X in \(\tau '\) is equal to \(\tau _X\). Recall that W is the symmetric difference between S and \(S'\). Since \(v_\forall \) is the only vertex of \(\Gamma _{\psi '}\)\(S'\) contains \(v_\forall \) which implies that \(\bot _v^{\psi + 1}\) is not in \(S'\). Hence \(S'\) contains all vertices of \(C(v_\forall )\). Consequently, for each \(i\in [1,\psi ]\)\(\lnot v^{\psi + i}\) is not contained in \(S'\). Hence, W contains all vertices of \(N[V_v]\). As a consequence, the remaining vertices of \(W \setminus N[V_v]\) are at most \(k - (4\psi + 8|Y| + \psi + 1) < 4\psi + 8|Y|\) which is less than the length of a variable cycle of any variable x in X. Thus, no variable cycle for any variable of x in X is switched from true positions to false positions or vice versa by W. As a consequence, \(S'\) contains all vertices of \(C(\tau _X)\) which implies that \(\tau ' \cap \mathcal {L}(X)\) is equal to \(\tau _X\). Hence, there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X} \cup \tau _{Y'}\) satisfies \(\Phi '\). \(\square \)

Since \(v_\forall \) is contained in every k-swap-optimal independent set for G, for each assignment \(\tau _{X}\) of X the independent set \(S(\tau _{X})\) is not k-swap-optimal in G, since \(v_\forall \) is not in \(S(\tau _{X})\). Thus, due to Claim 14, for each assignment \(\tau _{X}\) of X, there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X} \cup \tau _{Y'}\) satisfies \(\Phi '\). Hence, \(I'\) is a yes-instance of \({\forall \exists }\)-SAT.

Thus, \(\forall \)-LO-IS is \(\Pi ^{\text {P}}_{2}\)-hard even on graphs with a maximum degree of 3. Due to Observation 2 and the fact that \(\bot _v^{\psi + 1}\) is the only neighbor of \(v_\forall \), we obtain that \((G, \bot _v^{\psi + 1}, k)\) is a yes-instance of \(\exists \)-LO-IS if and only if \((G, v_\forall ,k)\) is a no-instance of \(\forall \)-LO-IS. Consequently, \(\exists \)-LO-IS is \(\Sigma ^{\text {P}}_{2}\)-hard even on graphs with a maximum degree of 3.

4 Max Cut

We now analyze the complexity of deciding whether an edge is a cut edge of some locally optimal cut for the Max Cut problem. We formally define cuts and their local neighborhoods as follows. Let S and T be subsets of V. The pair (ST) is a cut in G if \(S\cup T = V\) and \(S\cap T = \emptyset \).

A cut (ST) is a k-flip-optimal cut in G if there is no k-swap W in G such that \(|E(S',T')| > |E(S,T)|\) where \(S' = S \oplus W\) and \(T' = T \oplus W = V \setminus S'\). Let A and B be subsets of V. We say that A and B are in the same part of the cut if S contains all vertices of \(A \cup B\) or if T contains all vertices of \(A \cup B\). Moreover, A and B are in opposite parts of the cut if S contains all vertices of A and T contains all vertices of B, or vice versa. We say that an edge e is contained in a cut (S,T) if \(e\in E(S,T)\).

Observation 15

Let (ST) be a cut in a graph G. For each cycle of odd length in G, at least one edge is not contained in (ST).

In the following, we consider the problem, where we ask for the containment of a given edge in any k-flip-optimal cut.

Every Locally Optimal Max-Cut (\({\forall }\)-LO-MC) Input: An undirected graph \(G=(V,E)\), an edge \(e\in E\), and \(k\in \mathbb {N}\). Question: Is e contained in every k-flip-optimal cut in G?

Analogously, we ask in Some Locally Optimal Max-Cut (\({\exists }\)-LO-MC) if e is contained in some k-flip-optimal cut in G.

For every fixed value of k, we can check in polynomial time if a given cut (ST) is k-flip-optimal in G. Consequently, we obtain the following.

Observation 16

For every fixed value of k, \({\forall }\)-LO-MC is contained in \(\textrm{coNP}\) and \({\exists }\)-LO-MC is contained in \(\textrm{NP}\).

4.1 NP-Hardness for Flips of Size 1

We now show that both problems are hard, even for constant k and \(\Delta \). In the reduction, we use a graph called (2,3)-enforcer which is shown in Fig. 4. For a (2, 3)-enforcer F, we denote \(F_1:= B_1 \cup M_1\) and \(F_2:= B_2 \cup M_2\).

Proposition 17

Let G be a graph with \(\Delta (G) = 5\). If G contains a (2, 3)-enforcer \(F=(B_1\cup B_2 \cup M_1 \cup M_2,E')\) as an induced subgraph, then for every 1-flip-optimal cut (ST) in G\(F_1\) and \(F_2\) are in opposite parts of the cut.

Fig. 4
figure 4

A (2, 3)-enforcer \(F=(B_1\cup B_2\cup M_1 \cup M_2, F_E)\). The vertices of \(F_1\) are inside the yellow boxes and the vertices of \(F_2\) are inside the blue boxes

Proof

Let (ST) be a 1-flip-optimal cut in G. If not all vertices of \(M_1\) are in the same part of the cut, then there is a vertex v of \(M_1\) in S and a vertex w of \(M_1\) in T. Since the neighborhood of both v and w is \(B_2 \cup M_2\) and has odd size, v and w have both more neighbors in S than in T or the other way around. Hence, either \(\{v\}\) or \(\{w\}\) is an improving 1-flip for (ST), a contradiction. Consequently, all vertices of \(M_1\) are in the same part of the cut. Due to symmetry, the same property holds for \(M_2\).

Moreover, since \(M_2\) contains more vertices than \(B_2\)\(M_1\) and \(M_2\) are in opposite parts of the cut as, otherwise, \(\{v\}\) is an improving flip for every vertex \(v\in M_1\) which would contradict the fact that (ST) is 1-flip-optimal. Further, since each vertex of \(B_1\) is adjacent to each of the three vertices of \(M_2\) and G has degree at most 5, (ST) is not 1-flip-optimal if there is a vertex of \(B_1\) in the same part of the cut as \(M_2\) Due to symmetry, the same arguments also show that \(B_2\) and \(M_1\) are in opposite parts of the cut. \(\square \)

Theorem 18

\({\exists }\)-LO-MC is \(\textrm{NP}\)-complete and \({\forall }\)-LO-MC is \(\textrm{coNP}\)-complete if \(k = 1\) and \(\Delta = 5\).

Proof

We reduce 2P2N 3-SAT to \({\exists }\)-LO-MC. Given an instance \(I=(Z, \Phi )\) of 2P2N 3-SAT, we construct in polynomial time an equivalent instance \(I'=(G=(V,E), e_\exists , k)\) of \({\exists }\)-LO-MC where \(k = 1\) and where G has a maximum degree of 5. Further, we let \(\psi \) denote the number of clauses in \(\Phi \) and we assume that \(\psi =2^r\) for some even r.

Let \(\Phi = \{\phi _1, \dots , \phi _{\psi }\}\). We start with an empty graph G and add a balanced binary tree with \(r+1\) levels. We denote for each \(p \in [0,r]\) with \(L_p:= \{u_q^p\mid q \in [1,2^p]\}\) the vertices of the pth level of the tree. For each \(q \in [1, \psi ]\), the leaf \(u^r_q\) represents the clause \(\phi _q\). Further, we add a (2, 3)-enforcer \(F^\exists \) with \(B_1^\exists =\{w^1_\exists ,w^2_\exists \}\) and \(B_2^\exists =\{w^1_\forall ,w^2_\forall \}\) to G and, for each variable v of Z, we add a (2, 3)-enforcer \(F^v\) with \(B_1^v=\{v, v'\}\) and \(B_2^v=\{\lnot v, \lnot v'\}\) to G.

The idea is that \(F^v_1\) corresponds to the true-assignment of v and that \(F^v_2\) corresponds to the false-assignment of v since v is a vertex of \(F^v_1\) and \(\lnot v\) is a vertex of \(F^v_2\). By Proposition 17\(F^v_1\) and \(F^v_2\) are in opposite parts of every 1-flip-optimal cut for G. Thus, for every 1-flip-optimal cut (ST) for G, both \(S\cap \mathcal {L}(Z)\) and \(T\cap \mathcal {L}(Z)\) are assignments for the variables of Z.

Recall that \(u^r_q\) is the vertex of G that represents the clause \(\phi _q\). For each clause \(\phi _q\) of \(\Phi \) and each literal \(\ell \) of \(\phi _q\), we add an edge between \(\ell \) and \(u^r_q\) to G. Furthermore, we add edges to G such that \(L_1 \cup \{w^2_\exists \}\) is a cycle of length 3 and for each level \(p\in [2,r-1]\), we add edges to G such that \(L_p\) is a cycle of length \(2^p\). Finally, we add the edges between \(u^0_1\) and each of the vertices \(w^1_\forall ,w^2_\forall ,\) and \(w^1_\exists \) and we set \(e_\exists = \{w^1_\exists ,u^0_1\}\). This completes the construction of \(I'\). An example of this reduction is shown in Fig. 5. We now show that I is a yes-instance of 2P2N 3-SAT if and only if \(I'\) is a yes-instance of \({\exists }\)-LO-MC.

Fig. 5
figure 5

An illustration of the reduction described in the proof of Theorem 18 for a formula with 16 clauses. On top, three (2, 3)-enforcer are shown that represent the variables of the formula. Assume that the blue (red) vertices of these (2, 3)-enforcers indicate the positive (negative) literals of the corresponding variables. Then, the first clause consists of: the positive literal of the first variable, the negative literal of the second variable, and the positive literal of the last variable. Moreover, the fourth clause contains the positive literal of the first variable and the fifth clause contains the negative literal of the first clause. The dotted edges indicate the induced cycles of each level of the binary tree. Dotted edges are not contained in any 1-flip-optimal cut that contains the edge \(e_\exists \)

\((\Rightarrow )\) Let \(\tau _Z\) be an assignment of Z which satisfies \(\Phi \). We set 

$$S:=F^\exists _1 \cup \bigcup _{\text {odd~}p\in [1,r-1]}L_p \cup \bigcup _{v\in \widetilde{Z}}F^v_1 \cup \bigcup _{v\in Z\setminus \widetilde{Z}}F^v_2$$

and \(T= V \setminus S\) and show that (ST) is a 1-flip-optimal cut in G and contains \(e_\exists \). Note that for each literal \(\ell \) in \(\mathcal {L}(Z)\)S contains the vertex \(\ell \) if and only if \(\ell \) is a literal of \(\tau _Z\).

By construction, G has a maximum degree of 5. Thus, for every vertex v in any enforcer it follows that at least half of the neighbors of v are in the opposite part of the cut of v. Further, for each level \(p \in [1, r-1]\), each vertex v of \(L_p\) has two neighbors in \(L_{p+1}\) and one neighbor in \(L_{p-1}\). Hence, more than half of the neighbors of v are in the opposite part of the cut. The same also holds for the root \(u^0_1\) since \(u^0_1\) is in T and has three neighbors in the opposite part of the cut, namely, both vertices of \(L_1\) and the vertex \(w^1_\exists \). Since \(L_r \subseteq T\), it remains to show that for each \(q\in [1, \psi ]\), \(u^r_q\) has at least two neighbors in S, since \(u^r_q\) has only four neighbors. By definition of (ST), \(u^r_q\) has one neighbor in \(L_{r-1}\) which is contained in S. Moreover, since \(\tau _Z\) satisfies \(\Phi \), there is at least one literal \(\ell \) in \(\tau _Z\) which is contained in \(\phi _q\). Hence, the vertex \(\ell \) is in S and a neighbor of \(u^r_q\). Consequently, for each vertex v of V, at least half of the neighbors of v are in the opposite part of the cut of v. Therefore, (ST) is a 1-flip-optimal cut in G such that \(e_\exists \) is in E(ST).

\((\Leftarrow )\) Let (ST) be a 1-flip-optimal cut in G which contains the edge \(e_\exists \). By Proposition 17, we may assume without loss of generality that S contains all vertices of \(F^\exists _1\) and T contains all vertices of \(F^\exists _2\). Further, for every variable v of ZS contains either all vertices of \(F^v_1\) or all vertices of \(F^v_2\). Hence, \(\tau _{Z}:= \{v\in Z \mid F^v_1 \subseteq S\} \cup \{\lnot v \mid v\in Z, F^v_2 \subseteq S\}\) is an assignment of Z. We show that \(\tau _Z\) satisfies \(\Phi \). Note that for every literal \(\ell \) of \(\mathcal {L}(Z)\)\(\ell \) is a literal of \(\tau _Z\) if and only if \(\ell \) is a vertex of S since v is a vertex of \(F^v_1\) and \(\lnot v\) is a vertex of \(F^v_2\). Before we show that \(\tau _Z\) satisfies \(\Phi \), we make some observations about the structure of S and T.\(\square \)

Claim 19

For each level \(p\in [0,r]\)S contains all vertices of \(L_p\) if p is odd and T contains all vertices of \(L_p\) if p is even.

Proof

We show this statement via induction over the level p. First, we show the base cases for \(p \in \{0,1,2\}\). Since \(e_\exists \) is in E(ST) and \(w^1_\exists \) is in S\(u_1^0\) is a vertex of T. Further, since \(w^1_\forall \) and \(w^2_\forall \) are in T and adjacent to \(u^0_1\), both vertices of \(L_1\) are in S as, otherwise, \(u^0_1\) has more neighbors in the same part of the cut than in the opposite part of the cut which would contradict that (ST) is 1-flip-optimal. By construction, the three vertices of \(L_{1}\cup \{w^2_\exists \}\) form a cycle which implies that each vertex v of \(L_1\) has at least two neighbors in S since all three vertices of \(L_{1}\cup \{w^2_\exists \}\) are in S. Hence, both neighbors of v in \(L_2\) are in T as, otherwise, v has more neighbors in the same part of the cut than in the opposite part of the cut which would contradict that (ST) is 1-flip-optimal. Since each vertex of \(L_2\) has a neighbor in \(L_1\), each vertex of \(L_2\) is in T.

Now, suppose that the statement is true for some level \(p \in [2,r-1]\), we show that the statement is also true for level \(p+1\). Due to symmetry, we show this only for even values of p. By the induction hypothesis, T contains all vertices of \(L_p\). By construction, \(L_{p}\) forms a cycle which implies that each vertex v of \(L_p\) has two neighbors in T. Hence, both neighbors of v in \(L_{p+1}\) are in S as, otherwise, v has more neighbors in the same part of the cut than in the opposite part of the cut which would contradict that (ST) is 1-flip-optimal. Since each vertex of \(L_{p+1}\) has a neighbor in \(L_p\), each vertex of \(L_{p+1}\) is in S. \(\square \)

As a consequence, for each clause \(\phi _q\) of \(\Phi \), the vertex \(u^r_q\) is in T. Since (ST) is 1-flip-optimal in G, it holds that \(u^r_q\) has at least two neighbors in S: the single neighbor in \(L_{r-1}\) and at least one neighbor outside of \(L_{r-1}\). Recall that the neighbors of \(u^r_q\) outside of \(L_{r-1}\) are the vertices representing the literals of \(\phi _q\), that is, the vertex set \(\phi _q\). Since at least one neighbor of \(u^r_q\) outside of \(L_{r-1}\) is contained in S, there is some literal \(\ell \) of \(\phi _q\) such that the vertex \(\ell \) is in S. Thus, the literal \(\ell \) is in \(\tau _Z\) which implies that \(\tau _Z\) satisfies \(\phi _q\). Since this holds for each clauses \(\phi _q\) of \(\Phi \), \(\tau _Z\) satisfies \(\Phi \).

Thus, \({\exists }\)-LO-MC is \(\textrm{NP}\)-complete if \(k=1\) and \(\Delta =5\). Due to Proposition 17 and the fact that the (2, 3)-enforcer \(F^\exists \) contains both \(w^1_\exists \) and \(w^1_\forall \), we know that for every 1-flip-optimal cut (ST), \(w^1_\exists \) is in S if and only if \(w^1_\forall \) is in T. Hence, \(I'=(G,e_\exists ,1)\) is a no-instance of \({\exists }\)-LO-MC if and only if \(I''=(G,e_\forall ,1)\) is a yes-instance of \({\forall }\)-LO-MC, where \(e_\forall :=\{w^1_\forall , u^0_1\}\). Consequently, \({\forall }\)-LO-MC is \(\textrm{coNP}\)-complete if \(k=1\) and \(\Delta =5\).

4.2 Stronger Hardness Results for Unbounded Flip Size

We now show that for unbounded flip size, the problems are hard for the second level of the polynomial hierarchy.

Theorem 20

 \({\forall }\)-LO-MC is \(\Pi ^{\text {P}}_{2}\)-complete and \({\exists }\)-LO-MC is \(\Sigma ^{\text {P}}_{2}\)-complete even if \(\Delta = 3\).

Proof

It is a known fact that the decision problem that asks if a given cut (ST) is a k-flip-optimal cut in a graph G is contained in \(\textrm{coNP}\). Hence, there is a nondeterministic Turing machine which guesses a cut (ST) with \(e_\exists \in E(S,T)\) (\(e_\forall \not \in E(S,T)\), respectively) and afterwards uses the \(\textrm{coNP}\)-algorithm to check if (ST) is a k-flip-optimal cut in G. Consequently, both \({\exists }\)-LO-MC and the complement problem of \({\forall }\)-LO-MC are contained in \(\Sigma ^{\text {P}}_{2}\) and, therefore, \({\forall }\)-LO-MC is contained in \(\Pi ^{\text {P}}_{2}\).

To show the hardness result, we reduce the \(\Pi ^{\text {P}}_{2}\)-complete \({\forall \exists }\)-NAE-SAT problem to \({\forall }\)-LO-MC.

\({\forall \exists }\)-NAE-SATInput: Two disjoint sets of variables X and Y and a set of CNF-clauses \(\Phi \) over the variables \(Z:= X \cup Y\). Question: Is there for each assignment \(\tau _X\) of X an assignment \(\tau _Y\) of Y, such that \(\tau _X \cup \tau _Y\) nae-satisfies \(\Phi \)?

Given an instance \(I=(X,Y,\Phi )\) of \({\forall \exists }\)-NAE-SAT, we compute in polynomial time an equivalent instance \(I_2\) of \({\forall }\)-LO-MC. We can assume without loss of generality that every clause has size 3 and contains at most one variable of X, every variable only occurs positively, every variable of Y occurs three times, and every variable of X occurs once since \({\forall \exists }\)-NAE-SAT remains \(\Pi ^{\text {P}}_{2}\)-complete in this case [17].

Before we start the construction of \(I_2\) we transform I into an equivalent instance \(I'=(X',Y',\Phi ')\) of \({\forall \exists }\)-NAE-SAT where for every assignment of \(X'\) there is an assignment of \(Y'\) such that all except one clause of \(\Phi '\) are not-all-equal satisfied. Let \(\psi = |\Phi |\) and let \(\Phi =\{\phi _i\mid 1 \le i \le \psi \}\). We set \(X':= X, Y':= Y \cup \{a_i,b_i,c_i,d_i\mid 1 \le i \le \psi \} \cup \{v_1, v_2\},\) and \(Z':= X' \cup Y'\). We start with an empty set \(\Phi '\) and add for every clause \(\phi _i = \{\ell _1, \ell _2, \ell _3\} \in \Phi \) six new clauses

$$\begin{aligned} \phi '_{6(i-1)+1}&:=\{\ell _1, \ell _2,a_i\},\\ \phi '_{6(i-1)+2}&:=\{\lnot a_i, \ell _3,b_i\},\\ \phi '_{6(i-1)+3}&:=\{\lnot b_i, v_1,v_2\},\\ \phi '_{6(i-1)+4}&:=\{\ell _1, \ell _2,c_i\},\\ \phi '_{6(i-1)+5}&:=\{\lnot c_i, \ell _3,d_i\}, \text { and}\\ \phi '_{6i}&:=\{\lnot d_i, \lnot v_1, \lnot v_2\}. \end{aligned}$$

If \(\phi _i\) contains a variable of X, then we let \(\ell _3\) be that variable. Furthermore, we add one additional clause \(\phi '_{6\psi + 1}:= \{v_1, \lnot v_2\}\) and set \(\psi ':= |\Phi '| = 6\psi + 1\). The idea for this transformation is the following.

Observation 21

For every assignment \(\tau _{X}\) of X there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X} \cup \tau _{Y'}\) nae-satisfies \(\Phi ' \setminus \{\{v_1, \lnot v_2\}\}\).

Claim 22

It holds that I is a yes-instance of \({\forall \exists }\)-NAE-SAT if and only if \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT.

Proof

\((\Rightarrow )\) Suppose that I is a yes-instance of \({\forall \exists }\)-NAE-SAT. Let \(\tau _{X}\) be an assignment of X. We show that there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X}\cup \tau _{Y'}\) nae-satisfies \(\Phi '\). Since I is a yes-instance of \({\forall \exists }\)-NAE-SAT, there is an assignment \(\tau _{Y}\) of Y such that \(\tau \) nae-satisfies \(\Phi \) where \(\tau := \tau _{X}\cup \tau _{Y}\). Recall that every clause in \(\Phi \) only contains positive literals. We set 

$$\begin{aligned} \tau _{Y'} = \tau _{Y} \cup \{v_1, v_2\} \cup \{b_i, \lnot d_i\mid i \in [1,\psi ]\} \cup \{a_i, c_i\mid \phi _i=\{\ell _1, \ell _2, \ell _3\}\in \Phi , \ell _3 \in \tau \}\\ \cup \{\lnot a_i, \lnot c_i\mid \phi _i=\{\ell _1, \ell _2, \ell _3\}\in \Phi , \ell _3 \notin \tau \}. \end{aligned}$$

Let \(\tau '=\tau _{X}\cup \tau _{Y'})\). Since \(\{v_1, v_2\}\cup \{b_i\mid i \in [1,\psi ]\} \subseteq \tau '\) and \(\{\lnot d_i\mid i \in [1,\psi ]\}\subseteq \tau '\), the assignment \(\tau '\) nae-satisfies the clause \(\{v_1, \lnot v_2\}\) and for each \(i\in [1, \psi ]\) the clauses \(\{\lnot b_i, v_1, v_2\}\) and \(\{\lnot d_i, \lnot v_1, \lnot v_2\}\). Further, since for every clause \(\phi _i=\{\ell _1, \ell _2, \ell _3\}\) of \(\Phi \), either all literals of \(\{\ell _3,a_i, c_i\}\) are in \(\tau '\) or all literals of \(\{\lnot \ell _3,\lnot a_i, \lnot c_i\}\) are in \( \tau '\), we obtain that \(\tau '\) nae-satisfies both clauses \(\{\lnot a_i, \ell _3, b_i\}\) and \(\{\lnot c_i, \ell _3, d_i\}\). By the fact that \(\tau \) nae-satisfies \(\phi _i\), \(\tau '\) nae-satisfies both \(\{\ell _1, \ell _2,a_i\}\) and \(\{\ell _1, \ell _2,c_i\}\). Consequently, \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT.

\((\Leftarrow )\) Suppose that \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT. Let \(\tau _{X}\) be an assignment of X. Since \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau '\) nae-satisfies \(\Phi '\) where \(\tau ' = \tau _{X} \cup \tau _{Y'}\). We set \(\tau _Y = \tau _{Y'} \cap \mathcal {L}(Y)\) and show that \(\tau _{X} \cup \tau _Y \) nae-satisfies \(\Phi \). Let \(\phi _i = \{\ell _1, \ell _2, \ell _3\}\). Since \(\tau '\) nae-satisfies \( \{v_1, \lnot v_2\}\), the assignment \(\tau '\) contains either the literals \(v_1\) and \(v_2\) or the literals \(\lnot v_1\) and \(\lnot v_2\). Further, since \(\tau '\) nae-satisfies both clauses \(\{\lnot b_i, v_1, v_2\}\) and \(\{\lnot d_i,\lnot v_1, \lnot v_2\}\), we obtain that either \(b_i\in \tau '\) or \(d_i\in \tau '\) for all \(i\in [1,\psi ]\). Due to symmetry, assume that \(\tau '\) contains both literals \(\ell _3\) and \(b_i\). Hence, \(\tau '\) contains the literal \(a_i\) since \(\tau ' \) nae-satisfies \(\{\lnot a_i, \ell _3, b_i\}\). Consequently, by the fact that \(\tau ' \) nae-satisfies \( \{\ell _1, \ell _2, a_i\}\) and \(\tau '\) contains the literals \(\ell _3\) and \( a_i\), we obtain that \(\tau _{X}\cup \tau _{Y} \) nae-satisfies \( \{\ell _1, \ell _2, \ell _3\} = \phi _i\). Thus, I is a yes-instance of \({\forall \exists }\)-NAE-SAT. \(\square \)

We denote with c(z) the occurrence number of variable \(z\in Z'\), that is, the number of clauses of \(\Phi '\) containing z or \(\lnot z\). By construction it holds that \(c(v_1):= c(v_2):= 2\psi + 1, c(y):= 6\) if \(y\in Y\), and \(c(z):= 2\) otherwise. Moreover, for every variable \(z\in Z'\) and every \(i\in [1, c(z)]\) we set \(\#(z, i):= j\) if z occurs in \(\phi '_j\) and z occurs in exactly \(i-1\) clauses in \(\{\phi '_r\mid 1 \le r < j\}\). Hence, \(\#(z, i)\) denotes the index of the clause in which the ith occurrence of z is contained.

Next, we describe how to construct the equivalent \({\forall }\)-LO-MC-instance \(I_2=(G=(V,E), e^1_\forall , k)\). We start with an empty graph and add for every clause \(\phi '_i = \{\ell _1, \ell _2, \ell _3\}\in \Phi ' \setminus \{\{v_1, \lnot v_2\}\}\) the set of vertices \(\Gamma _i:= \{\ell ^i_1, \ell ^i_2, \ell ^i_3\}\) and make \({\Gamma _i}\) a clique. Further, for a variable \(z\in Z'\) and one of its literals \(\ell \in \{z, \lnot z\}\) we denote with \(\Gamma (\ell ):= \{\ell ^{j}\mid j\in [1, \psi ' - 1], \ell \in \phi '_j\}\) the set of vertices representing the occurrences of \(\ell \). Analogously, we define \(\Gamma (L):= \bigcup _{\ell \in L}\Gamma (\ell )\) for all literal subsets \(L \subseteq \mathcal {L}(Z')\). Moreover, we define the vertex set \(W_z:= \Gamma (z) \cup \Gamma (\lnot z)\) for all variables \(z\in Z'\).

We add for each variable \(y \in Y\) a variable cycle of length 12, for each variable \(x \in X\) a variable cycle of length \(26\psi + 18|Y|\), for each variable \(z\in \{a_i,b_i,c_i,d_i\mid 1 \le i \le \psi \}\) a variable cycle of length 4, and for each variable \(z \in \{v_1, v_2\}\) a variable cycle of length \(4\psi + 4\). Further, we add for each variable \(z\in Z'\setminus \{v_1, v_2\}\) and each occurrence \(i\in [1,c(z)]\) of z the edge \(\{\top ^i_z, \lnot z^{\#(z,i)}\}\) if \(\lnot z \in \phi '_{\#(z,i)}\) and the edge \(\{\bot ^i_z, z^{\#(z,i)}\}\) otherwise. For each variable \(z\in \{v_1, v_2\}\) and each \(i\in [1, c(z) -1]\), we add the edge \(\{\top ^i_z, \lnot z^{\#(z,i)}\}\) if \(\lnot z \in \phi '_{\#(z,i)}\) and the edge \(\{\bot ^i_z, z^{\#(z,i)}\}\), otherwise. Note that there are no vertices and no edges to represent the clause \(\phi '_{\psi '} = \{v_1, \lnot v_2\}\) yet.

Fig. 6
figure 6

The cycles \(C^1_\forall \) and \(C^2_\forall \). The dashed edges denote the remaining vertices and edges of the variable cycles of \(v_1\) and \(v_2\)

To represent the clause \(\phi '_{\psi '}\), we connect the variable cycles for \(v_1\) and \(v_2\) as shown in Fig. 6, that is, we add the three edges \(e_\forall ^1:=\{\bot ^{2\psi +1}_{v_1}, \top ^{2\psi +2}_{v_2}\}, e_\forall ^2:=\{\top ^{2\psi +2}_{v_1}, \bot ^{2\psi +1}_{v_2}\},\) and \(e_\exists :=\{\top ^{2\psi +1}_{v_1}, \top ^{2\psi +1}_{v_2}\}\). The edges \(e_\forall ^2\) and \(e_\exists \) are only added to later show the \(\Sigma ^{\text {P}}_{2}\)-completeness of \({\exists }\)-LO-MC. Note that there are two cycles of length 5 containing the edge \(e_\exists \):

$$\begin{aligned} C^1_\forall := \{\bot ^{2\psi +1}_{v_1},\top ^{2\psi +1}_{v_1},\top ^{2\psi +1}_{v_2},\bot ^{2\psi +2}_{v_2},\top ^{2\psi +2}_{v_2}\}&\text { and} \\ C^2_\forall := \{\bot ^{2\psi +1}_{v_2},\top ^{2\psi +1}_{v_2},\top ^{2\psi +1}_{v_1},\bot ^{2\psi +2}_{v_1},\top ^{2\psi +2}_{v_1}\}&. \end{aligned}$$

Finally, we set \(k = 30\psi + 18|Y| + 4\), that is, the sum of the length of a variable cycle of some variable \(x\in X\) and the length of the variable cycle of \(v_1\). Before we show the equivalence between \(I'\) and \(I_2\), we first give an upper bound \(k^*\) on the size of every cut in G. Moreover, we show that if a cut (ST) in G has size equal to this upper bound, then S encodes an assignment of Z which nae-satisfies \(\Phi '\).

Claim 23

Let \(k^*:= |E| - 6\psi - 1\). There is no cut (ST) in G with \(|E(S,T)| > k^*\). Moreover, for every cut (ST) in G with \(|E(S,T)| = k^*\), there is an assignment \(\tau _{Z'}\) of \(Z'\) such that \(S = C(\tau _{Z'}) \cup \Gamma (\tau _{Z'})\) and \(\tau _{Z'}\) nae-satisfies \(\Phi '\).

Proof

By construction, all the vertex sets \(\Gamma _i, i \in [1, 6\psi ]\) and \(C^1_\forall \) induce cycles of odd length which are pairwise edge disjoint. Due to Observation 15, it follows that \(|E(S,T)| \le |E| - 6\psi - 1 = k^*\). Further, the vertices of \(C^1_\forall \) also induce a cycle of odd length which only shares the edge \(e_\exists \) with the induced cycle of by the vertices of \(C^2_\forall \). Consequently, if \(|E(S,T)| = k^*\), then the edge \(e_\exists \) is not in E(ST) and both edges \(e^1_\forall \) and \(e^2_\forall \) are in E(ST). Moreover, all edges of \(\bigcup _{z\in Z'}E(N[V_z])\setminus \{e_\exists \}\) are in E(ST). As a consequence, for each variable \(z\in Z'\) it holds that \(C(z)\cup \Gamma (z)\) and \(C(\lnot z)\cup \Gamma (\lnot z)\}\) are in opposite parts of the cut and, thus, there is an assignment \(\tau \) of \(Z'\) such that \(S = C(\tau ) \cup \Gamma (\tau )\). It remains to show that \(\tau \) nae-satisfies all clauses of \(\Phi '\). Suppose that \(|E(S,T)| = k^*\). Hence, for each \(i\in [1,6\psi ]\), two edges of \(E(\Gamma _i)\) are in E(ST) and therefore \(\Gamma _i\) contains at least one vertex of S and at least one vertex of T. As a consequence, \(\tau \) nae-satisfies \( \phi '_i\) for all \(i\in [1,6\psi ]\) which implies that \(\tau \) nae-satisfies all clauses of \(\Phi '\setminus \{\{v_1, \lnot v_2\}\}\). Since \(e_\exists \) is not in E(ST), the vertices of \(C(v_1) \cup C(v_2)\) and the vertices of \( C(\lnot v_1) \cup C(\lnot v_2)\) are in opposite parts of the cut. Hence, \(\tau \) contains either both literals \(v_1\) and \(v_2\) or both literals \(\lnot v_1\) and \(\lnot v_2\) which implies that \(\tau \) nae-satisfies also the clause \(\{v_1, \lnot v_2\}\). \(\square \)

Next, we show that \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT if and only if \(I_2\) is a yes-instance of \({\forall }\)-LO-MC.

\((\Rightarrow )\) Before we show that \(I_2\) is a yes-instance of \({\forall }\)-LO-MC if \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT, we first analyze the structure of k-flip-optimal cuts in G in which \(e^1_\forall \) is not contained.

Observation 24

Let (ST) be a cut in G and let z be a variable of \(Z'\) such that C(z) and \(C(\lnot z)\) are not in opposite parts of the cut. At least two edges of \(E_z\) are not contained in E(ST).

Claim 25

Let (ST) be a k-flip-optimal cut in G with \(e_\forall ^1\not \in E(S,T)\). For each variable \(x \in X \cup \{v_1, v_2\}\), the vertices of \(C(x)\cup \Gamma (x)\) and the vertices of \(C(\lnot x)\cup \Gamma (\lnot x)\) are in opposite parts of the cut.

Proof

Assume towards a contradiction, that there is some variable \(x \in X \cup \{v_1, v_2\}\) such that \(C(x)\cup \Gamma (x)\) and \(C(\lnot x)\cup \Gamma (\lnot x)\) are not in opposite parts of the cut.

Case 1: \(V_{v_1}\cap S \not \in \{ C(v_1), C(\lnot v_1)\}\). Let 

$$\begin{aligned} V^*:= N[V_{v_1}\cup V_{v_2}] = V_{v_1}\cup V_{v_2} \cup W_{v_1}\cup W_{v_2}. \end{aligned}$$

Since \(e_\forall ^1\) is not in E(ST) and \(V_{v_1}\cap S\) is neither \(C(v_1)\) nor \(C(\lnot v_1)\}\), at least three edges of \(E(V^*)\) are not contained in E(ST), due to Observation 24. We set 

$$\begin{aligned} S':= (S \setminus V^*) \cup C(v_1) \cup C(\lnot v_2) \cup \Gamma (v_1) \cup \Gamma (\lnot v_2) \text { and~} T':= V \setminus S'. \end{aligned}$$

Since \(|S \oplus S'| \le |V^*| = 2(4\psi +4) + 4\psi \le k\) it remains to show that E(ST) is smaller than \(E(S',T')\). By construction, all edges of \(E(V^*)\) except for \(e^1_\forall \) and \(e^2_\forall \) are in \(E(S',T')\). Moreover, for each \(j\in [1, 2\psi ]\)\(E(S',T')\) contains two edges of \(E(\Gamma _{3j})\) which is at least the number of edges of \(E(\Gamma _{3j})\) in E(ST). Consequently, \(E(S',T')\) misses only \(2\psi + |\{e^1_\forall ,e^2_\forall \}| = 2\psi + 2\) edges of \(E(N[V^*])\), whereas E(ST) misses at least \(2\psi + 3\) edges of \(E(N[V^*])\). Since E(ST) and \(E(S',T')\) agree on all edges of \(E\setminus E(N[V^*])\), (ST) is not a k-flip-optimal cut in G, a contradiction.

Case 2: \(V_{v_2}\cap S \not \in \{ C(v_2), C(\lnot v_2)\}\). This case is analogous to Case 1.

Thus, we can assume in the following cases that \(C(v_i)\) and \(C(\lnot v_i)\) are in opposite parts of the cut for all \(i\in \{1,2\}\). Moreover, since the edge \(e^1_\forall \) is not in E(ST), we can assume without loss of generality, that \(V_{v_1}\cap S = C(v_1)\) and \(V_{v_2}\cap S = C(\lnot v_2)\).

Case 3: \((W_{v_1}\cup W_{v_2}) \cap S \ne \Gamma (v_1) \cup \Gamma (\lnot v_2)\). Thus, not all edges between the vertices of \(V_{v_1}\cup V_{v_2}\) and the vertices of \(W_{v_1}\cup W_{v_2}\) are in E(ST). We set 

$$S' = S \setminus (W_{v_1}\cup W_{v_2}) \cup \Gamma (v_1) \cup \Gamma (\lnot v_2)\text { and~}T' = V \setminus S'.$$

Hence, S and \(S'\) have symmetric difference at most k. It remains to show that \(E(S',T')\) is larger than E(ST). By construction of \((S',T')\) it follows that \(E(S',T')\) contains all edges of \(E(W_{v_1}\cup W_{v_2})\) and all edges of \(E(W_{v_1}\cup W_{v_2}, V_{v_1}\cup V_{v_2})\). Furthermore, for each \(j\in [1,2\psi ]\)\(S'\) contains at least one vertex of \(\Gamma _{3j}\) and \(T'\) contains at least one vertex of \(\Gamma _{3j}\). Hence, for each \(j\in [1, 2\psi ]\)\(E(S',T')\) contains two edges of \(E(\Gamma _{3j})\) which is at least the number of edges of \(E(\Gamma _{3j})\) in E(ST). Consequently, \(E(S',T')\) misses only \(2\psi \) edges of \(E(N[W_{v_1}\cup W_{v_2}])\), whereas E(ST) misses more edges of \(E(N[W_{v_1}\cup W_{v_2}])\). Since E(ST) and \(E(S',T')\) agree on all edges of \(E\setminus E(N[W_{v_1}\cup W_{v_2}])\), (ST) is not k-flip-optimal in G, a contradiction.

Case 4: There is a variable x of X such that \(C(x)\cup \Gamma (x)\) and \(C(\lnot x)\cup \Gamma (\lnot x)\) are not in. Thus, at least one edge of \(E(V_x\cup W_x)\) is not contained in E(ST). Since there is a unique clause \(\phi _i\) of \(\Phi \) that contains x it follows by construction of \(I'\) that x is contained in the two clauses \(\phi '_{6(i-1) + 2}\) and \(\phi '_{6(i-1) + 5}\) of \(\Phi '\). Note that these are the only two clauses of \(\Phi '\) containing x and there is no clause of \(\Phi '\) that contains \(\lnot x\). Let \(\tau = \{x, \lnot b_i, \lnot d_i\}\) and \(\mathcal {W} = \bigcup _{z \in \{x,b_i,d_i\}}(V_z \cup W_z)\). We set 

$$S' = (S \setminus \mathcal {W}) \cup C(\tau ) \cup \Gamma (\tau ) \text {~and~} T' = V \setminus S'.$$

Since \(S\oplus S' \subseteq \mathcal {W}\) and \(|\mathcal {W}|\le 26\psi + 18|Y| + 2 + 2(4 + 2) < k\)E(ST) is smaller than \(E(S',T')\).

Since E(ST) and \(E(S',T')\) agree on all edges of \(E\setminus E(N[\mathcal {W}])\), it remains to show that \(E(S,T) \cap E(N[\mathcal {W}])\) is smaller than \(E(S',T') \cap E(N[\mathcal {W}])\). Note that \(N[\mathcal {W}]\) consists of the vertices of the variable cycles for \(x,b_i\), and \(d_i\) and the vertices representing the literals of the clauses \(\phi '_{6(i-1) + 2}, \phi '_{6(i-1) + 3}, \phi '_{6(i-1) + 5}\) and \(\phi '_{6i}\), that is, 

$$N[\mathcal {W}] = V_x \cup V_{b_i}\cup V_{d_i} \cup \Gamma _{6(i-1) + 2}\cup \Gamma _{6(i-1) + 3}\cup \Gamma _{6(i-1) + 5}\cup \Gamma _{6i}.$$

By construction, for each \(z \in \{x, b_i, d_i\}\), all edges of \(E(V_z\cup W_z)\) are in \(E(S',T')\). Recall that \(V_{v_1}\cap S = C(v_1)\) and \(V_{v_2}\cap S = C(\lnot v_2)\) which implies \(V_{v_1}\cap S' = C(v_1)\) and \(V_{v_2}\cap S' = C(\lnot v_2)\). Let \(\tau _2 = \tau \cup \{v_1, \lnot v_2\}\). Since \(\tau _2\) nae-satisfies all clauses of \(\{\phi '_{6(i-1) + 2}, \phi '_{6(i-1) + 3}, \phi '_{6(i-1) + 5},\phi '_{6i}\}\)\(E(S',T')\) contains two edges of \(E(\Gamma _{j})\) which is at least the number of edges of \(E(\Gamma _{j})\) in E(ST) for each \(j\in \{6(i-1) + 2,6(i-1) + 3,6(i-1) + 5,6i\}\). Consequently, \(E(S',T')\) misses only 4 edges of \(E(N[\mathcal {W}])\), whereas E(ST) misses more edges of \(E(N[\mathcal {W}])\). Since E(ST) and \(E(S',T')\) agree on all edges of \(E\setminus E(N[\mathcal {W}])\), (ST) is not k-flip-optimal in G, a contradiction. \(\square \)

Suppose that \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT. We show that any cut (ST) in G with \(e^1_\forall \in E(S,T)\) is not k-flip-optimal. Assume towards a contradiction that there is a k-flip-optimal cut (ST) in G where \(e^1_\forall \) is not in E(ST). By Claim 25, there is an assignment \(\tau _X\) of X such that \(S\cap \bigcup _{z\in X}(V_z\cup W_z) = C(\tau _X) \cup \Gamma (\tau _X)\). Moreover, due to Claim 25, we can assume without loss of generality that \(S\cap (V_{v_1}\cup W_{v_1}\cup V_{v_2}\cup W_{v_2}) = C(v_1) \cup \Gamma (v_1) \cup C(\lnot v_2) \cup \Gamma (\lnot v_2)\) since \(e^1_\forall \) is not in E(ST). Let \(\tau := \tau _X \cup \tau _{Y'}\). Since \(I'\) is a yes-instance of \({\forall \exists }\)-NAE-SAT, there is some assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X} \cup \tau _{Y'}\) nae-satisfies \(\Phi '\). We set 

$$S' = (S \cap \bigcup _{x\in X}(V_x\cup W_x))\cup C(\tau _{Y'}) \cup \Gamma (\tau _{Y'}) = C(\tau ) \cup \Gamma (\tau )\text { and~}T' = V \setminus S'.$$

By construction, \(S\oplus S'\) is a subset of \(\bigcup _{y\in Y'} (V_y \cup W_y)\). Since \(\tau \) nae-satisfies the clause \(\{v_1, \lnot v_2\}\)\(\tau \) contains either both literals \(v_1\) and \(v_2\) or both literals \(\lnot v_1\) and \(\lnot v_2\). Thus, \((S\oplus S')\cap (V_{v_i} \cup W_{v_i}) = \emptyset \) for exactly one \(i\in \{1,2\}\). Hence, the symmetric difference between S and \(S'\) has size at most 

$$|V_{v_1} \cup W_{v_1}| + (12+6)|Y| + (4+2)4\psi = 4\psi + 4 + 2\psi + 18|Y| + 24\psi = k.$$

By construction, for each variable z of \(Z'\), all edges of \(E(V_z\cup W_z)\) are in \(E(S',T')\) and both edges \(e^1_\forall \) and \(e^2_\forall \) are in \(E(S',T')\). Moreover, since for each \(i\in [1, 6\psi ]\)\(\tau \) nae-satisfies the clause \(\phi _i\)\(\Gamma _i\) contains at least one vertex of \(S'\) and at least one vertex of \(T'\). Hence, two of the edges of \(E(\Gamma _i)\) are contained in \(E(S',T')\) for each \(i\in [1, 6\psi ]\). As a consequence, \(E(S',T')\) contains \(k^*\) edges. Since \(e^1_\forall \) is not in E(ST) we know due to Claim 23 that \(|E(S,T)| < k^* = |E(S',T')|\). This contradicts the fact that (ST) is k-flip-optimal in G. Consequently, \(I_2\) is a yes-instance of \({\forall }\)-LO-MC.

\((\Leftarrow )\) We show the statement by contraposition. Suppose that \(I'\) is a no-instance of \({\forall \exists }\)-NAE-SAT, we show that there is a k-flip-optimal cut (ST) in G such that \(e^1_\forall \) is not in E(ST). Since \(I'\) is a no-instance of \({\forall \exists }\)-NAE-SAT, there is an assignment \(\tau _{X}\) of X such that for each assignment \(\tau _{Y'}\) of \(Y'\), not all clauses of \(\Phi '\) are nae-satisfied by \(\tau _{X} \cup \tau _{Y'}\). By Observation 21, there is an assignment \(\tau _{Y'}\) of \(Y'\) such that \(\tau _{X} \cup \tau _{Y'}\) nae-satisfies all clauses of \(\Phi '\) except for the clause \(\{v_1, \lnot v_2\}\). Let \(\tau = \tau _{X} \cup \tau _{Y'}\). We set

$$S:= C(\tau ) \cup \Gamma (\tau )\text { and~}T := V \setminus S$$

and show that (ST) is a k-flip-optimal cut in G. By construction, for each variable \(z\in Z'\)E(ST) contains all edges of \(E(N[V_z])\setminus \{e_\forall ^1, e_\forall ^2\}\subseteq E(S,T)\). Moreover, since \(\tau \) nae-satisfies all clauses of \(\Phi '\setminus \{\{v_1, \lnot v_2\}\})\), for each \(i\in [1,6\psi ]\)\(\Gamma _i\) contains at least one vertex of S and at least one vertex of T. Hence, for each \(i\in [1,6\psi ]\)E(ST) contains two edges of \(E(\Gamma _i)\) which implies that \(|E(S,T)| = k^*-1\).

Assume towards a contradiction, that (ST) is not a k-flip-optimal cut in G. Hence, there is a cut \((S',T')\) in G with \(|S\oplus S'| \le k\) such that \(E(S',T')\) contains more than \( k^* - 1 = |E(S,T)|\) edges. Due to Claim 23, there is an assignment \(\tau _2\) of \(Z'\) such that \(S = C(\tau _2) \cup \Gamma (\tau _2)\) and \(\tau _2\) nae-satisfies \(\Phi '\). Recall that for each assignment \(\tau _{Y_2}\) of \(Y'\), at least one clause of \(\Phi '\) is not nae-satisfied by \(\tau _X \cup \tau _{Y_2}\). Hence, \(\tau _2\) does not contain all literals of \(\tau _{X}\). Thus, for each variable \(x\in (\tau _2 \oplus \tau _{X})\cap X\), all vertices of \(N[V_x]\) are in \(S\oplus S'\).

Further, since \(\tau _2\) nae-satisfies the clause \(\{v_1, \lnot v_2\}\)\(\tau _2\) contains either both literals \(v_1\) and \(v_2\) or both literals \(\lnot v_1\) and \(\lnot v_2\). Hence, \(C(v_1)\cup C(v_2)\) and \(C(\lnot v_1)\cup C(\lnot v_2)\) are in opposite parts of the cut \((S', T')\). Thus, either all vertices of \(V_{v_1}\) are in \(S\oplus S'\) or all vertices of \(V_{v_2}\) are in \(S\oplus S'\). Consequently, 

$$|S\oplus S'| \ge |V_{v_1}| + |N[V_x]| = 4\psi + 4 + 26\psi + 18|Y| + 2 = k + 2,$$

a contradiction. Hence, (ST) is a k-flip-optimal cut in G such that \(e_\forall ^1\) is not in E(ST) which implies that \(I_2\) is a no-instance of \({\forall }\)-LO-MC.

Thus, \({\forall }\)-LO-MC is \(\Pi ^{\text {P}}_{2}\)-complete even on graphs with maximum degree 3. Further, since for every k-flip-optimal cut (ST) in G it holds that either \(e^1_\forall \) is in E(ST) or \(e_\exists \) is in E(ST), \(I_3=(G,e_\exists , k)\) is a yes-instance of \({\exists }\)-LO-MC if and only if \(I_2\) is a no-instance of \({\forall }\)-LO-MC. Consequently, \({\exists }\)-LO-MC is \(\Sigma ^{\text {P}}_{2}\)-complete even on graphs with maximum degree 3.

Fig. 7
figure 7

The three possible kinds of minimal improving (1, k)-swaps: appending an edge to one of the endpoints, removing one endpoint and appending a path of length two to its neighbor in the path, or replacing an edge \(\{u,v\}\) with an (uv)-path of length at most k

5 Longest Path

Finally, we consider Longest Path which is NP-hard even on cubic graphs [18]. Here, one wants to know for a given graph G and an integer r, whether G contains a path of length at least r. Again, we want to find out whether some small part of the graph is contained in a locally optimal solution. We consider the following neighborhood.

Definition 2

Let k be an integer with \(k \ge 2\). Two paths \(P_1\) and \(P_2\) are (1, k)-swap neighbors, if

  1. 1.

    the lengths of \(P_1\) and \(P_2\) are distinct,

  2. 2.

    the relative ordering of the common vertices of \(P_1\) and \(P_2\) is equal in both paths, and

  3. 3.

     \(|E(P_1) \setminus E(P_2)| \le k\) and \(|E(P_2) \setminus E(P_1)| \le 1\) or vice versa.

Intuitively, if we can obtain a path \(P_2\) from a path \(P_1\) by removing any edge \(\{u,v\}\) from \(P_1\) and replacing it by a (uv)-path of length at most k, then \(P_1\) and \(P_2\) are (1, k)-swap neighbors.

There are three different kinds of minimal improving (1, k)-swaps. All of them are shown in Fig. 7.

Let \(s,s',t',t\) be (not necessarily distinct) vertices and let P be an (st) path containing the edges \(\{s,s'\}\) and \(\{t',t\}\). By definition, P is (1, k)-swap-optimal in G for \(k\ge 2\) if and only if:

  1. 1.

    P has length one and G contains no path of length at least two or,

  2. 2.
    1. 1.

      P contains all neighbors of s and all neighbors of t,

    2. 2.

      for each vertex \(x\in \{s',t'\}\)P contains at least a second vertex besides x of every path of length two starting in x, and

    3. 3.

      for each edge \(\{x,y\}\) of E(P), P contains at least a third vertex besides x and y of every (xy)-path of length at least two and at most k.

Some Locally Optimal Path (\({\exists }\)-LO-Path) Input: An undirected graph \(G=(V,E)\), an edge \(e^*\in E\), and \(k\in \mathbb {N}\). Question: Is \(e^*\) contained in some (1, k)-swap-optimal path \(P^*\) in G?

First, we observe that, unfortunately, the problem is hard already for fixed k. This holds even on graphs with an h-index of 5. Here, the h-index of a graph G is the largest integer h, such that G contains at least h vertices of degree at least h [19].

Theorem 26

\({\exists }\)-LO-Path is \(\textrm{NP}\)-complete for every fixed \(k\ge 2\) on graphs with an h-index of 5.

Proof

First, we show the containment in \(\textrm{NP}\). Let P be a path in G that contains the edge \(e^*\). Since there are at most \(\mathcal {O}(n\cdot \Delta ^k \cdot k)\) many possible improving (1, k)-swaps for a given path P, one can check in polynomial time for every fixed value of k if P is (1, k)-swap-optimal. Consequently, Some Locally Optimal Path is contained in \(\textrm{NP}\), since an \(\textrm{NP}\)-algorithm may nondeterministically choose a path P that contains the edge \(e^*\) and afterwards check in polynomial time, if P is (1, k)-swap-optimal.

Next, we show the \(\textrm{NP}\)-hardness. We reduce from Hamiltonian Path which is \(\textrm{NP}\)-complete even on subcubic graphs.

Hamiltonian Path Input: Given an undirected graph \(G=(V,E)\). Question: Does G contain a Hamiltonian path, that is, a path that contains every vertex of V exactly once?

Given an instance \(I = (G = (V,E))\) of Hamiltonian Path where G is subcubic, we construct an instance \(I'=(G'=(V', E'), e^*, 2)\) of Some Locally Optimal Path where \(G'\) has an h-index of 5 in polynomial time as follows. We obtain \(G'\) by adding three new vertices \(v^*, w^*\), and z to G and by adding edges such that \(v^*\) and \(w^*\) are adjacent to all vertices of \(G'\) (including z). Note that \(G'\) has an h-index of 5, since z is only adjacent to \(v^*\) and \(w^*\) and each vertex of V has at most three neighbors in V. Finally, we set \(e^*:= \{v^*, w^*\}\) and show that I is a yes-instance of Hamiltonian Path if and only if \(I'\) is a yes-instance of Some Locally Optimal Path.

\((\Rightarrow )\) Let P be a Hamiltonian path in G and let \(P^*\) be the path obtained by appending the path \((v^*, w^*, z)\) to P. By construction, \(P^*\) is a Hamiltonian path in \(G'\) containing the edge \(e^*\). Hence, \(P^*\) is (1, 2)-swap-optimal in \(G'\) and, thus, \(I'\) is a yes-instance of Some Locally Optimal Path.

\((\Leftarrow )\) Let \(P^*\) be a (1, 2)-swap-optimal path in \(G'\) containing the edge \(e^*\). Recall that each vertex u of \(V \cup \{z\}\) is adjacent to both \(u^*\) and \(v^*\). Since for each vertex u of \(V \cup \{z\}\), removing \(e^*\) and adding the edges \(\{v^*, u\}\) and \(\{u, w^*\}\) is not a valid (1, 2)-swap,   contains the vertex u. Hence, \(P^*\) contains all vertices of \(V \cup \{z\}\). Consequently, since \(P^*\) contains the edge \(e^*\)\(P^*\) is a Hamiltonian path in \(G'\). Since there is no edge between z and any vertex of V, we obtain that z is one endpoint of \(P^*\) and \( P^*\) contains either the edge \(\{z,v^*\}\) or the edge \(\{z,w^*\}\). Moreover, since the edge \(e^*\) is in \(P^*\)\(P^*\) contains the subpath \((v^*, w^*, z)\) or the subpath \((w^*, v^*, z)\). Consequently, there must be a path P in \(G'\) such that \(P^*\) can be obtained by appending either \((v^*, w^*, z)\) or \((w^*, v^*, z)\) to P. Recall that \(P^*\) is a Hamiltonian path in \(G'\) which implies that P contains all vertices of V. Since \(E'\setminus E\) contains no edges between vertices of V, we obtain that P is a Hamiltonian path in G.

In contrast, we show that on bounded-degree graphs, we can obtain an efficient algorithm for small values of k. Our algorithm is based on a sufficient and necessary condition for the existence of a (1, k)-swap-optimal path in G containing a specific edge. To formulate the condition, we define two collections of vertex sets. We denote for each integer k and each pair of distinct vertices v and w of V by 

$$ \mathcal {V}_k(v,w):= \{V(P) \setminus \{v,w\} \mid P~\text {is a}\ (v,w)\text {-path with}\ 2 < |V(P)| \le k+1 \} $$

the collection of sets of inner vertices of (vw)-paths with length at most k. Moreover, for each vertex v of V, we denote by 

$$ \mathcal {V}_2(v):= \{\{x,y\} \mid x,y\in V,~(v,x,y)~\text {is a path in}~G \} $$

the collection of subsets \(\widetilde{V}\) of \(V \setminus \{v\}\), such that G contains a path P of length 2 starting in v with \(V(P) = \widetilde{V} \cup \{v\}\). See Fig. 8 for an illustration of the defined collections of vertex sets.

Fig. 8
figure 8

An illustration of the defined vertex sets. For the depicted (st)-path that contains the edge \(e^*:= \{v^*,w^*\}\)\(\{x,y\}\) is a vertex set of the collection \(\mathcal {V}_k(v^*,w^*)\) and \(\{a,b\}\) is a vertex set of the collection \(\mathcal {V}_2(t')\)

Lemma 27

Let \(e^*=\{v^*,w^*\}\) be an edge which is not isolated and let \(k\ge 2\). There is a (1, k)-swap-optimal path \(P^*\) containing \(e^*\) if and only if there are (not necessarily distinct) vertices \(s,s',t'\) and t such that there is an (st)-path P in G

  • containing the edges \(e^*, \{s,s'\},\) and \(\{t', t\},\)

  • containing the vertices of \(N(s) \cup N(t)\), and

  • where V(P) is a hitting set for \(\mathcal {V}_k(s,s') \cup \mathcal {V}_2(s') \cup \mathcal {V}_k(v^*,w^*) \cup \mathcal {V}_2(t') \cup \mathcal {V}_k(t',t)\).

Proof

\((\Rightarrow )\) Let \(P^*\) be a (1, k)-swap-optimal path containing \(e^*\). Then, \(V(P^*)\) contains at least two vertices and, thus, there are (not necessarily distinct) vertices \(s,s',t',t\in V\) such that \(P^*\) contains the edges \(e^*, \{s,s'\},\) and \(\{t', t\}\). Moreover, \(P^*\) contains \(N(s) \cup N(t)\) as, otherwise, \(P^*\) is not (1, k)-swap-optimal. Assume towards a contradiction, that the set of vertices of \(P^*\) is not a hitting set for \(\mathcal {V}_k(s,s') \cup \mathcal {V}_2(s') \cup \mathcal {V}_k(v^*,w^*) \cup \mathcal {V}_2(t') \cup \mathcal {V}_r(t',t)\).

Case 1: \(V(P^*)\) is not a hitting set for \(\mathcal {V}_k(x,y)\) for some \(\{x,y\}\in \{\{s,s'\}, \{v^*,w^*\},\) \( \{t', t\}\}\). Then, there is some \(\widetilde{V} \in \mathcal {V}_k(x,y)\) such that there is some (xy)-path \(P'\) in G of length at most k and \(V(P') = \widetilde{V} \cup \{x,y\}\), such that \(V(P') \cap V(P^*) = \{x,y\}\). Replacing the edge \(\{x,y\}\) by the (xy)-path \(P'\) is an improving (1, k)-swap, since \(\widetilde{V} \ne \emptyset \). This contradicts the fact that \(P^*\) is (1, k)-swap-optimal in G.

Case 2: \(V(P^*)\) is not a hitting set for \(\mathcal {V}_2(x)\) for some \(x\in \{s',t'\}\). Then, there is some \(\widetilde{V} \in \mathcal {V}_2(x)\) such that there is some path \(P'\) of length 2 in G starting in x with \(V(P') = \widetilde{V} \cup \{x\}\) and \(V(P') \cap V(P^*) = \{x\}\). Hence, replacing the edge \(\{x,x'\}\) by the path \(P'\) is an improving (1, k)-swap, since \(P'\) contains two edges. This contradicts the fact that \(P^*\) is (1, k)-swap-optimal in G.

\((\Leftarrow )\) Suppose that there are vertices \(s,s',t',t\in V\) such that there is an (st)-path P in G containing the edges \(e^*, \{s,s'\}, \{t', t\},\) the vertices \(N(s) \cup N(t)\), and where V(P) is a hitting set for \(\mathcal {V}_k(s,s') \cup \mathcal {V}_2(s') \cup \mathcal {V}_k(v^*,w^*) \cup \mathcal {V}_2(t') \cup \mathcal {V}_k(t',t)\).

Since P contains 1) at least one inner vertex of every \((s, s')\)-path in G of length at least two and at most k, and 2) at least one inner vertex besides \(s'\) of every path of length two starting in \(s'\), there is no improving (1, k)-swap that removes \(\{s,s'\}\) from P. This also holds for the edge \(\{t',t\}\). Since V(P) is a hitting set for \(\mathcal {V}_k(v^*,w^*)\)P contains at least one inner vertex of every \((v^*, w^*)\)-path in G of length at least 2 and at most k.

In the following, we will show, that every path \(P^*\) which can be reached by an arbitrary number of improving (1, k)-swaps, also fulfills all properties of P. This implies that there is a (1, k)-swap-optimal path \(P^*\) in G containing \(e^*\).

Since \(e^*\) is not an isolated edge and P contains the vertices \(N(s) \cup N(t)\), and the edges \(e^*, \{s,s'\}, \{t', t\},\) we obtain that P contains at least three vertices. Hence, not all edges of P can be removed by a single improving (1, k)-swap. Note that an improving (1, k)-swap can only remove a vertex from the path if this vertex is one of the endpoints of the path.

By the above, none of the edges \(e^*, \{s,s'\}, \) or \(\{t', t\}\) can be removed by an improving (1, k)-swap. Hence, for every improving (1, k)-swap neighbor \(P'\) of P it holds that \(V(P) \subseteq V(P')\), \(P'\) contains the edges \(e^*, \{s,s'\},\) and \( \{t', t\}\). Moreover, since all vertices of \(N(s) \cup N(t)\) are in P, we obtain that \(P'\) is also an (st)-path. Consequently, one can show via induction, that for every path \(P^*\) which can be reached by an arbitrary number of improving (1, k)-swap starting from P, that \(P^*\) is an (st)-path containing the edges \(e^*, \{s,s'\},\) and \(\{t', t\},\) the vertices \(N(s) \cup N(t)\), and \(V(P^*)\) is a hitting set for  \(\mathcal {V}_k(s,s') \cup \mathcal {V}_2(s') \cup \mathcal {V}_k(v^*,w^*) \cup \mathcal {V}_2(t') \cup \mathcal {V}_k(t',t)\) . \(\square \)

Theorem 28

\({\exists }\)-LO-Path can be solved in time \(f(\Delta + k)\cdot n^4\) for some computable function f.

Proof

Let \(I=(G=(V,E), e^*=\{v^*,w^*\}, k)\) be an instance of \({\exists }\)-LO-Path with \(k\ge 2\). First, if \(e^*\) is an isolated edge, then, there is exactly one path \(P^* = (v^*, w^*)\) in G that contains the edge \(e^*\). This path is (1, k)-swap-optimal in G if and only if G does not contain a path with two edges. Hence, to determine if I is a yes-instance of \({\exists }\)-LO-Path, we only have to check if G contains a path with two edges, which can be done in \(\mathcal {O}(n+m)\) time. Second, if \(e^*\) is not an isolated edge, then, due to Lemma 27, it is sufficient to check if there are (not necessarily distinct) vertices \(s,s',t',t\in V\) such that there is an (st)-path P in G containing the edges \(e^*, \{s,s'\},\) and \(\{t', t\},\) the vertices \(N(s) \cup N(t)\), and where V(P) is a hitting set for \(\mathcal {V}_k(s,s') \cup \mathcal {V}_2(s') \cup \mathcal {V}_k(v^*,w^*) \cup \mathcal {V}_2(t') \cup \mathcal {V}_k(t',t)\). In the following, we describe how we can check in \(f(\Delta + k)\cdot n^4\) time, whether such a path exists.

For every combination of vertices \(s\in V, s'\in N(s), t\in V,\) and \(t'\in N(t)\), we compute the collections \(\mathcal {V}_k(s,s'), \mathcal {V}_2(s'), \mathcal {V}_k(v^*,w^*), \mathcal {V}_2(t'),\) and \(\mathcal {V}_k(t',t)\). We set \(\mathcal {V}:= \mathcal {V}_k(s,s') \cup \mathcal {V}_2(s') \cup \mathcal {V}_k(v^*,w^*) \cup \mathcal {V}_k(t',t) \cup \mathcal {V}_2(t')\). Each of these collections contains at most \(\Delta ^{k-1}\) sets of size at most \(k-1\) and each can be computed in \(\mathcal {O}(\Delta ^k)\) time. Moreover, for each \(\{x,y\}\in \{\{s,s'\},\{v^*,w^*\},\{t,t'\}\}\), each set \(V'\) of \(\mathcal {V}_k(x,y)\) is a subset of \(N^{k/2}[x] \cup N^{k/2}[y]\), where \(N^{k/2}[u]\) denotes the set of vertices having distance at most k/2 to u. Hence, \(V^*:= \bigcup _{V' \in \mathcal {V}} V'\) is a subset of \(\bigcup _{x \in \{s,s',v^*, w^*, t',t\}} N^{k/2}[x] \cup N^{2}[s'] \cup N^{2}[t']\). Consequently, \(\lambda := |V^*|\in \mathcal {O}(\Delta ^{\max (k/2, 2)})\).

Next, we check for each \(V'\subseteq V^*\) if \(V'\) is a hitting set for \(\mathcal {V}\). If this is the case, we let \(\widetilde{V}:= V' \cup N(s) \cup N(t) \cup \{s,t,v^*,w^*\}\) and let \(\ell := |\widetilde{V}|\) and check if there is an (st)-path P in G containing the edges \(e^*, \{s, s'\},\) and \(\{t', t\}\) such that \(V' \cup N(s) \cup N(t) \subseteq V(P)\). This can be done by checking if there is an ordering \(\pi = (x_1, \dots , x_\ell )\) of the vertices of \(\widetilde{V}\) such that there are pairwise vertex-disjoint \((x_i, x_{i+1})\)-paths for all \(i\in [1, \ell -1]\) where \(x_1 = s, x_2 = s', x_{\ell -1} = t', x_\ell = t\), and \(v^*\) and \(w^*\) are consecutive in \(\pi \). This can be done in \(g(|\widetilde{V}|)\cdot n^2\) time [20] for some computable function g. Since we check all combinations of \(s,s',t',\) and t as well as every possible hitting set for \(\mathcal {V}\), the algorithm is correct and has overall running time \(\mathcal {O}(n^2 \cdot \Delta ^2 \cdot \lambda \cdot 2^{\lambda } \cdot (\lambda + 4 + 2\Delta )! \cdot g(\lambda + 4 + 2\Delta ) \cdot n^2) \subseteq \mathcal {O}(f(\Delta + k)\cdot n^4)\). \(\square \)

6 Conclusion

We proposed a generic approach to the design of data reduction rules via local optimality and examined its viability for well-known NP-hard problems. For Independent Set and Max Cut for the neighborhoods under consideration we obtained only negative results: determining whether a vertex or an edge, respectively, is contained in some locally optimal solution is hard. In contrast, we obtained a positive result for Longest Path on bounded-degree graphs, where one can determine whether an edge is in a locally optimal solution for a certain edge-swap neighborhood in a running time that is exponential only in the neighborhood radius k. Currently, this is a mere classification result; for an application within a data reduction setting, one would first need to find an algorithm with a better running time guarantee. Moreover, it is open whether the problem of deciding if a given edge is contained in every locally optimal path for our considered edge-swap neighborhood (see Definition 2 ) is \(\textrm{NP}\)-hard. It seems also interesting to find further positive examples. Natural candidates are problems that are related to Longest Path, for example the Longest Cycle problem. It would also be interesting to consider extensions of the (1, k)-swap neighborhood for Longest Path or different neighborhoods for Independent Set or Max Cut. Finally, regardless of the connection to data reduction, it seems interesting in its own right to study which properties of locally optimal solutions can be computed efficiently.