The classical theorem of Erdős and Gallai  says that
Theorem 1 (Erdős and Gallai ).
Every graph with vertices and more than edges () contains a cycle of length at least .
Recall that a graph is -degenerate if every subgraph of has a vertex of degree at most , that is, the minimum degree . Respectively, the degeneracy of graph , is Since a graph of degeneracy has a subgraph with at least edges, by Theorem 1, it contains a cycle of length at least . Let us note that the degeneracy of a graph can be computed in polynomial time, see e.g. , and thus by Theorem 1, deciding whether a graph has a cycle of length at least can be done in polynomial time. In this paper we revisit this classical result from the algorithmic perspective.
We define the following problem.
Let us first sketch why Longest Cycle Above Degeneracy is -complete for even for connected graphs. We can reduce Hamiltonian Cycle to Longest Cycle Above Degeneracy with as follows. For a connected non-complete graph on vertices, we construct connected graph from and a complete graph on vertices as follows. We identify one vertex of with one vertex of . Thus the obtained graph has vertices and is connected; its degeneracy is . Then has a cycle with vertices if and only if has a Hamiltonian cycle.
Interestingly, when the input graph is -connected, the problem becomes fixed-parameter tractable being parameterized by . Let us remind that a connected graph is (vertex) -connected if for every , is connected. Our first main result is the following theorem.
On -connected graphs Longest Cycle Above Degeneracy is solvable in time .
Similar results can be obtained for paths. Of course, if a graph contains a cycle of length , it also contains a simple path on vertices. Thus for every graph of degeneracy , deciding whether contains a path on vertices can be done in polynomial time. Again, it is a easy to show that it is -complete to decide whether contains a path with vertices by reduction from Hamiltonian Path. The reduction is very similar to the one we sketched for Longest Cycle Above Degeneracy. The only difference that this time graph consists of a disjoint union of and . The degeneracy of is , and has a path with vertices if and only if contains a Hamiltonian path. Note that graph used in the reduction is not connected. However, when the input graph is connected, the complexity of the problem change drastically. We define
The second main contribution of our paper is the following theorem.
On connected graphs Longest Path Above Degeneracy is solvable in time .
We also show that the parameterization lower bound that is used in Theorems 3 and 2 is tight in some sense. We prove that for any , it is -complete to decide whether a connected graph contains a path with at least vertices and it is -complete to decide whether a -connected graph contains a cycle with at least vertices.
Related work. Hamiltonian Path and Hamiltonian Cycle problems are among the oldest and most fundamental problems in Graph Theory. In parameterized complexity the following generalizations of these problems, Longest Path and Longest Cycle, we heavily studied. The Longest Path problem is to decide, for given an -vertex (di)graph and an integer , whether contains a path of length at least . Similarly, the Longest Cycle problem is to decide whether contains a cycle of length at least . There is a plethora of results about parameterized complexity (we refer to the book of Cygan at al.  for the introduction to the field) of Longest Path and Longest Cycle (see, e.g., [5, 6, 8, 7, 13, 15, 22, 23, 24, 33]) since the early work of Monien . The fastest known randomized algorithm for Longest Path on undirected graph is due to Björklund et al.  and runs in time . On the other hand very recently, Tsur gave the fastest known deterministic algorithm for the problem running in time . Respectively for Longest Cycle, the current fastest randomized algorithm runs in time was given by Zehavi in  and the best deterministic algorithm constructed by Fomin et al. in  runs in time .
Our theorems about Longest Path Above Degeneracy and Longest Cycle Above Degeneracy fits into an interesting trend in parameterized complexity called “above guarantee” parameterization. The general idea of this paradigm is that the natural parameterization of, say, a maximization problem by the solution size is not satisfactory if there is a lower bound for the solution size that is sufficiently large. For example, there always exists a satisfying assignment that satisfies half of the clauses or there is always a max-cut containing at least half the edges. Thus nontrivial solutions occur only for the values of the parameter that are above the lower bound. This indicates that for such cases, it is more natural to parameterize the problem by the difference of the solution size and the bound. The first paper about above guarantee parameterization was due to Mahajan and Raman  who applied this approach to the Max Sat and Max Cut problem. This approach was successfully applied to various problems, see e.g. [1, 9, 17, 18, 19, 20, 25, 27].
For Longest Path, the only successful above guarantee parameterization known prior to our work was parameterization above shortest path. More precisely, let be vertices of an undirected graph . Clearly, the length of any -path in is lower bounded by the shortest distance, , between these vertices. Based on this observation, Bezáková et al. in  introduced the Longest Detour problem that asks, given a graph , two vertices , and a positive integer , whether has an -path with at least vertices. They proved that for undirected graphs, this problem can be solved in time . On the other hand, the parameterized complexity of Longest Detour on directed graphs is still open. For the variant of the problem where the question is whether has an -path with exactly vertices, a randomized algorithm with running time and a deterministic algorithm with running time were obtained . These algorithms work for both undirected and directed graphs. Parameterization above degeneracy is “orthogonal” to the parameterization above the shortest distance. There are classes of graphs, like planar graphs, that have constant degeneracy and arbitrarily large diameter. On the other hand, there are classes of graphs, like complete graphs, of constant diameter and unbounded degeneracy.
1.1 Our approach
Our algorithmic results are based on classical theorems of Dirac , and Erdős and Gallai  on the existence of “long cycle” and “long paths” and can be seen as non-trivial algorithmic extensions of these classical theorems. Let be the minimum vertex degree of graph .
Theorem 4 (Dirac ).
Every -vertex -connected graph with minimum vertex degree , contains a cycle with at least vertices.
Theorem 5 (Erdős and Gallai ).
Every connected -vertex graph contains a path with at least vertices.
We give a high-level overview of the ideas used to prove Theorem 2. The ideas behind the proof of Theorem 3 are similar. Let be a 2-connected graph of degeneracy . If , we can solve Longest Cycle Above Degeneracy in time by making of use one of the algorithms for Longest Cycle. Assume from now that for some constant , which will be specified in the proof. Then we find a -core of (a connected subgraph of with the minimum vertex degree at least ). This can be done in linear time by one of the known algorithms, see e.g. . If the size of is sufficiently large, say , we use Theorem 4 to conclude that contains a cycle with at least vertices.
The most interesting case occurs when . Suppose that has a cycle of length at least . It is possible to prove that then there is also a cycle of length at leat that it hits the core . We do not know how many times and in which vertices of this cycle enters and leaves , but we can guess these terminal points. The interesting property of the core is that, loosely speaking, for any “small” set of terminal points, inside the cycle can be rerouted in a such way that it will contain all vertices of .
A bit more formally, we prove the following structural result. We define a system of segments in with respect to , which is a family of internally vertex-disjoint paths in (see Figure 1). Moreover, for every , every path has at least vertices, its endpoints are in and all internal vertices of are in . Also the union of all the segments is a forest with every connected component being a path.
We prove that contains a cycle of length at least if and only if
either there is a path of length at least with endpoints in and all internal vertices outside , or
there is a system of segments with respect to such that the total number of vertices outside used by the paths of the system, is within the interval .
The proof of this structural result is built on Lemma 1, which describes the possibility of routing in graphs of large minimal degree. The crucial property is that we can complement any system of segments of bounded size by segments inside the core to obtain a cycle that contains all the vertices of as is shown in Figure 1.
Since , the problem of finding a cycle of length at least in boils down to one of the following tasks. Either find a path of length with all internal vertices outside , or find a system of segments with respect to such that the total number of vertices used by the paths of the system is , here and are the constants to be specified in the proof. In the first case, we can use one of the known algorithms to find in time such a long path. In the second case, we can use color-coding to solve the problem.
Organization of the paper. In Section 2 we give basic definitions and state some known fundamental results. Sections 3–4 contain the proof of Theorems 3 and 2. In Section 3 we state structural results that we need for the proofs and in Section 4 we complete the proofs. In Section 5, we give the complexity lower bounds for our algorithmic results. We conclude the paper in Section 6 by stating some open problems.
We consider only finite undirected graphs. For a graph , we use and to denote its vertex set and edge set, respectively. Throughout the paper we use and . For a graph and a subset of vertices, we write to denote the subgraph of induced by . We write to denote the graph ; for a single-element set , we write . For a vertex , we denote by the (open) neighborhood of , i.e., the set of vertices that are adjacent to in . For a set , . The degree of a vertex is . The minimum degree of is . A -core of is an inclusion maximal induced connected subgraph with . Every graph of degeneracy at least contains a -core and that can be found in linear time (see ). A vertex of a connected graph with at least two vertices is a cut vertex if is disconnected. A connected graph is -connected if it has no cut vertices. An inclusion maximal induced 2-connected subgraph of is called a biconnected component or block. Let be the set of blocks of a connected graph and let be the set of cut vertices. Consider the bipartite graph with the vertex set , where is the bipartition, such that and are adjacent if and only if . The block graph of a connected graph is always a tree (see ).
A path in a graph is a self-avoiding walk. Thus no vertex appears in a path more than once. A cycle is a closed self-avoiding walk . For a path with end-vertices and , we say that the vertices of are internal. We say that is a linear forest if each component of is a path. The contraction of an edge is the operation that removes the vertices and together with the incident edges and replaces them by a vertex that is adjacent to the vertices of of the original graph. If is obtained from by contracting some edges, then is a contraction of .
We summarize below some known algorithmic results which will be used as subroutines by our algorithm.
Longest Path and Longest Cycle are solvable in time .
We also need the result about the variant of Longest Path with fixed end-vertices. In the -Longest Path, we are given two vertices and of a graph and a positive integer . The task is to decide, whether has an -path with at least vertices. Using the results of Bezáková et al. , we immediately obtain the following.
-Longest Path is solvable in time .
3 Segments and rerouting
In this section we define systems of segments and prove structural results about them. These combinatorial results are crucial for our algorithms for Longest Path Above Degeneracy and Longest Cycle Above Degeneracy.
The following rerouting lemma is crucial for our algorithms.
Let be an -vertex graph and be a positive integer such that . Let , , be a collection of pairs of vertices of such that for all , , and there is at least one index such that . Then there is a family of pairwise vertex-disjoint paths in such that each is an -path and , that is, the paths cover all vertices of .
We prove the lemma in two steps. First we show that there exists a family of pairwise vertex-disjoint paths connecting all pairs . Then we show that if the paths of do not cover all vertices of , it is possible to enlarge a path such that the new family of paths covers more vertices.
We start by constructing a family of vertex-disjoint paths in such that each is an -path. We prove that we can construct paths in such a way that each has at most 3 vertices. Let and . Notice that We consecutively construct paths of for . If , then we have a trivial -path. If and are adjacent, then edge forms an -path with 2 vertices. Assume that and . The already constructed paths contain at most vertices of in total. Hence, there is a set of at least of vertices that are not contained in any of already constructed paths. Since , each vertex of has at most non-neighbors in . By the pigeonhole principle, there is such that . Then we can construct the path .
We proved that there is a family of vertex-disjoint -paths in . Among all such families, let us select a family covering the maximum number of vertices of . If , then the lemma holds. Assume that . Suppose . Since for some , there is an edge in one of the paths. Since there are at least vertices uncovered by paths of . Since , each vertex of has at most non-neighbors in . Thus there is adjacent to both and . But then we can extend the path containing by replacing by the path . The paths of the new family cover more vertices than the paths of , which contradicts the choice of .
Suppose . Because the paths of are vertex-disjoint, the union of edges of paths from contains a -matching. That is, there are edges of such that for every , vertices are consecutive in some path from and , for all non-equal . Let . We again use the observation that has at most non-neighbors in and, therefore, there is such that . Then we extend the path containing by replacing edge by the path , contradicting the choice of . We conclude that the paths of cover all vertices of . ∎
Let be a graph and let be a set of terminals. We need the following definitions.
Definition 1 (Terminal segments).
We say that a path in is a one-terminal -segment if it has at least two vertices, exactly one end-vertex of is in and other vertices are not in . Respectively, is a two-terminal -segment if it has at least three vertices, both end-vertices of are in and internal vertices of are not in .
For every cycle hitting , removing the vertices of from turns it into a set of two-terminal -segments for . So here is the definition.
Definition 2 (System of -segments).
We say that a set of paths in is a system of -segments if it satisfies the following conditions.
For each , is a two-terminal -segment,
are internally vertex-disjoint, and
the union of is a linear forest.
Let us remark that we do not require that the end-vertices of the paths cover all vertices of . System of segments will be used for solving Longest Cycle Above Degeneracy.
For Longest Path Above Degeneracy we need to modify the definition of a system of -segments to include the possibility that path can start or end in .
Definition 3 (Extended system of -segments).
We say that a set of paths in is an extended system of -segments if the following holds.
At least one and at most two paths are one-terminal -segments and the other are two-terminal -segments.
are internally vertex-disjoint and the end-vertices of each one-terminal segment that is in is pairwise distinct with the other vertices of the paths.
The union of is a linear forest and if contains two one-terminal segments, then the vertices of these segments are in distinct components of the forest.
The following lemma will be extremely useful for the algorithm solving Longest Path Above Degeneracy. Informally, it shows that if a connected graph is of large degeneracy but has a small core , then deciding whether has a path of length can be reduced to checking whether has an extended system of -segments with terminal set such that the total number of vertices used by the system is .
Let . Let be a connected graph with a -core such that and . Then has a path on vertices if and only if has an extended system of -segments with terminal set such that the total number of vertices contained in the paths of the system in is .
We put . Suppose first that has an extended system of -segments and that the total number of vertices of the paths in the system outside is . Let and be the end-vertices of for and assume without loss of generality that for , the vertices of and are pairwise distinct with the possible exception when . We also assume without loss of generality that is a one-terminal segment and and if has two one-terminal segments, then the second such segment is and .
Suppose that contains one one-terminal segment . Let be an arbitrary vertex of . Notice that such a vertex exists, because and . Consider the collection of pairs of vertices . Notice that vertices from distinct pairs are distinct and . By Lemma 1, there are vertex-disjoint paths in that cover such that is a -path for . By concatenating we obtain a path in with vertices.
Assume now that contains two one-terminal segments and . Consider the collection of pairs of vertices . Notice that vertices from distinct pairs are distinct and there is such that by the condition (iii) of the definition of an extended system of segments. By Lemma 1, there are vertex-disjoint paths in that cover such that is a -path for . By concatenating we obtain a path in with vertices.
To show the implication in the opposite direction, let us assume that has and -path with vertices. We distinguish several cases.
Case 1: . Consider a shortest path with one end-vertex and the second end-vertex . Notice that such a path exists, because is connected. Denote by and the and -subpaths of respectively. Because , or . Assume that . Then the concatenation of and is a path with at least vertices and it contains a subpath with the end-vertex with vertices. We have that is an extended system of -segments and has vertices outside .
Case 2: and . Let . Note that , because . Since is an induced subgraph of and , . Then for every , either the -subpath of contains at least vertices outside or the -subpath of contains at least vertices outside . Assume without loss of generality that contains at least vertices outside . Consider the minimal subpath of ending at such that . Then the start vertex of is not in . Let and assume that are ordered in the same order as they occur in starting from . In particular, . Let . Consider the paths where is the -subpath of for . Since , . We obtain that is an extended system of -segments with vertices outside .
Case 3: . Then there are distinct such that the -subpath of lies in . Since has at least vertices outside , there are such that the -subpath of is a subpath with exactly vertices outside with . Let be the family of inclusion maximal subpaths of containing the vertices of such that the internal vertices of each are outside . The set is a required extended system of -segments. ∎
The next lemma will be used for solving Longest Cycle Above Degeneracy.
Let . Let be a 2-connected graph with a -core such that and . Then has a cycle with at least vertices if and only if one of the following holds (where ).
There are distinct and an -path in with all internal vertices outside such that has at least internal vertices.
has a system of -segments with terminal set and the total number of vertices of the paths outside is at least and at most .
We put . First, we show that if (i) or (ii) holds, then has a cycle with at least vertices. Suppose that there are distinct and an -path in with all internal vertices outside such that has at least internal vertices. By Lemma 1, has a Hamiltonian -path . By taking the union of and we obtain a cycle with at least vertices.
Now assume that has a system of -segments and the total number of vertices of the paths outside is at least . Let and be the end-vertices of for and assume without loss of generality that for , the vertices of and are pairwise distinct with the possible exception when . Consider the collection of pairs of vertices . Notice that vertices from distinct pairs are distinct and . By Lemma 1, there are vertex-disjoint paths in that cover such that is a -path for and is a -path. By taking the union of and we obtain a cycle in with at least vertices.
To show the implication in the other direction, assume that has a cycle with at least vertices.
Case 1: . Since is a 2-connected graph, there are pairwise distinct vertices and and vertex-disjoint and -paths and such that the internal vertices of the paths are outside . The cycle contains an -path with at least vertices. The concatenation of , and is an -path in with at least internal verices and the internal vertices are outside . Hence, (i) holds.
Case 2: . Let for some vertex . Since is 2-connected, there is a shortest -path in such that and . The cycle contains an -path with at least vertices. The concatenation of and is an -path in with at least internal vertices and the internal vertices of the path are outside . Therefore, (i) is fulfilled.
Case 3: . Since and , we have that . Then we can find pairs of distinct vertices of and segments of such that (a) is an -path for with at least one internal vertex and the internal vertices of are outside , (b) for , the vertitces of and are distinct with the possible exception if and, possibly, , and (c) . If there is such that has at least internal vertices, then (i) is fulfilled.
Now assume that each has at most internal vertices; notice that in this case. We select an inclusion minimal set of indices such that . Notice that because each path has at most internal vertices, . Let and . By the choice of , the union of is either the cycle or a linear forest. Suppose that the union of the paths is . Then , and . We obtain that has at most vertices (the last inequality follows from the fact that ); a contradiction. Hence, the union of the paths is a linear forest. Therefore, is a system of -segments with terminal set and the total number of vertices of the paths outside is at least and at most , that is, (ii) is fulfilled. ∎
We have established the fact that existence of long (path) cycle is equivalent to the existence of (extended) system of -segments for some terminal set with at most vertices from outside . Towards designing algorithms for Longest Path Above Degeneracy and Longest Cycle Above Degeneracy, we define two auxiliary problems which can be solved using well known color-coding technique.
Segments with Terminal Set and Extended Segments with Terminal Set are solvable in time .
We start with the algorithm for Segments with Terminal Set. Then we show how to modify it for Extended Segments with Terminal Set. Our algorithm uses the color coding technique introduced by Alon, Yuster and Zwick in . As it is usual for algorithms of this type, we first describe a randomized Monte-Carlo algorithm and then explain how it could be derandomized.
Let be an instance of Segments with Terminal Set.
Notice that if paths are a solution for the instance, that is, is a system of -segments and the total number of internal vertices of the paths is , then . If , then because each path in a solution should have at least one internal vertex, is a no-instance. Therefore, we can assume without loss of generality that . Let . We color the vertices of with colors uniformly at random. Let be paths and and let be the end-vertices of for . We say that the paths
together with the ordered pairsof their end-vertices form a colorful solution if the following is fulfilled:
is a system of -segments,
if , and , then the vertices and have distinct colors unless , and (in this case the colors can be distinct or same).
It is straightforward to see that any colorful solution is a solution of the original problem. From the other side, if has a solution
, then with probability at leastall distinct vertices of the paths of a solution are colored by distinct colors and for such a coloring, is a colorful solution. Since , we have that the probability is lower bounded by . This shows that if there is no colorful solution, then the probability that is a yes-instance is at most . It immediately implies that if after trying random colorings there is no colorful solution for any of them, then the probability that is a yes-instance is at most .
We construct a dynamic programming algorithm that decides whether there is a colorful solution. Denote by the considered random coloring.
In the first step of the algorithm, for each non-empty and distinct , we compute the Boolean function such that if and only if there are and an -path such that is a two-terminal -segment, , , and the vertices of are colored by pairwise distinct colors from . We define if . For other cases, we use dynamic programming.
We use a dynamic-programming algorithm to compute . For each and each non-empty , we compute the Boolean function such that if and only if there is and an -path such that , , and the vertices of are colored by pairwise distinct colors from .
We compute recursively starting with one-element sets. For every , where , and every , we set if and is adjacent to a vertex of colored , and we set otherwise. For of size at least two, we set if and there is with , and otherwise.
We set if and only if there are and such that and .
The correctness of computing and is proved by standard arguments in a straightforward way. Notice that we can compute the tables of values of and in time . First, we compute the values of for all , and non-empty . Then we use the already computed values of to compute the table of values of .
Next, we use the table of values of to check whether a colorful solution exists. We introduce the Boolean function such that for each , , integer and , if and only if there are paths and ordered pairs of distinct vertices of such that each is an -path and the following is fulfilled:
is a system of -segments,
if , and , then the vertices and have distinct colors unless , and when the colors could be same,
Notice, that if , then . Our aim is to compute for and . Then we observe that a colorful solution exists if and only if there is and such that .
If and , then
For , we use the following recurrence: