<p>A partial answer to the easier of my two questions:</p>

<p>If an edge $x\rightarrow y$ is 'obviously' part of all Hamiltonian paths because it is the only edge into vertex $y$, then all other edges from $x$ cannot be in <em>any</em> Hamiltonian cycle, because this would imply the path visits $x$ more than once. Thus, these other edges from $x$ can be removed from the graph, and this may reveal further edges that have in-degree 1 (and thus must also be in all Hamiltonian paths). And so on.</p>

<p>Similar logic can be used where an edge $w \rightarrow z$ is the only edge from $w$, or where the graph is undirected.</p>

<p>I don't think this will find the complete set of edges that are in all Hamiltonian paths, but at least it might find more than just going with the 'obvious' ones mentioned in the question.</p>

<p>Come to think of it if there is some algorithm for finding edges that are not part of any Hamiltonian paths then I'd also be interested in that - this solves a related problem in the field.</p>

CC BY-SA 3.0
2014-01-03T09:27:10.703Z
It certainly doesn't find all the edges. Any bridge (an edge whose removal disconnects the graph) must be in every Hamiltonian path.
David Richerby
CC BY-SA 3.0
2014-01-04T02:02:51.333Z
Hang on, if a graph contains a bridge, then the graph cannot be Hamiltonian. Do you mean bridges cannot be in any Hamiltonian path?
BenJWoodcroft
CC BY-SA 3.0
2014-01-04T02:39:01.857Z
If a graph contains a bridge, it cannot have a Hamiltonian cycle but it can still contain a Hamiltonian path. For example, if the graph itself is a path, every edge is a bridge and every edge lies on the unique Hamiltnian path.
David Richerby
CC BY-SA 3.0
2014-01-03T05:52:07.007Z
2014-01-03T05:52:07.007Z
BenJWoodcroft
<p>If we didn't have the guarantee that there is at least one Hamiltonian path, the following would show <strong>NP</strong>-hardness.</p>

<hr>

<p>Write $h(G)$ for the set of edges of the digraph&nbsp;$G$ that appear in every Hamiltonian path.  The key fact is the following.</p>

<p><strong>Lemma.</strong> For a digraph $G$, $h(G)=E(G)$ if, and only if, $G$&nbsp;is a directed path or $G$&nbsp;has no Hamiltonian path.</p>

<p><em>Proof.</em> If $G$&nbsp;is a directed path, then clearly $h(G)=E(G)$; if $G$&nbsp;has no Hamiltonian path then, for any edge $e\in G$ there is no Hamiltonian path that does not contain&nbsp;$e$ so $e\in h(G)$.</p>

<p>Conversely, suppose that $h(G)=E(G)$.  If $G$&nbsp;is a directed path, then we are done.  If not, then any Hamiltonian path in&nbsp;$G$ would have to be the whole of&nbsp;$G$, which is impossible, since $G$&nbsp;is not a directed path. Therefore, $G$&nbsp;has no Hamiltonian path.&nbsp;&nbsp;&nbsp;&nbsp;$\Box$</p>

<p>As a result, it is <strong>NP</strong>-hard to compute $h(G)$ since, given $h(G)$, we can determine whether an input graph&nbsp;$G$ has a Hamiltonian path by checking whether $G$&nbsp;is a path and whether $h(G)=E(G)$. Thus, there is (probably) no polynomial-time algorithm to compute $h(G)$.  </p>

CC BY-SA 3.0
2014-01-03T02:14:33.853Z
Ben stated that we can assume the input graph to contain at least
one hampath, so we can cosider it to be a promise problem. In this case using the promise to show hardness is inappropriate.
John D.
CC BY-SA 3.0
2014-01-03T02:16:28.897Z
Let me elaborate: as you certainly know the idea behind reducing A to B is that given an algorithm for B we can solve A as well within the same complexity bounds. However, if Ben happens to find an efficient algorithm for his problem which assumes that the input graphs always contain at least one hampath, it doesn't help us to solve Hampath efficiently by only your reasoning(the promise problem still might be NP-hard for other reasons).
John D.
CC BY-SA 3.0
2014-01-03T02:17:12.477Z
On the other hand, if we drop the promise property your implied reduction doesn't work anymore because we have to check for the existence of a hampath as well. If $h(G)$ returns an empty set this either means there exists no hampath or there is no edge common to all hampaths.
John D.
CC BY-SA 3.0
2014-01-03T02:29:51.537Z
Thanks for your answer David but I'm with @user17410.
BenJWoodcroft
CC BY-SA 3.0
2014-01-03T06:09:47.323Z
Updated the question to more explicit about this.
BenJWoodcroft
CC BY-SA 3.0
2014-01-03T09:23:11.940Z
@user17410 I take the point about the promise problem; I'd not noticed the statement that the graph has at least one Hamiltonian path. However, if the promise is removed then my reduction works just fine: as explained in the proof of the lemma, if $G$ has no Hamiltonian path, $h(G)$ is not the empty set: it is $E(G)$.
David Richerby
CC BY-SA 3.0
2014-01-03T10:45:45.990Z
@DavidRicherby you are right, I wrongly assumed that $h(G)$ is empty for a graph that contains no hampaths, which is not how you defined it.
John D.
CC BY-SA 3.0
2014-01-03T01:41:33.500Z
2014-01-03T09:25:27.433Z
2014-01-03T09:25:27.433Z
David Richerby
<p>A polytime algorithm that can find such a collection of edges <em>even in the promise version of this problem</em> can be used as a blackbox to solve the <code>Hamiltonian Path</code> problem in polynomial time, and thus this promise problem is NP-Hard under Cook reductions. The idea here is to use the algorithm for solving the promise problem on a sequence of graphs, many (but not all) of which potentially violate the promise given in the problem statement. Importantly, <strong>nothing is assumed of the output of the algorithm when it is fed a promise-violating graph as input</strong>, just that it outputs something (perhaps even adversarially). We can, of course, always cut the algorithm off and return the empty set as its solution if its execution is taking longer than some provided time bound (a bound only proven to hold only in promise-satisfying instances) and satisfy this requirement. It is the nature of the change in the algorithm's output (or lack thereof) on the sequence of instances that interests us.</p>

<p>Suppose you have a graph $G=(V,E)$ in which you wish to determine the existence of a Hamiltonian path, and oracle access to a function $\varphi$ such that $\varphi(G) = h(G)$ (where $h$ is defined as in David's post) whenever $G$ contains a Hamiltonian path (and returns an arbitrary answer otherwise). Intuitively, the algorithm searches for a supergraph $H$ of $G$ on which $\varphi(H) = h(H)$ is violated. If such a graph can be found, it must be the case that $H$ (and all of its subgraphs, including $G$) is <em>not</em> Hamiltonian. Conversely, not violating the inequality on any graph in the sequence shows that the original $G$ is Hamiltonian.</p>

<p>Now construct a sequence of graphs $G_0 \cdots G_{n-1}$ as follows:</p>

<ol>
<li>Let $G_0 = G$</li>
<li>Pick a permutation $\pi$ of $V$ such that no $(\pi_i, \pi_{i+1})$ is an edge of $\varphi(G_0)$.*</li>
<li>For $i = 1$ to $n-1$
<ol>
<li>Let $e_i = (\pi_i, \pi_{i+1})$</li>
<li>Let $G_i = G_{i-1}$ with edge $e_i$ added (if it did not already exist in $G_{i-1}$)</li>
</ol></li>
</ol>

<p>Note that $h(G_x) \supseteq h(G_y)$ when $x &lt; y$ (i.e. containment of some fixed edge in $h$ is hereditary among the $\{G_i\}$). Thus, if $e_i \in \varphi(G_i)$ for some $i \geq 1$, it must be the case that $G$ <em>does not contain</em> a Hamiltonian Path, since $\varphi(\cdot)$ is not hereditary on this graph family (recall that $e_i$ is not in $\varphi(G_0)$) and thus $\varphi(G_i) \neq h(G_i)$ for some $G_i$.</p>

<p>However, if $e_i \not \in \varphi(G_i)$ for all $i$, no single addition of an edge was necessary in the construction of the first (set of) Hamiltonian Path(s) in the sequence in which we constructed $\{G_i\}$. Since $G_{n-1}$ contains a Hamiltonian path by construction, a simple inductive argument implies $G_0$ <em>must contain</em> one as well.</p>

<p>Thus, <code>Hamiltonian Path</code> can be solved via $O(n)$ queries to an oracle solving this promise problem (assuming they produce an arbitrary output on promise-violating graphs), meaning that any time bound $f(n)$ for an algorithm solving this problem implies a time bound of $O(n f(n))$ for solving <code>Hamiltonian Path</code>, and thus $f(n)$ (and any provable upper bound on the running time for a TM solving this problem) cannot be a polynomial unless $P = NP$.</p>

<p>*This is easy to do because $|h(G_0)| \leq n$ by definition, and we could always of course prematurely determine the nonexistance of a Hamiltonian path if $|\varphi(G_0)|$ is any larger than that.</p>

CC BY-SA 3.0
2014-01-03T10:35:58.223Z
In my post, I already showed that it's trivial to use $h(G)$ to determine whether $G$ has a Hamiltonian path. Also, we both missed that the question states that $G$ is assumed to have at least one Hamiltonian path.
David Richerby
CC BY-SA 3.0
2014-01-03T12:57:56.453Z
I'm aware of this. Still, any algorithm for a promise problem can be run on an instance violating the promise and produce *some* (potentially completely arbitrary) output. I try to show that a technique for solving the problem posed can be useful even when the promise may or may not hold. Particularly, if we apply it on a certain sequence of graphs where the promise must hold on at least some subset of the instances, we can glean some information out of when (or if) the algorithm's guess at $h(G)$ changes its value due to the introduction of a single edge. I tried clarifying this in my post.
Yonatan N
CC BY-SA 3.0
2014-01-04T12:40:54.403Z
While I reckon you are right @Yonatan I don't have the chops to be confident marking my question as answered, unless there is further upvoting. But thanks. And bugger!
BenJWoodcroft
CC BY-SA 3.0
2014-01-04T23:12:01.287Z
Not a problem. If you want any clarification somewhere, let me know!
Yonatan N
CC BY-SA 3.0
2014-01-03T09:36:03.170Z
2014-01-13T22:35:21.183Z
2014-01-13T22:35:21.183Z
Yonatan N
<p>I'm wondering if there is any algorithm known for finding edges in a graph that are part of all hamiltonian paths (operating under the assumption that the graph has at least one such path). Failing that, is there an algorithm for finding as many of these edges as possible, relaxing the requirement that all such edges are found?</p>

<p>One could find all hamiltonian paths in the graph, and then look at all the edges in those paths, but is there a better way?</p>

<p>One type of edge in this class obvious even to me is edges that are directed to vertices with in-degree 1 (or similarly edges from vertices that have out-degree 1). I'm particularly interested in directed graphs but the insight into the undirected version would also be helpful.</p>

<p>My apologies if this question is overly naive - I ran across this problem while doing microbial genomics, and any help would be greatly appreciated.</p>

<p>Thanks in advance,
ben</p>

<graph-theory><hamiltonian-paths>
Is there an efficient algorithm for finding edges that are part of all hamiltonian paths?
BenJWoodcroft
# Is there an efficient algorithm for finding edges that are part of all hamiltonian paths?

(Asked by: username_0 on 2014-01-02)

I'm wondering if there is any algorithm known for finding edges in a graph that are part of all hamiltonian paths (operating under the assumption that the graph has at least one such path). Failing that, is there an algorithm for finding as many of these edges as possible, relaxing the requirement that all such edges are found?

One could find all hamiltonian paths in the graph, and then look at all the edges in those paths, but is there a better way?

One type of edge in this class obvious even to me is edges that are directed to vertices with in-degree 1 (or similarly edges from vertices that have out-degree 1). I'm particularly interested in directed graphs but the insight into the undirected version would also be helpful.

My apologies if this question is overly naive - I ran across this problem while doing microbial genomics, and any help would be greatly appreciated.

Thanks in advance,
ben

**Tags:** graph-theory, hamiltonian-paths

---

## 3 answers

### Answer by username_3 on 2014-01-03. Score: 7 | Accepted answer

A polytime algorithm that can find such a collection of edges *even in the promise version of this problem* can be used as a blackbox to solve the `Hamiltonian Path` problem in polynomial time, and thus this promise problem is NP-Hard under Cook reductions. The idea here is to use the algorithm for solving the promise problem on a sequence of graphs, many (but not all) of which potentially violate the promise given in the problem statement. Importantly, **nothing is assumed of the output of the algorithm when it is fed a promise-violating graph as input**, just that it outputs something (perhaps even adversarially). We can, of course, always cut the algorithm off and return the empty set as its solution if its execution is taking longer than some provided time bound (a bound only proven to hold only in promise-satisfying instances) and satisfy this requirement. It is the nature of the change in the algorithm's output (or lack thereof) on the sequence of instances that interests us.

Suppose you have a graph $G=(V,E)$ in which you wish to determine the existence of a Hamiltonian path, and oracle access to a function $\varphi$ such that $\varphi(G) = h(G)$ (where $h$ is defined as in David's post) whenever $G$ contains a Hamiltonian path (and returns an arbitrary answer otherwise). Intuitively, the algorithm searches for a supergraph $H$ of $G$ on which $\varphi(H) = h(H)$ is violated. If such a graph can be found, it must be the case that $H$ (and all of its subgraphs, including $G$) is *not* Hamiltonian. Conversely, not violating the inequality on any graph in the sequence shows that the original $G$ is Hamiltonian.

Now construct a sequence of graphs $G\_0 \cdots G\_{n-1}$ as follows:

1. Let $G\_0 = G$
2. Pick a permutation $\pi$ of $V$ such that no $(\pi\_i, \pi\_{i+1})$ is an edge of $\varphi(G\_0)$.\*
3. For $i = 1$ to $n-1$
   1. Let $e\_i = (\pi\_i, \pi\_{i+1})$
   2. Let $G\_i = G\_{i-1}$ with edge $e\_i$ added (if it did not already exist in $G\_{i-1}$)

Note that $h(G\_x) \supseteq h(G\_y)$ when $x < y$ (i.e. containment of some fixed edge in $h$ is hereditary among the $\{G\_i\}$). Thus, if $e\_i \in \varphi(G\_i)$ for some $i \geq 1$, it must be the case that $G$ *does not contain* a Hamiltonian Path, since $\varphi(\cdot)$ is not hereditary on this graph family (recall that $e\_i$ is not in $\varphi(G\_0)$) and thus $\varphi(G\_i) \neq h(G\_i)$ for some $G\_i$.

However, if $e\_i \not \in \varphi(G\_i)$ for all $i$, no single addition of an edge was necessary in the construction of the first (set of) Hamiltonian Path(s) in the sequence in which we constructed $\{G\_i\}$. Since $G\_{n-1}$ contains a Hamiltonian path by construction, a simple inductive argument implies $G\_0$ *must contain* one as well.

Thus, `Hamiltonian Path` can be solved via $O(n)$ queries to an oracle solving this promise problem (assuming they produce an arbitrary output on promise-violating graphs), meaning that any time bound $f(n)$ for an algorithm solving this problem implies a time bound of $O(n f(n))$ for solving `Hamiltonian Path`, and thus $f(n)$ (and any provable upper bound on the running time for a TM solving this problem) cannot be a polynomial unless $P = NP$.

\*This is easy to do because $|h(G\_0)| \leq n$ by definition, and we could always of course prematurely determine the nonexistance of a Hamiltonian path if $|\varphi(G\_0)|$ is any larger than that.

> **Comments:**
> **username_1**: In my post, I already showed that it's trivial to use $h(G)$ to determine whether $G$ has a Hamiltonian path. Also, we both missed that the question states that $G$ is assumed to have at least one Hamiltonian path.  
> **username_3**: I'm aware of this. Still, any algorithm for a promise problem can be run on an instance violating the promise and produce *some* (potentially completely arbitrary) output. I try to show that a technique for solving the problem posed can be useful even when the promise may or may not hold. Particularly, if we apply it on a certain sequence of graphs where the promise must hold on at least some subset of the instances, we can glean some information out of when (or if) the algorithm's guess at $h(G)$ changes its value due to the introduction of a single edge. I tried clarifying this in my post.  
> **username_0**: While I reckon you are right @Yonatan I don't have the chops to be confident marking my question as answered, unless there is further upvoting. But thanks. And bugger!  
> **username_3**: Not a problem. If you want any clarification somewhere, let me know!  

---

### Answer by username_0 on 2014-01-03. Score: 1

A partial answer to the easier of my two questions:

If an edge $x\rightarrow y$ is 'obviously' part of all Hamiltonian paths because it is the only edge into vertex $y$, then all other edges from $x$ cannot be in *any* Hamiltonian cycle, because this would imply the path visits $x$ more than once. Thus, these other edges from $x$ can be removed from the graph, and this may reveal further edges that have in-degree 1 (and thus must also be in all Hamiltonian paths). And so on.

Similar logic can be used where an edge $w \rightarrow z$ is the only edge from $w$, or where the graph is undirected.

I don't think this will find the complete set of edges that are in all Hamiltonian paths, but at least it might find more than just going with the 'obvious' ones mentioned in the question.

Come to think of it if there is some algorithm for finding edges that are not part of any Hamiltonian paths then I'd also be interested in that - this solves a related problem in the field.

> **Comments:**
> **username_1**: It certainly doesn't find all the edges. Any bridge (an edge whose removal disconnects the graph) must be in every Hamiltonian path.  
> **username_0**: Hang on, if a graph contains a bridge, then the graph cannot be Hamiltonian. Do you mean bridges cannot be in any Hamiltonian path?  
> **username_1**: If a graph contains a bridge, it cannot have a Hamiltonian cycle but it can still contain a Hamiltonian path. For example, if the graph itself is a path, every edge is a bridge and every edge lies on the unique Hamiltnian path.  

---

### Answer by username_1 on 2014-01-03. Score: 1

If we didn't have the guarantee that there is at least one Hamiltonian path, the following would show **NP**-hardness.

---

Write $h(G)$ for the set of edges of the digraph $G$ that appear in every Hamiltonian path. The key fact is the following.

**Lemma.** For a digraph $G$, $h(G)=E(G)$ if, and only if, $G$ is a directed path or $G$ has no Hamiltonian path.

*Proof.* If $G$ is a directed path, then clearly $h(G)=E(G)$; if $G$ has no Hamiltonian path then, for any edge $e\in G$ there is no Hamiltonian path that does not contain $e$ so $e\in h(G)$.

Conversely, suppose that $h(G)=E(G)$. If $G$ is a directed path, then we are done. If not, then any Hamiltonian path in $G$ would have to be the whole of $G$, which is impossible, since $G$ is not a directed path. Therefore, $G$ has no Hamiltonian path.    $\Box$

As a result, it is **NP**-hard to compute $h(G)$ since, given $h(G)$, we can determine whether an input graph $G$ has a Hamiltonian path by checking whether $G$ is a path and whether $h(G)=E(G)$. Thus, there is (probably) no polynomial-time algorithm to compute $h(G)$.

> **Comments:**
> **username_2**: Ben stated that we can assume the input graph to contain at least one hampath, so we can cosider it to be a promise problem. In this case using the promise to show hardness is inappropriate.  
> **username_2**: Let me elaborate: as you certainly know the idea behind reducing A to B is that given an algorithm for B we can solve A as well within the same complexity bounds. However, if Ben happens to find an efficient algorithm for his problem which assumes that the input graphs always contain at least one hampath, it doesn't help us to solve Hampath efficiently by only your reasoning(the promise problem still might be NP-hard for other reasons).  
> **username_2**: On the other hand, if we drop the promise property your implied reduction doesn't work anymore because we have to check for the existence of a hampath as well. If $h(G)$ returns an empty set this either means there exists no hampath or there is no edge common to all hampaths.  
> **username_0**: Thanks for your answer David but I'm with @user17410.  
> **username_0**: Updated the question to more explicit about this.  
> **username_1**: @user17410 I take the point about the promise problem; I'd not noticed the statement that the graph has at least one Hamiltonian path. However, if the promise is removed then my reduction works just fine: as explained in the proof of the lemma, if $G$ has no Hamiltonian path, $h(G)$ is not the empty set: it is $E(G)$.  
> **username_2**: @DavidRicherby you are right, I wrongly assumed that $h(G)$ is empty for a graph that contains no hampaths, which is not how you defined it.  

---

