<p>Counting endomorphisms or fixed-point-free endomorphisms is complete for $\mathsf{FP}^{\mathsf{\# P}}$: given a connected graph $G$, consider the graph $G'$ which is the disjoint union of $G$ and a triangle. Then $|\text{End}(G')| = (|\text{End}(G)| + \# 3COL(G))(\#\{\text{triangles in } G\} + 3^3)$, so $\# 3COL$ can be computed using two endomorphism counts (and by a general result, even just one suffices) and some poly-time post-processing. Note that the number of triangles can be counted in cubic (or even matrix multiplication) time. The same equation holds for fixed-point free endomorphisms, since the 3-colorings and triangles are fixed-point-free endomorphisms of $G'$. </p>

<p>If you would like $G'$ to be connected, you can do as follows. First note that counting vertex-colored graph endomorphisms (where vertices of color $c$ can only be mapped to other vertices of color $c$) is equivalent to counting graph endomorphisms, as follows. Let the colors be $\{1,...,C\}$. For each vertex $v$ of color $c$, add in a new disjoint <em>odd</em> cycle $C_v$ of size at least $n + 2c$ ($n=|V(G)|$), and connect one vertex of $C_v$ to $v$. Every endomorphism of $G$ corresponds to $2^n$ endomorphisms of the new graph (for each cycle, you have two choices of how to map it). Note that no vertices of $G$ can map to vertices of any $C_v$, since the cycles are too large (you'd have to be able to fit one cycle inside another, which you can't for odd cycles). </p>

<p>Now, to make a version of $G'$ that is connected, we start with a colored version, and then apply the above transformation. Start as before, by adding to $G$ a disjoint triangle $\Delta$. Now add a single new vertex $v_0$ that is connected to every vertex in $G \cup \Delta$. Color $v_0$ red and all other vertices blue. </p>

CC BY-SA 3.0
2014-05-21T09:45:46.750Z
Thanks! I'm not sure of your exact formula for $|\mathrm{End}(G')|$ (I get $(|\mathrm{End}(G)| + \#3COL(G))(\#triangles + 3^3)$, and something similar for fixed-point-free) but the argument still holds. The second part of your argument shows hardness even assuming connectedness, I think it is true but I think it doesn't apply directly to fixed-point-free endomorphisms (there are fixed points in the cycle mappings), but that's not so important. I'd be more curious to know: is the decision problem NP-hard (for non-trivial, and for fixed-point-free endomorphisms)? Thanks again!
Antoine Amarilli 'a3nm'
CC BY-SA 3.0
2014-05-21T10:02:43.027Z
You're right about the formula - I updated it. To make the second part apply to fixed-point-free, put an edge from each of two maximally distant vertices of $C_v$ to $v$. The count for fixed-point-free will be slightly different, but I think it still works. (You may also need to increase the size of the cycles...). For pairs of rigid graphs (no nontrivial endos) $G,H$, deciding existence of endos of $G \cup H$ (disjoint union) is equivalent to deciding existence of a homomorphism $G \to H$ or $H \to G$. Almost all graphs are rigid w.h.p., so it's quite possible that decision is NP-hard...
Joshua Grochow
CC BY-SA 3.0
2014-05-21T13:03:11.843Z
OK I think I buy your argument for fixed-point-free count. For decision, in fact I now notice that "The core of a graph", Hell, p. 8-9, seems to prove that deciding the existence of a non-trivial endomorphism is NP-complete. (The question of fixed-point-free endomorphisms remains but there is little reason to believe it wouldn't be hard also.)
Antoine Amarilli 'a3nm'
CC BY-SA 3.0
2014-05-21T00:08:53.443Z
2014-05-21T09:56:19.757Z
2014-05-21T09:56:19.757Z
Joshua Grochow
<p>A <em>homomorphism</em> from a graph $G = (V, E)$ to a graph $G' = (V', E')$ is a mapping $f$ from $V$ to $V'$ such that if $x$ and $y$ are adjacent in $E$ then $f(x)$ and $f(y)$ are adjacent in $E'$. An <em>endomorphism</em> of a graph $G$ is a homomorphism from $G$ to itself; it is <em>fixed-point-free</em> if there is no $x$ such that $f(x) = x$ and it is <em>non-trivial</em> if it is not the identity.</p>

<p>I have recently asked <a href="https://cstheory.stackexchange.com/questions/22547/complexity-of-counting-poset-automorphisms">a question</a> related to poset (and graph) <em>automorphisms</em>, that is, bijective endomorphisms whose converse are also an endomorphism. I found related work about counting (and deciding the existence of) automorphisms, but searching I couldn't find any results related to endomorphisms.</p>

<p>Hence my question: <strong>What is the complexity, given a graph $G$, of deciding the existence of a non-trivial endomorphism of $G$, or of counting the number of endomorphisms? Same question with fixed-point-free endomorphisms.</strong></p>

<p>I think the argument given in <a href="https://cstheory.stackexchange.com/a/22570/4795">this answer</a> extends to endomorphisms and justifies that the case of directed bipartite graphs, or posets, is no easier than the problem for general graphs (the problem for general graphs reduces to this case), but its complexity do not seem straightforward to determine. It is known that deciding the existence of an homomorphism from one graph to another is <a href="https://en.wikipedia.org/wiki/Graph_homomorphism#Complexity" rel="nofollow noreferrer">NP-hard</a> (this is clear as it generalizes graph coloring), but it seems like restricting the search to homomorphisms from a graph to <em>itself</em> might make the problem easier, so this doesn't help me determine the complexity of these problems.</p>

<cc.complexity-theory><graph-algorithms><counting-complexity><graph-isomorphism><homomorphism>
Complexity of counting graph endomorphisms
Antoine Amarilli 'a3nm'
# Complexity of counting graph endomorphisms

(Asked by: username_0 on 2014-05-17)

A *homomorphism* from a graph $G = (V, E)$ to a graph $G' = (V', E')$ is a mapping $f$ from $V$ to $V'$ such that if $x$ and $y$ are adjacent in $E$ then $f(x)$ and $f(y)$ are adjacent in $E'$. An *endomorphism* of a graph $G$ is a homomorphism from $G$ to itself; it is *fixed-point-free* if there is no $x$ such that $f(x) = x$ and it is *non-trivial* if it is not the identity.

I have recently asked [a question](https://cstheory.stackexchange.com/questions/22547/complexity-of-counting-poset-automorphisms) related to poset (and graph) *automorphisms*, that is, bijective endomorphisms whose converse are also an endomorphism. I found related work about counting (and deciding the existence of) automorphisms, but searching I couldn't find any results related to endomorphisms.

Hence my question: **What is the complexity, given a graph $G$, of deciding the existence of a non-trivial endomorphism of $G$, or of counting the number of endomorphisms? Same question with fixed-point-free endomorphisms.**

I think the argument given in [this answer](https://cstheory.stackexchange.com/a/22570/4795) extends to endomorphisms and justifies that the case of directed bipartite graphs, or posets, is no easier than the problem for general graphs (the problem for general graphs reduces to this case), but its complexity do not seem straightforward to determine. It is known that deciding the existence of an homomorphism from one graph to another is [NP-hard](https://en.wikipedia.org/wiki/Graph_homomorphism#Complexity) (this is clear as it generalizes graph coloring), but it seems like restricting the search to homomorphisms from a graph to *itself* might make the problem easier, so this doesn't help me determine the complexity of these problems.

**Tags:** cc.complexity-theory, graph-algorithms, counting-complexity, graph-isomorphism, homomorphism


---

## 1 answers

### Answer by username_1 on 2014-05-21. Score: 6 | Accepted answer

Counting endomorphisms or fixed-point-free endomorphisms is complete for $\mathsf{FP}^{\mathsf{\# P}}$: given a connected graph $G$, consider the graph $G'$ which is the disjoint union of $G$ and a triangle. Then $|\text{End}(G')| = (|\text{End}(G)| + \# 3COL(G))(\#\{\text{triangles in } G\} + 3^3)$, so $\# 3COL$ can be computed using two endomorphism counts (and by a general result, even just one suffices) and some poly-time post-processing. Note that the number of triangles can be counted in cubic (or even matrix multiplication) time. The same equation holds for fixed-point free endomorphisms, since the 3-colorings and triangles are fixed-point-free endomorphisms of $G'$.

If you would like $G'$ to be connected, you can do as follows. First note that counting vertex-colored graph endomorphisms (where vertices of color $c$ can only be mapped to other vertices of color $c$) is equivalent to counting graph endomorphisms, as follows. Let the colors be $\{1,...,C\}$. For each vertex $v$ of color $c$, add in a new disjoint *odd* cycle $C\_v$ of size at least $n + 2c$ ($n=|V(G)|$), and connect one vertex of $C\_v$ to $v$. Every endomorphism of $G$ corresponds to $2^n$ endomorphisms of the new graph (for each cycle, you have two choices of how to map it). Note that no vertices of $G$ can map to vertices of any $C\_v$, since the cycles are too large (you'd have to be able to fit one cycle inside another, which you can't for odd cycles).

Now, to make a version of $G'$ that is connected, we start with a colored version, and then apply the above transformation. Start as before, by adding to $G$ a disjoint triangle $\Delta$. Now add a single new vertex $v\_0$ that is connected to every vertex in $G \cup \Delta$. Color $v\_0$ red and all other vertices blue.

> **Comments:**
> **username_0**: Thanks! I'm not sure of your exact formula for $|\mathrm{End}(G')|$ (I get $(|\mathrm{End}(G)| + \#3COL(G))(\#triangles + 3^3)$, and something similar for fixed-point-free) but the argument still holds. The second part of your argument shows hardness even assuming connectedness, I think it is true but I think it doesn't apply directly to fixed-point-free endomorphisms (there are fixed points in the cycle mappings), but that's not so important. I'd be more curious to know: is the decision problem NP-hard (for non-trivial, and for fixed-point-free endomorphisms)? Thanks again!  
> **username_1**: You're right about the formula - I updated it. To make the second part apply to fixed-point-free, put an edge from each of two maximally distant vertices of $C_v$ to $v$. The count for fixed-point-free will be slightly different, but I think it still works. (You may also need to increase the size of the cycles...). For pairs of rigid graphs (no nontrivial endos) $G,H$, deciding existence of endos of $G \cup H$ (disjoint union) is equivalent to deciding existence of a homomorphism $G \to H$ or $H \to G$. Almost all graphs are rigid w.h.p., so it's quite possible that decision is NP-hard...  
> **username_0**: OK I think I buy your argument for fixed-point-free count. For decision, in fact I now notice that "The core of a graph", Hell, p. 8-9, seems to prove that deciding the existence of a non-trivial endomorphism is NP-complete. (The question of fixed-point-free endomorphisms remains but there is little reason to believe it wouldn't be hard also.)  

---

