# A new edge selection heuristic for computing the Tutte polynomial of an undirected graph.

Michael Monagan¹†

¹Department of Mathematics, Simon Fraser University, Burnaby, B.C., V5A 1S6, CANADA.

**Abstract.** We present a new edge selection heuristic and vertex ordering heuristic that together enable one to compute the Tutte polynomial of much larger sparse graphs than was previously doable. As a specific example, we are able to compute the Tutte polynomial of the truncated icosahedron graph using our Maple implementation in under 4 minutes on a single CPU. This compares with a recent result of Haggard, Pearce and Royle whose special purpose C++ software took one week on 150 computers.

**Résumé.** Nous présentons deux nouvelles heuristiques pour le calcul du polynôme de Tutte de graphes de faible densité, basées sur les principes de sélection d’arêtes et d’arrangement linéaire de sommets, et qui permettent de traiter des graphes de bien plus grande tailles que les méthodes existantes. Par exemple, en utilisant notre implémentation en Maple, nous pouvons calculer le polynôme de Tutte de l’isocahédron tronqué en moins de 4 minutes sur un ordinateur à processeur unique, alors qu’un programme ad-hoc récent de Haggard, Pearce et Royle, utilisant 150 ordinateurs, a nécessité une semaine de calcul pour obtenir le même résultat.

**Keywords:** Tutte polynomials, edge deletion and contraction algorithms, NP-hard problems.

## 1 Introduction

Let $G$ be an undirected graph. The Tutte polynomial of $G$ is a bivariate polynomial $T(G, x, y)$ which contains information about how $G$ is connected. We recall Tutte’s original definition for $T(G, x, y)$. Let $e = (u, v)$ be an edge in $G$. Let $G - e$ denote the graph obtained by deleting $e$ and let $G / e$ denote the graph obtained by contracting $e$, that is, first deleting $e$ then joining vertexes $u$ and $v$. Figure 1 shows an example of edge deletion and contraction.

<figure><img src="image_1.png" /><figcaption>**Fig. 1:** Graph edge deletion and contraction.</figcaption></figure>

<footnote>†This work was supported by the Mprime NCE of Canada</footnote>
**Definition 1** Let $G$ be a connected undirected graph. The Tutte polynomial $T(G, x, y)$ is the bivariate polynomial defined by

$$ T(G) = \begin{cases} 1 & \text{if } |E| = 0, \\ xT(G/e) & \text{if } e \text{ is a cut-edge in } G, \\ yT(G - e) & \text{if } e \text{ is a loop in } G \\ T(G - e) + T(G/e) & \text{if the edge } e \text{ is neither a loop nor a cut-edge in } G. \end{cases} \quad (1) $$

This definition immediately gives a recursive algorithm for computing $T(G, x, y)$. In general, a naive implementation of the algorithm will make an exponential number of recursive calls because of the last case in (1). If $G$ has $n$ vertexes and $m$ edges, the number of recursive calls $C(n+m)$ is bounded by

$$ C(n+m) \leq C(n+m-1) + C(n-1+m-1). $$

This is the Fibonacci recurrence. Hence $C(n+m) \in O(1.618^{n+m})$. If $G$ is not biconnected one can apply the following theorem to reduce $C(n+m)$.

**Theorem 1 (Tutte [10])** Let $G$ be a graph with $m$ biconnected components (blocks) $B_1, B_2, \dots, B_m$. Then $T(G, x, y) = \prod_{i=1}^{m} T(B_i, x, y)$.

Another way to reduce $C(n+m)$ is to “remember” the Tutte polynomials computed in the computation tree and use a graph isomorphism test to test whether a graph in the computation tree has been seen before. In [6], Haggard, Pearce and Royle present timings for random cubic and quartic graphs, complete graphs, and random graphs with varying edge densities $0 < p < 1$ that shows that employing graph isomorphism is very effective. For example, it roughly increases by 50% the size of random cubic graphs that can be handled in a given time. A factor determining the effectiveness of the isomorphism test is the order in which the edges are selected. In [9], Haggard, Pearce and Royle investigate various edge ordering heuristics. Two heuristics, which they call MINDEG and VORDER, are found to perform consistently better than random selection.

Our paper is organized as follows. In section 2 we describe the MINDEG and VORDER heuristics and present a new edge selection heuristic. The VORDER heuristic, and our new heuristic, also depend on the ordering of the vertexes in $G$. We present an ordering that we have found works particularly well with our edge selection heuristic. In section 3 we describe our Maple implementation and explain how we test for isomorphic graphs in the computation tree. In section 4 we present benchmarks comparing the three heuristics with and without the new vertex ordering and with and without an explicit graph isomorphism test. The data presented shows that our new heuristic again, roughly increases by 50% the size of sparse cubic graphs that can be handled in a given time. An experimental finding in this paper is that our new edge selection heuristic, when combined with our vertex ordering, does not require an explicit isomorphism test; a simple test for identical graphs is sufficient.

We end the introduction with some further information about available software for computing Tutte polynomials and related polynomials. Useful references include the very good Wikipedia webpage http://en.wikipedia.org/wiki/Tutte_polynomial and Bollobás' text [1]. The graph theory packages in Mathematica and Maple include commands for computing Tutte polynomials. The Mathematica algorithm does not look for identical or isomorphic graphs in the computation tree (see [6]). The TuttePolynomial command in Maple 11 and more recent versions (see [4]) uses the VORDER heuristic and hashing to
test for identical graphs in the computation tree. The fastest available software for computing Tutte polynomials and related polynomials is that of Haggard, Pearce and Royle [9, 6]. It is available on David Pearce's website at http://homepages.ecs.vuw.ac.nz/~djp/tutte/. It uses the canonical graph ordering available in Brendan Mckay's nauty package (see [7]) to identify isomorphic graphs.

We recall the definition for the reliability polynomial and chromatic polynomial.

**Definition 2** Let $G$ be an undirected graph. The reliability polynomial of $G$, denoted $R_p(G)$, is the probability that $G$ remains connected when each edge in $G$ fails with probability $p$. The chromatic polynomial of $G$, denoted $P_\lambda(G)$, counts the number of ways the vertexes of $G$ can be colored with $\lambda$ colors.

For example, $R_p(\bullet\bullet\bullet) = 1-p$ and $P_\lambda(\bullet\bullet\bullet) = \lambda(\lambda-1)$. The reliability and chromatic polynomials can also be computed by the edge deletion and contraction algorithm (see [5]). If $G$ has $n$ vertexes and $m$ edges, they are related to the Tutte polynomial as follows:

$$R_p(G) = (1-p)^{(n-1)} p^{(m-n+1)} T(G, 1, p^{-1}), \qquad (2)$$

$$P_{\lambda}(G) = (-1)^{(n-1)} \lambda T(G, 1 - \lambda, 0). \qquad (3)$$

Since graph coloring is NP-complete, it follows that computing the chromatic polynomial is NP-hard. Thus (3) implies computing the Tutte polynomial is also NP-hard. It is also known that computing $R_p(G)$ is NP-hard (see [8]). This does not mean, however, that computing the Tutte polynomial for a given graph is not polynomial time. Our new edge selection heuristic is polynomial time for some structured sparse graphs.

# 2 Edge selection heuristics.

In applying the identity $T(G) = T(G - e) + T(G/e)$ we are free to choose any edge which is neither a cut-edge nor a loop. [If $G$ has a cut-edge or loop, then those edges should be processed first.] In [9], Haggard, Pearce and Royle propose two heuristics, the minimum degree heuristic (MINDEG) and the vertex order heuristic (VORDER). We describe the heuristics here and introduce our new heuristic which is a variation on VORDER.

## 2.1 The minimum degree heuristic: MINDEG

Consider the graph $G$ in Figure 2.

<figure><img src="image_2.png" /><figcaption>Fig. 2: The minimum degree heuristic.</figcaption></figure>
The minimum degree heuristic picks the edge $e = (u, v)$ where $u$ is the first vertex of minimum degree ($u = 2$ in the example) and $v$ is the first vertex adjacent to $u$ of minimum degree ($v = 5$ in the example). Hence $e = (2, 5)$ is chosen. Shown in the figure are the graphs $G - e$ and $G/e$. The reader can see that the next edge that will be selected in $G - e$ is the edge (2, 4), which is a cut-edge. The algorithm will then contract the edge (2, 4), then select the edge (1, 5), another cut-edge. After contracting (1, 5) what is left is the triangle on vertexes 1, 3, 4. For the graph $G/e$, the MINDEG heuristic selects the edge (2,1). After deleting (2,1), MINDEG will select and contract the edge (2,4) again yielding the triangle 1, 3, 4. This example shows how identical graphs in the computation tree arise.

## 2.2 The vertex order heuristic: VORDER

Consider again the graph $G$ shown in the Figure 3.

<figure><img src="image_3.png" /><figcaption>Fig. 3: The VORDER-pull heuristic.</figcaption></figure>

The vertex order heuristic picks the edge $e = (u, v)$ where $u$ is simply the first vertex in the $G$ and $v$ is the first vertex adjacent to $u$. In our example $u = 1$, $v = 3$, hence $e = (1, 3)$ is chosen. Shown in Figure 3 are the graphs $G - e$ and $G/e$ where when we contracted the edge $e = (1, 3)$ we “pulled” vertex 3 down to vertex 1. The next edge selected in $G/e$ will be one of the edges (1,4).

There is alternative choice here when constructing the graph $G/e$. Instead of “pulling” vertex $v = 3$ down to $u = 1$, if instead we “push” vertex $u = 1$ up to $v = 3$ we get the contracted graph shown in Figure 4. Observe that the two contracted graphs $G/e$ in figures 3 and 4 are isomorphic. However, in the vertex order heuristic, the next edge selected in $G/e$ is different. In figure 3 the vertex order heuristic selects edge (1,4). In figure 4 it selects edge (2,4). We will call the two vertex order heuristics VORDER-pull and VORDER-push, respectively.

<figure><img src="image_4.png" /><figcaption>Fig. 4: The VORDER-push heuristic.</figcaption></figure>

To visualize the difference between VORDER-pull and VORDER-push, picture the computation tree of graphs produced by the algorithm as it applies the identity

$$T(G) = T(G - e) + T(G/e).$$
On the left of the computation tree we repeatedly delete edges. On the right of the tree we repeatedly contract edges. The two vertex order heuristics differ when we contract. In the VORDER-pull heuristic, we always select the same first vertex and contract (pull) other vertexes to it thus typically increasing the degree of the first vertex. In the VORDER-push heuristic, we select the first vertex and push it away (into the middle of the graph) and move on to the next vertex in the ordering. Thus one measurable difference between VORDER-pull and VORDER-push is that the degree of the vertex $u$ selected will generally be greater in VORDER-pull than in VORDER-push. We will measure this explicitly in our benchmarks.

## 2.3 The vertex label ordering

The VORDER-pull and VORDER-push heuristics, and also to a lesser extent, the MINDEG heuristic, also depend on the input permutation of the labels of the vertexes in $G$. All three heuristics are sensitive to this ordering with a random ordering producing a bad behavior. In [9], Haggard, Pearce and Royle state "using an ordering where vertexes with higher degree come lower in the ordering generally also gives better performance". Their idea is to increase the probability that more identical graphs appear *higher* in the computation tree. To achieve this we propose to label the vertexes in the input graph in an order so that the algorithm deletes and contracts edges *locally*. We found that the following vertex ordering heuristic works best amongst the orderings we tried. To simplify the presentation we assume $G$ is connected. We describe it below with pseudo-code and an example.

**Algorithm SHARC** - short arc order.

Input: An undirected connected graph $G$ on $n > 0$ vertexes $V = \{1, 2, ..., n\}$.

1. Initialize the ordered list $S = [1]$

2. **while** $|S| < n$ do the following

Using breadth first search (BFS), starting from the vertexes in $S$ find the first path from $S$ back to $S$ which includes at least one new vertex, that is, find a path $u \rightarrow v_1 \rightarrow v_2 \rightarrow ... \rightarrow v_m \rightarrow w$ where $u \in S, w \in S, m > 0, v_i \in V \setminus S$.

If such a path exists, append $v_1, v_2, ..., v_m$ to $S$. Otherwise ($G$ may have a cutedge) pick the least vertex $v_1$ not in $S$ but adjacent to a vertex in $S$ and append $v_1$ to $S$.

**end while**

3. **output** $S$.

We explain the algorithm with an example. Consider again the graph $G$ below.

<figure><img src="image_5.png" /></figure>

Initially we have $S = [1]$. Using BFS we insert all vertexes adjacent to the vertexes in $S$ not already in $S$ into a queue $Q$. In the example, we obtain $Q = [3, 4, 5]$. Hence we have paths $1 \rightarrow 3, 1 \rightarrow 4$ and $1 \rightarrow 5$ which we maintain in an array $P = [0, 0, 1, 1, 1]$, that is $P_3 = 1$ stores the edge from 3 to 1 and $P_1 = 0$ indicates the end of a path. We take the first vertex 3 from $Q$ and consider the new edge (3, 4). Since $P_4$ is not zero we know there is a path from 1 back to 4 stored in $P$. Since 3 came from $Q$ we know there is
a path from 1 to 3 stored in $P$. Thus we are done this iteration; we extract the path $1 \to 3 \to 4 \to 1$ from $P$ and append 3, 4 to $S$ obtaining $S = [1, 3, 4]$. In the second iteration the algorithm will find the path $1 \to 5 \to 2 \to 4$ and set $S = [1, 3, 4, 5, 2]$. Since $|S| = 5$ the algorithm stops. The reader can see that the algorithm finds a short cycle in the first iteration, then in the subsequent iterations, finds short arcs from $S$ back to $S$. We will call this ordering a short arc ordering (SHARC). By picking the first path found using BFS, the short arc ordering maintains locality in $S$. Although it would be simpler to order the vertexes in simple breadth first search order, that ordering did not prove to be as good as SHARC in our experiments.

# 3 Maple Implementation

We use a list of neighbors representation for a multi-graph in our Maple implementation. We illustrate with an example in Figure 5.

<figure><img src="image_6.png" /><figcaption>Fig. 5: Maple list of lists data structure for $G$</figcaption></figure>

To identify identical graphs in the computation tree we make use of *option remember*. This is a feature of the Maple programming language that enables our Maple procedure to automatically identify identical graphs in the computation tree using hashing. For this to work we must canonically re-label vertexes to be 1, 2, ..., $n-1$ after edge contraction.

To identify non-equal isomorphic graphs we have implemented our own graph isomorphism test for multi-graphs as the `IsIsomorphic` command in Maple's `GraphTheory` package (see [4]) treats simple graphs only. Instead of searching all previous graphs, we first hash on the characteristic polynomial of the Laplacian matrix of $G$, a known graph invariant. The Laplacian matrix is an $n$ by $n$ matrix $D - A$ where $D$ is the degree matrix of $G$ and $A$ is the adjacency matrix of $G$. For increased efficiency, we compute the characteristic polynomial of $D - A$ modulo a machine prime $p$. This can be computed in $O(n^3)$ arithmetic operations in $\mathbb{F}_p$. See Algorithm 2.2.9 in Chapter 2 of [2].

Our Maple code may be downloaded from http://www.cec.m.sfu.ca/~mmonagan/tutte

# 4 Experiments

## 4.1 Random cubic graphs

In this experiment we generated ten random connected cubic graphs on $n$ vertexes for $16 \le n \le 50$. Note, the probability that these graphs are biconnected is high so Theorem 1 is not applicable. Indeed all the graphs generated are biconnected. We computed the average and median time it takes our Maple program to compute the Tutte polynomial using the MINDEG, VORDER-pull and VORDER-push heuristics, on a 2.66 Ghz Intel Core i7 980 desktop with 6 GB RAM. We do this for two permutations of the vertex labels, random (see Table 1) and SHARC (the short arc ordering) (see Table 2). In all cases, we do not use an explicit graph isomorphism test; rather, we use Maple's `option remember`; facility so that
Tutte polynomials for identical graphs that appear in the computation tree are not recomputed. The data shows the SHARC ordering is much better than the input random ordering for both VORDER-pull and VORDER-push. The data also shows that VORDER-push with SHARC is much better than VORDER-pull with SHARC. We find similar results for random quartic graphs.

<table><caption>Tab. 1: Timings in CPU seconds for random cubic graphs with *n* vertices using random vertex order.</caption><thead><tr><th colspan="2"></th><th colspan="2">MINDEG heuristic</th><th colspan="2">VORDER pull</th><th colspan="2">VORDER push</th></tr><tr><th>n</th><th>m</th><th>ave</th><th>med</th><th>ave</th><th>med</th><th>ave</th><th>med</th></tr></thead><tbody><tr><td>16</td><td>24</td><td>0.41</td><td>0.36</td><td>0.18</td><td>0.11</td><td>0.22</td><td>0.14</td></tr><tr><td>18</td><td>27</td><td>1.21</td><td>1.02</td><td>0.53</td><td>0.33</td><td>0.57</td><td>0.45</td></tr><tr><td>20</td><td>30</td><td>3.90</td><td>3.38</td><td>1.27</td><td>1.02</td><td>1.86</td><td>1.46</td></tr><tr><td>22</td><td>33</td><td>14.40</td><td>12.07</td><td>4.65</td><td>3.36</td><td>7.22</td><td>6.88</td></tr><tr><td>24</td><td>36</td><td>56.24</td><td>32.19</td><td>13.84</td><td>9.23</td><td>25.05</td><td>22.46</td></tr><tr><td>26</td><td>39</td><td>193.34</td><td>118.98</td><td>41.03</td><td>20.07</td><td>58.94</td><td>24.57</td></tr><tr><td>28</td><td>39</td><td></td><td></td><td>199.70</td><td>116.32</td><td>210.69</td><td>75.24</td></tr></tbody></table>

<table><caption>Tab. 2: Timings in CPU seconds for random cubic graphs with *n* vertices using SHARC vertex order.</caption><thead><tr><th colspan="2"></th><th colspan="2">MINDEG heuristic</th><th colspan="2">VORDER pull</th><th colspan="2">VORDER push</th></tr><tr><th>n</th><th>m</th><th>ave</th><th>med</th><th>ave</th><th>med</th><th>ave</th><th>med</th></tr></thead><tbody><tr><td>18</td><td>27</td><td>0.68</td><td>0.51</td><td>0.05</td><td>0.03</td><td>0.02</td><td>0.02</td></tr><tr><td>22</td><td>33</td><td>7.73</td><td>4.68</td><td>0.38</td><td>0.14</td><td>0.10</td><td>0.07</td></tr><tr><td>26</td><td>39</td><td>80.11</td><td>38.45</td><td>1.24</td><td>0.41</td><td>0.17</td><td>0.12</td></tr><tr><td>30</td><td>45</td><td></td><td></td><td>11.10</td><td>4.36</td><td>0.67</td><td>0.37</td></tr><tr><td>34</td><td>51</td><td></td><td></td><td>94.58</td><td>19.15</td><td>2.06</td><td>1.29</td></tr><tr><td>38</td><td>57</td><td></td><td></td><td></td><td></td><td>5.40</td><td>2.83</td></tr><tr><td>42</td><td>63</td><td></td><td></td><td></td><td></td><td>40.66</td><td>8.82</td></tr><tr><td>46</td><td>69</td><td></td><td></td><td></td><td></td><td>87.63</td><td>49.03</td></tr><tr><td>50</td><td>75</td><td></td><td></td><td></td><td></td><td>179.64</td><td>39.61</td></tr></tbody></table>

## 4.2 Generalized Petersen graphs.

The generalized Petersen graph $P(n, k)$ with $1 \le k < n/2$ is a cubic graph on $2n$ vertexes. Figure 6 shows $P(5, 1)$ and $P(5, 2)$. $P(5, 2)$ is the familiar Petersen graph. To construct $P(n, k)$ the vertexes are divided into two sets $1, 2, ..., n$ and $n + 1, n + 2, ..., 2n$, which are placed on two concentric circles as shown in figure 6. The first set of vertexes are connected in a cycle $1, 2, ..., n, 1$. The second set are connected to the first with vertex $i$ connected to $n + i$ for $1 \le i \le n$. The second parameter governs how the second set is connected. Connect $n + i$ to $n + (n + i \pm k \mod n)$ for $1 \le i \le n$.

The SHARC vertex order for $P(5, 1)$ and $P(5, 2)$ is [1,2,7,6,10,5,4,3,8,9] and [1,5,4,3,2,8,6,9,10,7] respectively. In Tables 3 and 4 we compare the time it takes to compute the Tutte polynomials of $P(n, 3)$ for increasing *n* using the VORDER-pull (Table 3 and VORDER-push (Table 4). For the first set of
<figure><img src="image_7.png" /><figcaption>Fig. 6: Petersen graphs $P(5, 1)$ and $P(5, 2)$.</figcaption></figure>

timings in each table we apply a full graph isomorphism test for $|V| > 15$. For the second set of timings we identify identical graphs only in the computation tree only. Column #calls is the total number of recursive calls made by the algorithm. Column #ident counts the number of recursive calls for which the graph is identical to a graph previously computed in the computation tree. Column #isom counts the number of recursive calls for which the graph is not identical but isomorphic to a graph previously computed in the computation tree.

<table><caption>Tab. 3: Data for $P(n, 3)$ for VORDER-pull with the SHARC ordering.</caption><thead><tr><th colspan="3">VORDER-pull</th><th colspan="4">with isomorphism test</th><th colspan="3">no isomorphism test</th></tr><tr><th>n</th><th>|V|</th><th>m</th><th>#calls</th><th>#ident</th><th>#isom</th><th>time</th><th>#calls</th><th>#ident</th><th>time</th></tr></thead><tbody><tr><td>8</td><td>16</td><td>24</td><td>28641</td><td>10419</td><td>0</td><td>1.21</td><td>28641</td><td>10419</td><td>1.19</td></tr><tr><td>9</td><td>18</td><td>27</td><td>30235</td><td>9818</td><td>3</td><td>1.40</td><td>32693</td><td>10681</td><td>1.41</td></tr><tr><td>10</td><td>20</td><td>30</td><td>90772</td><td>31049</td><td>22</td><td>4.53</td><td>240600</td><td>85017</td><td>12.16</td></tr><tr><td>11</td><td>22</td><td>33</td><td>434402</td><td>149286</td><td>244</td><td>26.63</td><td>736447</td><td>259390</td><td>44.82</td></tr><tr><td>12</td><td>24</td><td>36</td><td>471530</td><td>152284</td><td>978</td><td>34.72</td><td>1217966</td><td>406976</td><td>87.89</td></tr><tr><td>13</td><td>26</td><td>39</td><td>1668636</td><td>552034</td><td>7072</td><td>177.33</td><td>5905078</td><td>2049833</td><td>730.16</td></tr><tr><td>14</td><td>28</td><td>42</td><td>4035615</td><td>1346519</td><td>45340</td><td>798.37</td><td>17437880</td><td>6062683</td><td>2805.78</td></tr><tr><td>15</td><td>30</td><td>45</td><td>6330229</td><td>2016961</td><td>149699</td><td>2149.02</td><td></td><td></td><td></td></tr></tbody></table>

In comparing the data for $P(n, 3)$, it's clear that VORDER-push (Table 4) is much better than VORDER-pull (Table 3). In fact, VORDER-push is polynomial time in $n$. The reader can see that the number of graphs (column #calls) is increasing linearly with $n$. We find the same linear increase for VORDER-push for $P(n, 1)$, $P(n, 2)$, $P(n, 3)$ and $P(n, 4)$. For $P(n, 5)$ and $P(n, 6)$ the data is not clear.

The data for $P(n, 3)$ also shows that a high percentage of isomorphic graphs in the computation tree are identical (compare columns #ident and #isom). The data shows that the explicit graph isomorphism test helps VORDER-pull (Table 3) but hurts the performance of VORDER-push (Table 4).

In Table 5 we show data for $P(n, 6)$. The irregularity of the data in Table 5 is partly explained by low girth. In particular, $P(18, 6)$ has 6 triangles. The girth of $P(n, k)$ is a minimum when $k$ divides $n$ where the girth is $n/k$. In Table 6 we fix $n$ to be 14 and vary $k$ to show the dependence on the girth.

## 4.3 The truncated icosahedron graph.

The Tutte polynomial of a planar graph $G$ and its dual $G^*$ are related by $T(G, x, y) = T(G^*, y, x)$. Shown in Figure 7 is the truncated icosahedron graph $TI$ and its dual $TI^*$.
<table><caption>**Tab. 4:** Data for $P(n, 3)$ for VORDER-push with the SHARC ordering.</caption><thead><tr><th colspan="3">VORDER-push</th><th colspan="4">with isomorphism test</th><th colspan="3">no isomorphism test</th></tr><tr><th>n</th><th>|V|</th><th>m</th><th>#calls</th><th>#ident</th><th>#isom</th><th>time</th><th>#calls</th><th>#ident</th><th>time</th></tr></thead><tbody><tr><td>8</td><td>16</td><td>24</td><td>2776</td><td>703</td><td>0</td><td>0.10</td><td>2776</td><td>703</td><td>0.09</td></tr><tr><td>10</td><td>20</td><td>30</td><td>4680</td><td>1119</td><td>6</td><td>0.31</td><td>6490</td><td>1634</td><td>0.23</td></tr><tr><td>12</td><td>24</td><td>36</td><td>7449</td><td>1828</td><td>16</td><td>0.79</td><td>9552</td><td>2487</td><td>0.40</td></tr><tr><td>14</td><td>28</td><td>42</td><td>40142</td><td>10639</td><td>192</td><td>7.66</td><td>46924</td><td>12962</td><td>2.34</td></tr><tr><td>16</td><td>32</td><td>48</td><td>62306</td><td>16316</td><td>691</td><td>26.04</td><td>77896</td><td>22103</td><td>4.41</td></tr><tr><td>18</td><td>36</td><td>54</td><td>88244</td><td>23154</td><td>1299</td><td>55.82</td><td>112280</td><td>32545</td><td>7.30</td></tr><tr><td>20</td><td>40</td><td>60</td><td>115682</td><td>30503</td><td>1996</td><td>105.72</td><td>148412</td><td>43676</td><td>11.30</td></tr><tr><td>22</td><td>44</td><td>66</td><td>143035</td><td>37734</td><td>2754</td><td>181.40</td><td>184852</td><td>54925</td><td>15.68</td></tr><tr><td>24</td><td>48</td><td>72</td><td>170917</td><td>45204</td><td>3501</td><td>289.46</td><td>221107</td><td>66114</td><td>21.70</td></tr><tr><td>26</td><td>52</td><td>78</td><td>198675</td><td>52641</td><td>4278</td><td>445.24</td><td>257671</td><td>77437</td><td>29.50</td></tr><tr><td>28</td><td>56</td><td>84</td><td>226615</td><td>60085</td><td>5071</td><td>674.25</td><td>294126</td><td>88700</td><td>39.07</td></tr><tr><td>30</td><td>60</td><td>90</td><td>254629</td><td>67585</td><td>5855</td><td>975.65</td><td>330379</td><td>99888</td><td>50.28</td></tr></tbody></table>

<table><caption>**Tab. 5:** Data for $P(n, 6)$ for VORDER-pull and VORDER-push.</caption><thead><tr><th colspan="2">VORDER-pull</th><th colspan="3">VORDER-push</th></tr><tr><th>k</th><th>girth</th><th>time(s)</th><th>#calls</th><th>#ident</th><th>time(s)</th><th>#calls</th><th>#ident</th></tr></thead><tbody><tr><td>13</td><td>5</td><td>85.55</td><td>875232</td><td>270060</td><td>0.30</td><td>6884</td><td>1715</td></tr><tr><td>14</td><td>6</td><td>1262.37</td><td>5524084</td><td>1807371</td><td>4.16</td><td>85103</td><td>23822</td></tr><tr><td>15</td><td>5</td><td></td><td></td><td></td><td>6.62</td><td>124203</td><td>35033</td></tr><tr><td>16</td><td>7</td><td></td><td></td><td></td><td>43.69</td><td>606569</td><td>177341</td></tr><tr><td>17</td><td>6</td><td></td><td></td><td></td><td>23.35</td><td>384107</td><td>112730</td></tr><tr><td>18</td><td>3</td><td></td><td></td><td></td><td>3.98</td><td>65379</td><td>16181</td></tr><tr><td>19</td><td>6</td><td></td><td></td><td></td><td>24.55</td><td>315584</td><td>87375</td></tr><tr><td>20</td><td>7</td><td></td><td></td><td></td><td>482.93</td><td>3647975</td><td>1081545</td></tr></tbody></table>

In [6], Haggard, Pearce and Royle report that they computed the Tutte polynomial for $TI^*$ in one week on 150 computers. They used the VORDER-pull heuristic. Using the VORDER-push heuristic, and the vertex ordering as shown in the figure 7, we computed the Tutte polynomial for $TI$ on a single core of a 2.66 Ghz Intel Core i7 desktop in under 4 minutes and 2.8 gigabytes, and for $TI^*$ in under 9 minutes and 8.8 gigabytes. Notice that the vertexes of $TI$ (and also $TI^*$) are numbered in concentric cycles. This was the ordering that we input the graph from a picture. Notice that the vertex ordering is a short arc ordering. This is why we tried the short arc ordering on other graphs.

## 4.4 Dense graphs.

Up to this point, the data shows that VORDER-push is much better than VORDER-pull. This, however, is not the case for dense graphs. In Table 7 we give data for the complete graphs $K_n$ on n vertexes. VORDER-pull is clearly better than VORDER-push.
<table><caption>**Tab. 6:** Data for $P(14, k)$. Column deg shows the average degree of the first vertex in the computation tree.</caption><thead><tr><th rowspan="2">k</th><th rowspan="2">girth</th><th colspan="3">VORDER-pull</th><th colspan="3">VORDER-push</th></tr><tr><th>time(s)</th><th>#calls</th><th>deg</th><th>time(s)</th><th>#calls</th><th>deg</th></tr></thead><tbody><tr><td>1</td><td>4</td><td>6.12</td><td>54040</td><td>6.48</td><td>0.16</td><td>693</td><td>2.10</td></tr><tr><td>2</td><td>5</td><td>209.33</td><td>1362412</td><td>5.19</td><td>0.65</td><td>4727</td><td>2.30</td></tr><tr><td>3</td><td>6</td><td>806.92</td><td>4035615</td><td>4.32</td><td>3.82</td><td>40142</td><td>2.47</td></tr><tr><td>4</td><td>7</td><td>2273.75</td><td>8430139</td><td>4.61</td><td>7.71</td><td>88579</td><td>2.49</td></tr><tr><td>5</td><td>6</td><td>1218.51</td><td>6208087</td><td>4.49</td><td>5.62</td><td>71717</td><td>2.50</td></tr><tr><td>6</td><td>6</td><td>979.73</td><td>5524084</td><td>4.44</td><td>6.43</td><td>71054</td><td>2.47</td></tr></tbody></table>

<figure><img src="image_8.png" /><figcaption>**Fig. 7:** The truncated icosahedron graph and its dual.</figcaption></figure>

## 4.5 Monitoring execution for large graphs.

For large graphs, the user of software for computing Tutte polynomials will need some way to know how far a large computation has progressed and how much memory has been consumed so that the user can stop the computation when it becomes obvious that it not going to terminate in a reasonable time. When the Tutte polynomial for a graph $G$ of size $n$ vertexes in the computation tree is computed for the first time, we display the additional time it took to compute $T(G)$ since the time it took to compute the Tutte polynomial for a graph of size $n-1$ for the first time, and the total space used after $T(G)$ is computed. In Table 8 and Table 9 we show the output of VORDER-push (VORDER-pull respectively) for the truncated icosahedron $TI$ (for $n > 20$). The reader can see that VORDER-pull will take a very long time.
<table><caption>**Tab. 7:** Data for $K_n$ for VORDER-pull and VORDER-push</caption><thead><tr><th colspan="2"></th><th colspan="4">VORDER-pull</th><th colspan="4">VORDER-push</th></tr><tr><th>n</th><th>m</th><th>time(s)</th><th>#calls</th><th>#ident</th><th>deg</th><th>time</th><th>#calls</th><th>#ident</th><th>deg</th></tr></thead><tbody><tr><td>10</td><td>45</td><td>0.08</td><td>2519</td><td>1002</td><td>7.40</td><td>0.24</td><td>7448</td><td>2826</td><td>4.84</td></tr><tr><td>11</td><td>55</td><td>0.18</td><td>5075</td><td>2024</td><td>8.27</td><td>0.64</td><td>17178</td><td>6667</td><td>5.25</td></tr><tr><td>12</td><td>66</td><td>0.46</td><td>10191</td><td>4070</td><td>9.12</td><td>1.72</td><td>38940</td><td>15372</td><td>5.70</td></tr><tr><td>13</td><td>78</td><td>1.07</td><td>20427</td><td>8164</td><td>10.02</td><td>4.57</td><td>87070</td><td>34829</td><td>6.10</td></tr><tr><td>14</td><td>91</td><td>2.43</td><td>40903</td><td>16354</td><td>10.90</td><td>12.64</td><td>192544</td><td>77838</td><td>6.54</td></tr><tr><td>15</td><td>105</td><td>6.10</td><td>81859</td><td>32736</td><td>11.81</td><td>39.00</td><td>421922</td><td>172047</td><td>6.95</td></tr><tr><td>16</td><td>120</td><td>16.36</td><td>163775</td><td>65502</td><td>12.71</td><td>113.42</td><td>917540</td><td>376848</td><td>7.37</td></tr><tr><td>17</td><td>136</td><td>46.25</td><td>327611</td><td>131036</td><td>13.64</td><td>273.40</td><td>1982502</td><td>819217</td><td>7.78</td></tr><tr><td>18</td><td>153</td><td>113.39</td><td>655287</td><td>262106</td><td>14.54</td><td></td><td></td><td></td><td></td></tr></tbody></table>

<table><caption>**Tab. 8:** Trace of time and space for the truncated icosahedron using VORDER-push. Total time 204.58 seconds.</caption><thead><tr><th>n</th><th>time(s)</th><th>space</th><th>n</th><th>time</th><th>space</th><th>n</th><th>time</th><th>space</th><th>n</th><th>time(s)</th><th>space</th></tr></thead><tbody><tr><td>21</td><td>0.06</td><td>0.067gb</td><td>31</td><td>0.84</td><td>0.100gb</td><td>41</td><td>4.60</td><td>0.258gb</td><td>51</td><td>25.32</td><td>1.167gb</td></tr><tr><td>22</td><td>0.09</td><td>0.090gb</td><td>32</td><td>0.00</td><td>0.100gb</td><td>42</td><td>5.61</td><td>0.340gb</td><td>52</td><td>22.60</td><td>1.443gb</td></tr><tr><td>23</td><td>0.17</td><td>0.095gb</td><td>33</td><td>1.32</td><td>0.120gb</td><td>43</td><td>0.00</td><td>0.340gb</td><td>53</td><td>0.01</td><td>1.443gb</td></tr><tr><td>24</td><td>0.00</td><td>0.095gb</td><td>34</td><td>0.00</td><td>0.120gb</td><td>44</td><td>1.36</td><td>0.360gb</td><td>54</td><td>0.20</td><td>1.451gb</td></tr><tr><td>25</td><td>0.10</td><td>0.095gb</td><td>35</td><td>0.18</td><td>0.120gb</td><td>45</td><td>5.52</td><td>0.443gb</td><td>55</td><td>25.12</td><td>1.786gb</td></tr><tr><td>26</td><td>0.00</td><td>0.095gb</td><td>36</td><td>0.00</td><td>0.120gb</td><td>46</td><td>10.98</td><td>0.619gb</td><td>56</td><td>12.77</td><td>1.950gb</td></tr><tr><td>27</td><td>0.34</td><td>0.095gb</td><td>37</td><td>1.93</td><td>0.150gb</td><td>47</td><td>0.00</td><td>0.619gb</td><td>57</td><td>0.00</td><td>1.950gb</td></tr><tr><td>28</td><td>0.00</td><td>0.095gb</td><td>38</td><td>0.00</td><td>0.150gb</td><td>48</td><td>12.69</td><td>0.757gb</td><td>58</td><td>6.82</td><td>2.058gb</td></tr><tr><td>29</td><td>0.55</td><td>0.095gb</td><td>39</td><td>3.15</td><td>0.193gb</td><td>49</td><td>10.52</td><td>0.880gb</td><td>59</td><td>43.38</td><td>2.679gb</td></tr><tr><td>30</td><td>0.00</td><td>0.095gb</td><td>40</td><td>0.00</td><td>0.193gb</td><td>50</td><td>0.01</td><td>0.880gb</td><td>60</td><td>8.13</td><td>2.761gb</td></tr></tbody></table>

# 5 Conclusion

We have presented a new edge selection heuristic that we call VORDER-push for computing the Tutte polynomial of a graph using the edge deletion and contraction algorithm. We find that for sparse graphs, VORDER-push outperforms VORDER-pull and the other heuristics considered by Haggard, Pearce and Royle in [9] by several orders of magnitude and which significantly increases the range of graphs that can be computed for what is an NP-hard problem. For some graphs, including grid graphs and the Petersen graphs $P(n, k)$ for $1 \le k \le 4$, our new heuristic automatically finds polynomial time constructions for the Tutte polynomial. At this point we only have a partial understanding of why and when VORDER-push is so effective. Graphs with large girth appear to be more difficult.

We are integrating our new heuristic into the TuttePolynomial command in Maple's GraphTheory package. This should become available in Maple 17. The overall improvement is huge. For example, for the dodecahedron graph, a cubic graph with 20 vertices and 30 edges, the time to compute the Tutte polynomial improves from 162.093 seconds in Maple 16 to 0.219 seconds. The GraphTheory package [4, 3] has been under development since 2004. We have also installed a command for computing the reliability polynomial $R_p(G)$ in the package. Our improvement for computing $T(G, x, y)$ will automatically improve Maple's performance for computing the chromatic polynomial $P_\lambda(G)$ and other related
<table><caption>**Tab. 9:** Trace of time (in seconds) and space for the truncated icosahedron using VORDER-pull.</caption><thead><tr><th>n</th><th>time(s)</th><th>space</th><th>n</th><th>time</th><th>space</th><th>n</th><th>time</th><th>space</th><th>n</th><th>time(s)</th><th>space</th></tr></thead><tbody><tr><td>21</td><td>0.08s</td><td>0.085gb</td><td>27</td><td>1.04s</td><td>0.099gb</td><td>33</td><td>7.44s</td><td>0.241gb</td><td>39</td><td>205.00s</td><td>1.532gb</td></tr><tr><td>22</td><td>0.00s</td><td>0.085gb</td><td>28</td><td>0.00s</td><td>0.099gb</td><td>34</td><td>0.00s</td><td>0.241gb</td><td>40</td><td>0.10s</td><td>1.532gb</td></tr><tr><td>23</td><td>0.36s</td><td>0.095gb</td><td>29</td><td>1.88s</td><td>0.115gb</td><td>35</td><td>14.77s</td><td>0.340gb</td><td>41</td><td>399.84s</td><td>3.115gb</td></tr><tr><td>24</td><td>0.00s</td><td>0.095gb</td><td>30</td><td>0.00s</td><td>0.115gb</td><td>36</td><td>0.20s</td><td>0.341gb</td><td>42</td><td>0.01s</td><td>3.115gb</td></tr><tr><td>25</td><td>0.73s</td><td>0.095gb</td><td>31</td><td>5.22s</td><td>0.160gb</td><td>37</td><td>0.00s</td><td>0.341gb</td><td>43</td><td>758.37s</td><td>6.205gb</td></tr><tr><td>26</td><td>0.00s</td><td>0.095gb</td><td>32</td><td>0.00s</td><td>0.160gb</td><td>38</td><td>59.27s</td><td>0.661gb</td><td>44</td><td>&gt;1500s</td><td>&gt;14gb</td></tr></tbody></table>

polynomials.

## References

[1] Béla Bollobás. *Modern Graph Theory*. Springer Graduate Texts in Mathematics. No. 184, 1998.

[2] Henri Cohen. *A Course in Computational Algebraic Number Theory*. Springer-Verlag Graduate Texts in Mathematics. No. 138, 1993.

[3] M. Ebrahimi, M. Ghebleh, M. Javadi, M. Monagan, and A. Wittkopf. A Graph Theory Package for Maple, Part II: Graph Coloring, Graph Drawing, Support Tools, and Networks. *Maple Conference 2006 Proceedings*, MapleSoft, ISBN 1-897310-13-7, pp. 99–112, July 2006. Also available at http://www.cecm.sfu.ca/CAG/papers/GT2006.pdf.

[4] Jeff Farr, Mahdad Khatarinejad, Sara Khodadad, and Michael Monagan. A Graph Theory Package for Maple. *Proceedings of the 2005 Maple Conference*, pp. 260–271, Maplesoft, 2005. Also available at http://www.cecm.sfu.ca/CAG/papers/GTpaper.pdf.

[5] Chris Godsil and Gordon Royle. *Algebraic Graph Theory*. Springer-Verlag Graduate Texts in Mathematics 207, 2001.

[6] Gary Haggard, David Pearce, and Gordon Royle. Computing Tutte Polynomials. *Transactions on Mathematical Software* 37:3 (2011) article 24.

[7] Brendan Mckay. The nauty page. http://cs.anu.edu.au/~bdm/nauty/

[8] James Oxley and Dominic Welsh. Chromatic, Flow and Reliability Polynomials: The Complexity of their Coefficients. *J. Combinatorics, Probability and Computing* 11 (2002) 403–426.

[9] Pearce D.J., Haggard G., Royle G. Edge-Selection Heuristics for Computing Tutte Polynomials. *Chicago J. of Theoretical Computer Science*, Vol. 2010, (2010) article 6.

[10] William Tutte. A contribution to the theory of chromatic polynomials. *Can. J. Math.* 6 (1954) 80–91.