1 Introduction

It is a known fact that in any simple graph \(G\) there are at least two vertices of the same degree. The situation changes if we consider multigraphs. Each multiple edge may be represented with some integer label and the (weighted) degree of any vertex \(x\) is then calculated as the sum of labels over all edges incident to \(x\). The maximum label \(s\) is called the strength of the labelling. The labelling itself is called irregular if the weighted degrees of all the vertices are distinct. The smallest value of \(s\) that allows some irregular labelling is called irregularity strength of \(G\) and denoted by \(s(G)\).

The problem of finding \(s(G)\) was introduced by Chartrand et al. (1988) and investigated by numerous authors. The best published result, due to Kalkowski et al. (2011), is \(s(G)\le 6n/\delta \). There are some signals that it was recently improved by Majerski and Przybyło (2013) for dense graphs of sufficiently big order (\(s(G)\le (4+o(1))n/\delta +4\) in this case). The exact value of \(s(T)\) for a tree \(T\) was investigated e.g. by Aigner and Triesch (1990), Amar and Togni (1998), Ferrara et al. (2010) and Togni (1998).

On the other hand, numerous authors studied various labelling problems when elements of finite Abelian groups were used instead of integers to label either vertices or edges of graph. We give only few examples here. Graham and Sloane (1980) studied harmonious graphs, i.e., graphs for which there exists an injection \(f:V(G)\rightarrow \mathbb Z _q\) that assigns to every edge \((x,y)\in E(G)\) unique sum \(f(x)+f(y)\) modulo \(q\). Beals et al. (1991) considered the concept of harmoniousness with respect to arbitrary Abelian groups. Żak (2009) generalized the problem and introduced new parameter, harmonious order of \(G\), the smallest number \(t\) such that injection \(f:V(G)\rightarrow \mathbb Z _t\) (or surjection if \(t<V(G)\)) produces distinct edge sums. Hovey (1991) considers the so-called \(A-cordial\) labellings, where for a given Abelian group \(A\) and a graph \(G\) one wants to obtain a vertex labelling such that the classes of vertices labelled with one label are (almost) equinumerous and so are the classes of edges with the same sums. Cavenagh et al. (2006) consider edge-magic total labellings with finite Abelian groups, i.e., the labelings of vertices and edges resulting in equal edge sums. Froncek (2013) defined the notion of group distance magic graphs, i.e., graphs allowing the bijective labelling of vertices with elements of an Abelian group resulting in constant sums of neighbour labels. Stanley (1973) studied vertex-magic labellings of edges with the elements of an Abelian group \(A\), i.e., labellings where the resulting weighted degrees are constant. Kaplan et al. (2009) considered vertex-antimagic edge labellings, i.e., bijections \(f:E(G)\rightarrow A\), where \(A\) is a cyclic group, resulting in distinct weighted degrees of vertices.

The problems considered in the paper fit within the framework of the research conducted thus far on both irregular labellings and labellings from Abelian groups. Assume we are given an arbitrary graph \(G\) of order \(n\) with no components isomorphic to \(K_1\) or \(K_2\). Assume \(\mathcal G \) is an Abelian group of order \(m\ge n\) with the operation denoted by \(+\) and identity element \(0\). For convenience we will write \(ka\) to denote \(a+a+\dots +a\) (where element \(a\) appears \(k\) times), \(-a\) to denote the inverse of \(a\) and we will use \(a-b\) instead of \(a+(-b)\). Moreover, the notation \(\sum _{a\in S}{a}\) will be used as a short form for \(a_1+a_2+a_3+\dots \), where \(a_1, a_2, a_3, \dots \) are all the elements of the set \(S\).

Given an edge labelling \(f:E(G)\rightarrow \mathcal G \), we define the weighted degree of a vertex \(v\) to be

$$\begin{aligned} w(v)=\sum _{e\ni v}{f(e)}. \end{aligned}$$

We call \(f\) \(\mathcal G \) -irregular if all the weighted degrees are distinct. The group irregularity strength of \(G\), denoted \(s_g(G)\), is the minimum integer value \(s\) such that for every Abelian group \(\mathcal G \) of order \(s\) there exists a \(\mathcal G \)-irregular labelling \(f\) of \(G\). The main result of our paper is the following theorem, determining the value of \(s_g(G)\) for every connected graph \(G\) of order \(n\ge 3\).

Theorem 1

Let \(G\) be arbitrary connected graph of order \(n\ge 3\). Then

$$\begin{aligned} s_g(G)={\left\{ \begin{array}{ll} n+2&{}\quad \,when\, G\cong K_{1,3^{2q+1}-2} \,for\,some\,integer\, q\ge 1\\ n+1&{}\quad \,when\, n\equiv 2 (\text{ mod }\, 4) \wedge G\not \cong K_{1,3^{2q+1}-2} \,for\,any\,integer\, q\ge 1\\ n&{}\quad otherwise \end{array}\right. } \end{aligned}$$

We also show that the following theorem is true.

Theorem 2

Let \(G\) be arbitrary connected graph of order \(n\ge 3\). Then, for every \(k>s_g(G)\) and every finite Abelian group \(\mathcal G \) of order \(k\), \(G\) admits a \(\mathcal G \)-irregular labelling, except for the cases when:

  • \(G\cong K_{1,n-1}\) and \(\mathcal G \cong \mathbb Z _3\times \mathbb Z _3\times \dots \times \mathbb Z _3=(\mathbb Z _3)^q\) for some \(q\) such that \(3^q= n+1\)

  • \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _2\times \ldots \times \mathbb Z _2=(\mathbb Z _2)^q\) for some \(q\) such that \(2^q=n+2\).

2 Proof of Theorem 1

In order to distinguish \(n\) vertices in the graph we need at least \(n\) distinct elements of \(\mathcal G \). However, \(n\) elements are not always enough, as shows the following lemma.

Lemma 1

Let \(G\) be of order \(n\), if \(n \equiv 2 (\text{ mod }4)\), then \(s_g(G) \ge n+1\).

Proof

We prove the Lemma by contradiction. Let \(\mathcal G \) be an Abelian group of order \(n=2(1+2k)\). The fundamental theorem of finite Abelian groups states that the finite Abelian group \(\mathcal G \) can be expressed as the direct sum of cyclic subgroups of prime-power order. This implies that \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _{p_{1}^{\alpha _1}}\times \mathbb Z _{p_{2}^{\alpha _2}}\times \ldots \times \mathbb Z _{p_{m}^{\alpha _m}}\), where \(n=2\prod _{i=1}^m{p_i^{\alpha _i}}\) and \(p_i>2\) for \(i=1,\dots ,m\) are not necessarily distinct primes. This implies that one can write \(a \in \mathcal G \) as \(a=(a_0,a_1,\ldots ,a_m)\). Notice that in the group \(\mathcal G \) we have \(1+2k\) elements with the first coordinate \(0\) and \(1+2k\) with the first coordinate \(1\). Let now \(w(G)=\sum _{v \in V(G)}w(v)=\sum _{a\in \mathcal G }a\). Observe that \(w(G)\) is a vector with the first coordinate \(1\) (since we are summing in \(\mathbb Z _2\)). On the other hand \(w(G)=\sum _{v \in V(G)}(\sum _{ev}f(e))\), so each label \(f(e)\) for any \(e \in E(G)\) appears in the sum twice. Therefore \(w(G)\) is a vector with the first coordinate \(0\) (since we are summing in \(\mathbb Z _2\)), a contradiction. \(\square \)

We continue with the following lemma, determining the group irregularity strength of stars.

Lemma 2

Let \(K_{1,n-1}\) be a star with \(n-1\) pendant vertices and \(n\ge 3\). Then

$$\begin{aligned} s_g(K_{1,n-1})\!=\!{\left\{ \begin{array}{ll} n\!+\!2&{}\quad \,when\, n\equiv 2\, (\text{ mod }4) \wedge n=3^q-1 \,for\, some\, integer\, q\ge 1\\ n\!+\!1&{}\quad \,when\, n\equiv 2\, (\text{ mod }4) \wedge n\ne 3^q-1 \,for\, any\, integer\, q\ge 1\\ n&{}\quad otherwise. \end{array}\right. } \end{aligned}$$

Proof

Case 1: \(n\) is odd.

We put all the elements of \(\mathcal G \) other than \(0\) on the pendant edges and obtain this way distinct weighted degrees (same as edge labels) on the leafs and weighted degree \(0\) in the central vertex.

Case 2: \(n=4k\) for some \(k\ge 1\).

We distinguish two cases, depending on the number of involutions.

If there is only one involution, then it is guaranteed that there exists a subgroup of \(\mathcal G \) isomorphic with \(\mathbb Z _4\): \(\{0,a,2a,3a\}\) (\(2a\) is the only involution here). In such a situation we label the edges with all the elements of \(\mathcal G \) except \(3a\), assigning this way the same values to the weighted degrees of all the pendant vertices. It is straightforward to check that the weighted degree of central vertex is \(3a\).

If there are at least two involutions, then the sum of all the elements of \(\mathcal G \) is \(0\) (see e.g. Combe et al. 2004, Lemma 8). We put on the edges all the elements of \(\mathcal G \) but \(0\) and thus obtain distinct weighted degrees of pendant vertices not equal to \(0\) and weighted degree \(0\) of the central vertex.

Case 3: \(n=4k+2\) for some natural \(k\ge 1\).

In this case the order of \(\mathcal G \) must be at least \(4k+3\) by Lemma 1. If \(|\mathcal G |=4k+3\), then there is no involution in \(\mathcal G \). We distinguish two cases, depending on the orders of the elements of \(\mathcal G \).

If there is an element \(a\) in \(\mathcal G \) of order more than \(3\), then we assign to three edges labels \(a\), \(-2a\) and \(0\) and we put \(2k-1\) pairs \(\{a_j,-a_j\}\), where \(a_j\not \in \{0,a,-a,2a,-2a\}\), on the remaining edges, obtaining this way the \(\mathcal G \)-irregular labelling.

If all the elements of \(\mathcal G \) have order \(3\), then \(n=3^q-1\). Let \(\mathcal G \cong \mathbb Z _3\times \mathbb Z _3\times \dots \times \mathbb Z _3\). Assume we are able to label \(K_{1,n-1}\) with \(n+1\) labels from \(\mathcal G \). In such a situation we would have to use \(n-1\) distinct elements of \(\mathcal G \) on the edges, which would leave us two distinct elements, say \(a_1\) and \(a_2\). The weighted degree of the central vertex would be \(-(a_1+a_2)\). This number should be distinct from all other degrees, so one of the equalities \(-(a_1+a_2)=a_1\) or \(-(a_1+a_2)=a_2\) should be satisfied. In both cases it follows that \(a_1=a_2\), contradiction.

Thus we have to use a group \(\mathcal G \) of order at least \(n+2=4k+4\) in order to obtain a \(\mathcal G \)-irregular labelling. Observe that \(n+2\) can not be equal to \(2^p\) for any natural number \(p\) (this follows from the Mihǎilescu Theorem, also known as the Catalan Conjecture, see Mihǎilescu 2004). Thus in any group of order \(n+2\) there are two distinct elements \(a_1\) and \(a_2\) such that \(a_1+a_2=0\).

If there is more than one involution in \(\mathcal G \), then we label the edges with all the elements of \(\mathcal G \) but \(0\), \(a_1\) and \(a_2\) and obtain this way the sum \(0\) at the central vertex, distinct from all the other weighted degrees.

If there is exactly one involution \(i\) in \(\mathcal G \), then \(\mathcal G \) has a subgroup \(\mathcal G _1\) isomorphic with \(\mathbb Z _4\): \(\mathcal G _1=\{0,a,2a=i,3a\}\). Thus we can put \(0\), \(a\) and \(2a\) on three of the edges of the star. The remaining \(4k\) elements of \(\mathcal G \) form \(2k\) distinct pairs \(\{a_j,-a_j\}\) such that \(a_j\not \in \mathcal G _1\), so we can put \(2k-1\) of them on the remaining edges. Finally the central vertex obtains the weight \(3a\) and all the vertex weights are distinct. \(\square \)

Now we are going to determine the value of \(s_g(K_{1,n-1})\) for arbitrary tree \(T\) not being a star.

Lemma 3

Let \(T\) be arbitrary tree on \(n\ge 3\) vertices not being a star. Then

$$\begin{aligned} s_g(T)={\left\{ \begin{array}{ll} n+1&{} \,when\, n\equiv 2\, (\text{ mod }\,4) \\ n&{} otherwise. \end{array}\right. } \end{aligned}$$

Proof

Assume we properly colored the vertices of \(T\) with two colors, obtaining color classes \(V_1\) and \(V_2\). Given any two vertices \(x_1\) and \(x_2\), there exists unique path \(P(x_1,x_2)\) that joins them. If \(x_1\) and \(x_2\) belong to the same color class, then the path consists of odd number of vertices and even number of edges (we will call such a path odd path). If \(x_1\) and \(x_2\) belong to distinct color classes, then the path consists of even number of vertices and odd number of edges (we will call such a path even path).

We start with \(0\) on all the edges of \(T\). Then, in every step, we will add some labels to all the edges of chosen path \(P(x_1,x_2)\). To be more specific, we will add some label \(a\) to all the edges having odd position on the path (starting from \(x_1\)) and \(-a\) to all the edges having even position. We will denote such a modification in the edge labelling by \(\phi (x_1,x_2)=a\). Observe that if \(P(x_1,x_2)\) is odd, then putting \(\phi (x_1,x_2)=a\) increases the weighted degree of \(x_1\) by \(a\) and the weighted degree of \(x_2\) by \(-a\). If \(P(x_1,x_2)\) is even, then the weighted degrees of \(x_1\) and \(x_2\) increase by \(a\). In both cases the weighted degrees of the remaining vertices stay unchanged.

We are going to consider three cases.

Case 1: \(n=2k+1\) for some integer \(k\ge 1\).

Let \(\mathcal G \) be an arbitrary Abelian group of order \(n\). As \(\mathcal G \) does not have any elements of order \(2\), we can choose \(k\) elements \(a_1, a_2,\dots , a_k\in \mathcal G \) such that \(a_i\not \in \{a_j,-a_j\}\) for \(i\ne j\) and \(a_i\ne 0\) for \(1\le i\le k\). One of the color classes of \(V(T)\), say \(V_1\), has odd number of vertices and \(V_2\) even. We join the vertices of \(V_2\) in pairs, then do the same with all the vertices in \(V_1\) but one, say \(x_0\). We obtained this way exactly \(k\) monochromatic pairs \((x_{j,1},x_{j,2})\). Now we put \(\phi (x_{j,1},x_{j,2})=a_j\), for \(1\le j\le k\). This way we obtain the \(\mathcal G \)-irregular weighting: \(w(x_0)=0\), \(w(x_{j,1})=a_j\) for \(1\le j\le k\), \(w(x_{j,2})=-a_j\) for \(1\le j\le k\).

Case 2: \(n=4k\) for some integer \(k\ge 1\).

We distinguish two subcases, depending on the number of involutions in \(\mathcal G \).

Case 2.1: There is only one involution in \(\mathcal G \).

If there is only one involution in \(\mathcal G \), then there exists a subgroup \(\{0, a, 2a, 3a\}\) of \(\mathcal G \), where \(2a\) is the only element of order \(2\) in \(\mathcal G \). In such a case we choose two vertices \(x_1\), \(x_2\) from one of the color classes and one vertex \(x_0\) from the other one. We put \(\phi (x_0,x_1)=a\) and \(\phi (x_0,x_2)=2a\), obtaining this way \(w(x_1)=a\), \(w(x_2)=2a\) and \(w(x_0)=3a\). The number of the remaining vertices in one of the color classes is now odd and in the second one even. Thus we can proceed as in the case of \(n\) odd, using the remaining labels \(\{a_j,-a_j\}\) such that \(a_j\not \in \{a,2a,3a\}\) and obtaining this way \(\mathcal G \)-irregular labelling of \(T\).

Case 2.2: The number of involutions \(r>1\).

If there are more involutions \(a_1, a_2,\dots , a_r\), then their number \(r\) is odd and their sum equals \(0\) (see e.g. Combe et al. (2004), Lemma 8).

If \(r\le n/2\), then we choose one vertex \(x_0\) from the color class with less vertices (say \(V_p\)) and \(r\) vertices \(x_1\), \(x_2\), \(\dots \), \(x_r\) from \(V_{3-p}\) and we put \(\phi (x_0,x_j)=a_j\) for \(j=1,\dots ,r\). This way we obtain \(w(x_0)=0\) and \(w(x_j)=a_j\) for \(j=1,\dots ,r\). If the numbers of the remaining vertices in \(V_1\) and \(V_2\) are both even, we continue like in the case of \(n\) odd (this time we do not obtain \(w(x)=0\) for any new vertex). If both numbers are odd, we choose one vertex \(x_{r+1}\) from \(V_p\) and any element \(a_{r+1}\not \in \{0,a_1,\dots , a_r\}\). By putting \(\phi (x_0,x_{r+1})=a_{r+1}\) we obtain finally \(w(x_0)=a_{r+1}\) and \(w(x_{r+1})=-a_{r+1}\). Now the number of remaining vertices in \(V_p\) is even and in \(V_{3-p}\) odd. Since \(w(v)\ne 0\) for any previously considered vertex \(v\), we can proceed as in the case of \(n\) odd.

If \(r>n/2\), then \(\mathcal G \cong \mathbb Z _2\times \mathbb Z _2\times \dots \times \mathbb Z _2\) and all the elements of \(\mathcal G \) but \(0\) have order \(2\). In such case we chose any vertex \(x_0\) of \(T\) and put \(\phi (x_0,x_j)=a_j\) for \(j=1,\dots , n-1\) for distinct elements \(a_j\ne 0\). This way we obtain \(w(x_j)=a_j\ne 0\) for \(j=1,\dots , n-1\) and \(w(x_0)=0\).

Case 3: \(n=4k+2\) for some integer \(k\ge 1\).

If \(n=4k+2\), then we will use a group of order \(n+1\). We have to distinguish two cases.

If both color classes of \(T\) are even, then we proceed as in the case when \(n\) is odd (the difference is that there is no vertex \(x_0\) with \(w(x_0)=0\)).

Suppose that both color classes are odd. We will reduce their sizes in such a way that they both become even.

If there is an element of \(\mathcal G \) of order greater than \(3\), say \(a\), then we select three arbitrary vertices \(x_1\), \(x_2\), \(x_3\) from one color class and any vertex \(x_0\) from the other one and we put \(\phi (x_1,x_0)=a\), \(\phi (x_2,x_0)=-2a\), \(\phi (x_3,x_0)=0\). This way we obtain the following weighted degrees: \(w(x_0)=-a\), \(w(x_1)=a\), \(w(x_2)=-2a\), \(w(x_3)=0\). As we can easily see, these degrees are distinct and we still have \(k-2\) pairs of elements \(\{a_j,-a_j\}\) to label the remaining vertices as in the previous cases, as no element in the pairs \(\{a_j,-a_j\}\) belongs to the set \(\{-2a,-a,0,a,2a\}\).

If all the elements of \(\mathcal G \) have order \(3\), then \(n\ge 26\) (in fact, we need only \(n\ge 10\)). We choose \(a, b, c\in \mathcal G \) such that \(a\ne 0\), \(b\ne 0\), \(c\ne 0\), \(a\not \in \{b,-b\}\), \(c\not \in \{a, -a, b, -b, a+b, -(a+b), a-b, b-a\}\). As \(T\) is not star and both color classes are odd, each of them contains at least \(3\) vertices. Thus we can choose five vertices \(x_1\), \(x_2\), \(x_3\), \(x_4\), \(x_5\) from one color class and three \(y_1\), \(y_2\), \(y_3\) from another one. Now we put \(\phi (x_1, y_1)=a\), \(\phi (x_2, y_1)=a\), \(\phi (x_2, y_2)=2a+b\), \(\phi (x_3, y_2)=a+b\), \(\phi (x_3, y_3)=2a+2b+c\), \(\phi (x_4, y_3)=a+b+c\), \(\phi (x_5, y_3)=0\). This way we obtain \(8\) distinct weighted degrees \(w(x_1)=a\), \(w(x_2)=b\), \(w(x_3)=c\), \(w(x_4)=a+b+c\not \in \{0,a,b,c,-a,-b,-c\}\), \(w(x_5)=0\), \(w(y_1)=-a\), \(w(y_2)=-b\), \(w(y_3)=-c\) and we still have \(2k-3\) pairs \(\{a_j,-a_j\}\) to distinguish remaining even numbers of vertices in both color classes. \(\square \)

Theorem 1 follows easily from the above lemmas. If \(G\) is a star, then we use Lemma 2. Otherwise we choose any spanning tree of \(G\) not being a star, and use Lemmas 3 and 1, labelling all the remaining edges with \(0\).

3 Proof of Theorem 2

Before we prove Theorem 2, we need the following technical lemma that was proved in Anholcer and Cichacz (2013).

Lemma 4

[(Anholcer and Cichacz 2013)] Let \(\mathcal G \) be an Abelian group with involutions set \(I^\star =\{i_1,\dots , i_{2^k-1}\}\), \(k\ge 2\) and let \(I=I^\star \cup \{0\}\). Then for any given \(r\) such that \(0\le r \le 2^k\), there exists set \(R\subseteq I\), \(|R|=r\), such that

$$\begin{aligned} \sum _{i\in R}{i}=0 \end{aligned}$$

if and only if \(r\not \in \{2,2^k-2\}\).

In the next step we are going to show the construction of desired labelling for stars.

Lemma 5

Let \(K_{1,n-1}\) be a star with \(n-1\) pendant vertices and \(n\ge 3\). Then \(K_{1,n-1}\) admits \(\mathcal G \)-irregular labelling for any finite Abelian group \(\mathcal G \) of order \(k> s_g(K_{1,n-1})\) except the cases when \(\mathcal G \cong \mathbb Z _3\times \mathbb Z _3\times \dots \times \mathbb Z _3=(\mathbb Z _3)^q\) for some \(q\) such that \(3^q= n+1\) and \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _2\times \ldots \times \mathbb Z _2=(\mathbb Z _2)^q\) for some \(q\) such that \(2^q=n+2\).

Proof

We can write \(k=2^{p}(2m+1)\) for some natural numbers \(p\) and \(m\). We are going to distinguish two cases, depending on the number of the involutions in \(\mathcal G \).

Case 1: There exists at most one involution \(i \in \mathcal G \).

If \(n\) is odd then we put \(\frac{n-1}{2}\) pairs \(\{a_j,-a_j\}\) (\(a_j \ne 0\)) on the pendant edges and obtain this way distinct weighted degrees (same as edge labels) on the leafs and the weighted degree \(0\) in the central vertex.

If \(n\) is even and there is an element \(a\in \mathcal G \) of order more than \(3\), then we assign to three edges labels \(a\), \(-2a\) and \(0\) and we put \(\frac{n-4}{2}\) pairs \(\{a_j,-a_j\}\), where \(a_j\not \in \{0,a,-a,2a,-2a\}\), on the remaining edges, obtaining this way the \(\mathcal G \)-irregular labelling of \(G\) (such number of pairs exist, as \(k>n\)).

If \(n\) is even and all the elements of \(\mathcal G \) have order less than \(4\) and there exists the involution \(i \in \mathcal G \) then \(k\ge n+2\) (as \(k\) is even) and we assign to three edges labels \(a\), \(i\) and \(0\) and we put \(\frac{n-4}{2}\) pairs \(\{a_j,-a_j\}\), where \(a_j\not \in \{0,a,-a,i,a+i,-a+i\}\), on the remaining edges, obtaining this way the \(\mathcal G \)-irregular labelling.

Finally, if all the elements of \(\mathcal G \) have order \(3\), then \(k=3^r\) for some \(r\) and \(\mathcal G \cong \mathbb Z _3\times \mathbb Z _3\times \dots \times \mathbb Z _3\).

If now \(n+1=k\), then \(s_g(G)=n\) (recall that \(k>s_g(G)\)) and \(n\equiv 0 (\text{ mod }\,4)\) by Theorem 1. Assume that we are able to label \(K_{1,n-1}\) with \(n+1\) labels from \(\mathcal G \). In such a situation we would have to use \(n-1\) distinct elements of \(\mathcal G \) on the edges, which would leave us two distinct elements, say \(a_1\) and \(a_2\). The weighted degree of the central vertex would be \(-(a_1+a_2)\). This number should be distinct from all other degrees, so one of the equalities \(-(a_1+a_2)=a_1\) or \(-(a_1+a_2)=a_2\) should be satisfied. In both cases it follows that \(a_1=a_2\), contradiction.

Thus we have to use the group \(\mathcal G \) of order at least \(n+2\) in order to obtain \(\mathcal G \)-irregular labelling. Observe that \(n+2\) can not be equal to \(2^p\) for any natural number \(p\) (this follows from the Mihǎilescu Theorem, also known as the Catalan Conjecture, see Mihǎilescu 2004). Thus in any group of order \(n+2\) there are two distinct  elements \(a_1\) and \(a_2\) such that \(a_1+a_2=0\). We label the edges with all the elements of \(\mathcal G \) but \(0\), \(a_1\) and \(a_2\) and obtain this way the sum \(0\) at the central vertex, distinct from all the other weighted degrees. Thus we can assume that \(n+3\le k\) and we assign to three edges labels \(a\), \(b\ne 2a\) and \(2a+2b\) and we put \(\frac{n-4}{2}\) pairs \(\{a_j,-a_j\}\), where \(a_j\not \in \{0,a,2a,b,2b,a+b,2a+2b\}\), on the remaining edges, obtaining this way the \(\mathcal G \)-irregular labelling.

Case 2: There exist \(t>1\) involutions \(i_1,\ldots ,i_t\) in \(\mathcal G \).

Recall that \(t=2^q-1 \) for some \(1<q\le p\) and \(\sum _{j=1}^ti_t=0\) (see e.g. Combe et al. 2004, Lemma 8). Let \(I^\star \) denote the set of all the involutions and let \(I=I^\star \cup \{0\}\). We will consider three subcases, depending on the relation between \(n\) and \(t\).

Case 2.1: \(t\le n\).

If \(n\) is even, then we put \(i_j\), where \(j=1,\dots ,t\), on \(t\) edges and \((n-t-1)/2\) distinct pairs \(\{x_l,-x_l\}\) on the remaining edges.

If \(n\) is odd, then we put \(i_j\), where \(j=1,\dots ,t-1\) on \(t-1\) edges and \((n-t)/2\) distinct pairs \(\{x_l,-x_l\}\) on the remaining edges. This way the leafs obtain distinct weighted degrees same as edge labels and the central degree obtains weighted degree either \(0\) (when \(n\) is even) or \(i_t\) (when \(n\) is odd).

Case 2.2: \(t=n+1\).

Obviously \(n\) is even.

If there exists an element \(a\in \mathcal G \) such that \(2a \ne 0\), then we assign to two edges labels \(a\), \(-a\). Using Lemma 4, we can choose \(n-2=2^{q}-4\) elements \(i_{j_1},i_{j_2},\ldots ,i_{j_{n-2}}\in I\), such that

$$\begin{aligned} \sum _{l=1}^{n-2}i_{j_l}=0. \end{aligned}$$

We put the elements \(i_{j_1},i_{j_2},\ldots ,i_{j_{n-3}}\) on the remaining edges, obtaining this way the \(\mathcal G \)-irregular labelling.

If there is no element \(a \in \mathcal G \) such that \(2a \ne 0\), then \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _2\times \ldots \times \mathbb Z _2\) and \(k=2^p=n+2\). Let us assume that we managed to distinguish all the vertices and we did not use labels \(a,b \in \mathcal G \) (\(a\ne b\)). Thus \(\sum _{v\in V(G)}w(v)=\sum _{g\in \mathcal G }g-a-b=-a-b \ne 0\). On the other hand each label \(f(e)\) for any \(e \in E(G)\) appears in the sum twice. Therefore \(\sum _{v\in V(G)}w(v)= 0\). The contradiction shows that it is impossible to find desired labelling if \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _2\times \ldots \times \mathbb Z _2\) and \(2^p=n+2\).

Case 2.3: \(t\ge n+2\).

We have that \(2<n< 2^p-2\), thus using Lemma 4 we can choose \(n\) elements \(i_{j_1},i_{j_2},\ldots ,i_{j_{n}}\in I\) such that

$$\begin{aligned} \sum _{l=1}^{n}i_{j_l}=0. \end{aligned}$$

We put the elements \(i_{j_1},i_{j_2},\ldots ,i_{j_{n-1}}\) on the edges obtaining this way distinct weighted degrees (same as edge labels) for the leafs and the weighted degree \(i_n\) for the central vertex. \(\square \)

Lemma 6

Let \(T\) be arbitrary tree on \(n\ge 4\) vertices not being a star. Then \(T\) admits \(\mathcal G \)-irregular labelling for any abelian group \(\mathcal G \) of order \(k> s_g(T)\) except the case when \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _2\times \ldots \times \mathbb Z _2=(\mathbb Z _2)^q\) for some \(q\) such that \(2^q=n+2\).

Proof

We can write \(k=2^{p}(2m+1)\) for some natural numbers \(p\) and \(m\). We distinguish three cases depending on the number of the involutions in \(\mathcal G \) and the parity of the color classes of \(T\).

Case 1: There exists at most one involution \(i \in \mathcal G \) and at least one of the color classes is even.

Since we have at least \(\lfloor \frac{n}{2}\rfloor \) pairs \(\{a_i,-a_i\}\) such that \(2a_i \ne 0\), we combine the vertices of \(V_1\) into pairs (except possibly one vertex if \(|V_1|\) is odd), then do the same with all the vertices in \(V_2\). We obtain this way exactly \(\lfloor \frac{n}{2}\rfloor \) monochromatic pairs \((x_{j,1},x_{j,2})\) plus possibly one additional vertex, say \(x_0\). Now we put \(\phi (x_{j,1},x_{j,2})=a_j\), for \(1\le j\le \lfloor \frac{n}{2}\rfloor \). This way we obtain a \(\mathcal G \)-irregular weighting, as \(w(x_{j,1})=a_j=-w(x_{j,2})\) for \(1\le j\le k\) and if \(n\) is odd, then \(w(x_0)=0\) (this follows from the fact that we begin with all the edges labelled \(0\)).

Case 2: There exists at most one involution \(i \in \mathcal G \) and at both color classes are odd.

We distinguish three cases related to the structure of \(\mathcal G \).

Case 2.1: There is an element \(a\in \mathcal G \) of order greater than \(3\) or there exists an involution \(i \in \mathcal G \).

We select three arbitrary vertices \(x_1\), \(x_2\), \(x_3\) from one color class and any vertex \(x_0\) from the other one.

If there is an element \(a\in \mathcal G \) of order greater than \(3\), then we put \(\phi (x_1,x_0)=a\), \(\phi (x_2,x_0)=-2a\), \(\phi (x_3,x_0)=0\). This way we obtain the following weighted degrees: \(w(x_0)=-a\), \(w(x_1)=a\), \(w(x_2)=-2a\), \(w(x_3)=0\).

In there exists an involution \(i \in \mathcal G \), then we choose some \(a\not \in \{0,i\}\) and we put \(\phi (x_1,x_0)=i\), \(\phi (x_2,x_0)=a\), \(\phi (x_3,x_0)=0\). This way we obtain the following weighted degrees: \(w(x_0)=a+i\), \(w(x_1)=i\), \(w(x_2)=a\), \(w(x_3)=0\). Observe that the existence of an involution implies that \(k\ge n+2\).

As we can easily see, in both cases the weighted degrees are distinct and since \(n\) is even and \(k\ge n+1\) (\(k\ge n+2\), respectively) we still have at least \(\frac{n-4}{2}\) pairs of elements \(\{a_j,-a_j\}\) to label the remaining vertices as in the previous cases.

Case 2.2: All the elements of \(\mathcal G \) have order \(3\) and \(k\ge 10\).

We choose \(a, b, c\in \mathcal G \) such that \(a\ne 0\), \(b\ne 0\), \(c\ne 0\), \(a\not \in \{b,-b\}\), \(c\not \in \{a, -a, b, -b, a+b, -(a+b), a-b, b-a\}\). As \(T\) is not star and both color classes are odd, we can choose at least three vertices from each color class. Now the labelling depends on the value of \(n\).

If \(n\ge 8\), then we can choose five vertices \(x_1\), \(x_2\), \(x_3\), \(x_4\), \(x_5\) from one color class and three \(y_1\), \(y_2\), \(y_3\) from the other one. Now we put \(\phi (x_1, y_1)=a\), \(\phi (x_2, y_1)=a\), \(\phi (x_2, y_2)=2a+b\), \(\phi (x_3, y_2)=a+b\), \(\phi (x_3, y_3)=2a+2b+c\), \(\phi (x_4, y_3)=a+b+c\), \(\phi (x_5, y_3)=0\). This way we obtain \(8\) distinct weighted degrees \(w(x_1)=a\), \(w(x_2)=b\), \(w(x_3)=c\), \(w(x_4)=a+b+c\not \in \{0,a,b,c,-a,-b,-c\}\), \(w(x_5)=0\), \(w(y_1)=-a\), \(w(y_2)=-b\), \(w(y_3)=-c\) and we still have \(\frac{k-9}{2}\ge \lceil \frac{n-8}{2}\rceil \) pairs \(\{a_j,-a_j\}\) to distinguish remaining even numbers of vertices in both color classes.

If \(n=6\), then obviously in both color classes there are exactly three vertices, say \(x_1\), \(x_2\), \(x_3\) and \(y_1\), \(y_2\), \(y_3\), respectively. We put \(\phi (x_1, y_1)=a\), \(\phi (x_1, y_2)=b\), \(\phi (x_2, y_1)=a\), \(\phi (x_2, y_3)=c\), \(\phi (x_3, y_2)=b\) and \(\phi (x_3, y_3)=c\). This way we obtain six distinct weighted degrees \(w(x_1)=a+b\), \(w(x_2)=a+c\), \(w(x_3)=b+c\), \(w(y_1)=-a\), \(w(y_2)=-b\) and \(w(y_3)=-c\).

Case 2.3: \(\mathcal G \cong \mathbb Z _3 \times \mathbb Z _3\).

Again, the labelling depends on the value of \(n\).

If \(n=8\), then since \(T\) is not star, we can choose five vertices \(x_1\), \(x_2\), \(x_3\), \(x_4\), \(x_5\) from one color class and three \(y_1\), \(y_2\), \(y_3\) from another one. Now we put \(\phi (x_1, y_1)=(1,0)\), \(\phi (x_2, y_1)=(2,0)\), \(\phi (x_2, y_2)=(0,0)\), \(\phi (x_3, y_2)=(1,1)\), \(\phi (x_3, y_3)=(2,1)\), \(\phi (x_4, y_3)=(2,1)\), \(\phi (x_5, y_3)=(2,2)\). This way we obtain \(8\) distinct weighted degrees \(w(x_1)=(1,0)\), \(w(x_2)=(2,0)\), \(w(x_3)=(0,2)\), \(w(x_4)=(2,1)\), \(w(x_5)=(2,2)\), \(w(y_1)=(0,0)\), \(w(y_2)=(1,1)\), \(w(y_3)=(0,1)\).

If \(n=6\), then there are exactly three vertices in both color classes, say \(x_1\), \(x_2\), \(x_3\) and \(y_1\), \(y_2\), \(y_3\), respectively. We put \(\phi (x_1, y_1)=(1,1)\), \(\phi (x_1, y_2)=(2,0)\), \(\phi (x_2, y_2)=(1,2)\), \(\phi (x_2, y_3)=(1,0)\) and \(\phi (x_3, y_3)=(0,0)\). This way we obtain six distinct weighted degrees \(w(x_1)=(0,1)\), \(w(x_2)=(2,2)\), \(w(x_3)=(0,0)\), \(w(y_1)=(1,1)\), \(w(y_2)=(0,2)\) and \(w(y_3)=(1,0)\).

Case 3: There exist \(t>1\) involutions in \(\mathcal G \).

Recall that \(t=2^q-1 \) for some \(1<q\le p\). We distinguish three cases, depending on the relation between \(t\) and \(n\).

Case 3.1: \(t\le n\).

We choose \(t\) vertices \(x_1,x_2,\ldots , x_t\in V_1\cup V_2\) in such a way, that at least one of the numbers of remaining vertices in \(V_1\) and \(V_2\) is even. We put \(\phi (x_1,x_j)=i_j\) for \(j=2,\dots ,t\) obtaining \(w(x_j)=i_j\) for \(j=1,\dots ,t\). Since the numbers of remaining vertices in at least one of the color classes \(V_1\) and \(V_2\) are even, we construct \(\lfloor \frac{n-t}{2}\rfloor \) monochromatic pairs and use the pairs \(\{x_l,-x_l\}\) to label them. If there is some unpaired vertex, then its weighted degree is \(0\), so the obtained labelling is \(\mathcal G \)-irregular.

Case 3.2: \(t=n+1\).

If there exists an element \(a\in \mathcal G \) such that \(2a \ne 0\), then we choose two vertices \(x_{n-1}\), \(x_{n}\) from one color class and we put \(\phi (x_{n-1}, x_{n})=a\). Using Lemma 4 we can choose \(t-3=n-2=2^{q}-4\) elements \(i_{j_1},i_{j_2},\ldots ,i_{j_{n-2}}\in I\) such that

$$\begin{aligned} \sum _{l=1}^{n-2}i_{j_l}=0. \end{aligned}$$

We put \(\phi (x_1,x_l)=i_{j_l}\) for \(l=2,\dots , n-2\). This way we obtain \(w(x_l)=i_{j_l}\) for \(l=1,\dots ,n-2\).

If there is no element \(a\in \mathcal G \) such that \(2a \ne 0\), then \(\mathcal G \cong \mathbb Z _2 \times \mathbb Z _2\times \ldots \times \mathbb Z _2\) and \(k=2^p=n+2\). As in the proof of Lemma 5 let us assume that we distinguished all vertices and we did not use labels \(a,b \in \mathcal G \) (\(a\ne b\)). Thus \(\sum _{v\in V(G)}w(v)=\sum _{g\in \mathcal G }g-a-b=-a-b \ne 0\). On the other hand each label \(f(e)\) for any \(e \in E(G)\) appears in the sum twice. Therefore \(\sum _{v\in V(G)}w(v)= 0\). This contradiction shows that it is impossible to find desired labelling in such a case.

Case 3.3: \(t\ge n+2\).

We have \(2<n< 2^q-2\), thus using Lemma 4 we can choose \(n\) elements \(i_{j_1},i_{j_2},\ldots ,i_{j_{n}}\) such that

$$\begin{aligned} \sum _{l=1}^{n-1}i_{j_l}=0. \end{aligned}$$

We put \(\phi (x_1,x_l)=i_{j_l}\) for \(l=2,\dots , n\). This way we obtain \(w(x_l)=i_{j_l}\) for \(l=1,\dots ,n\). \(\square \)

Theorem 2 follows easily from the above lemmas. If \(G\) is a star, then we use Lemma 5. Otherwise we choose any spanning tree of \(G\) not being a star, and use Lemma 6 labelling all the remaining edges with \(0\). Observe that in the latter case same argument as in the proof of Lemma 6 shows that for every graph \(G\) it is impossible to find \(\mathcal G \)-irregular labelling of \(G\) if \(\mathcal G \cong (\mathbb Z _2)^q\) for some \(q\) such that \(2^q=n+2\).

4 Computational complexity issues

In Sect. 2, the group irregularity strength \(s_g(G)\) of an arbitrary connected graph \(G\) was determined. It is natural to ask about the computational complexity of the corresponding problem, where we assume that the group \(\mathcal G \) is given in the most compact form that follows from the fundamental theorem of Abelian groups.

Irregular Labeling.

Instance: A connected graph \(G\), an Abelian group \(\mathcal G \) of order \(|\mathcal G |\), given as the list of (orders of) cyclic subgroups \(\mathcal G _1,\ldots , \mathcal G _k\) of prime-power order such that \(\mathcal G \cong \mathcal G _1\times \ldots \times \mathcal G _k\)

Task: Find a \(\mathcal G \)-irregular labelling of \(G\) or answer that it is impossible.

The proofs in Sect. 2 and 3 are constructive and lead to efficient algorithms for the Irregular Labeling problem.

In order to construct an irregular labeling whose existence is proved in Sect. 2, we first construct, in time \(O(|V(G)|+|E(G)|)\), a spanning tree \(T\) of the given graph \(G\). A proper \(2\)-coloring of \(T\) can also be obtained in time \(O(|V(T)|)= O(|V(G)|)\). The rest of the construction of the irregular labeling reduces to solving constantly many instances of the following problem: Given a tree \(T= (V,E)\) and a non-empty set \(A\subseteq V\) of even cardinality, partition the elements of \(A\) into pairs, say \(\{a_1,a_2\},\ldots , \{a_{2r-1},a_{2r}\}\), and construct the corresponding paths \(P(a_1,a_2),\ldots , P(a_{2r-1},a_{2r})\) joining them. The problem is clearly solvable in polynomial time. However, if the set \(A\) is large (as is the case for the subproblems one needs to solve in order to construct an irregular labeling), the total length of the paths \(P(a_1,a_2),\ldots , P(a_{2r-1},a_{2r})\) can be of the order \(\Omega (|V|^2)\). Can one do better? In particular, can the Irregular Labeling problem be solved in linear time? We will show in this section that this is indeed the case. With this goal in mind, we introduce the following optimization problem:

Shortest Path Collection.

Instance: A tree \(T= (V,E)\) and a non-empty set \(A\subseteq V\) of even cardinality.

Task: Find a partition of the elements of \(A\) into pairs, say \(\{\{a_1,a_2\},\ldots , \{a_{2r-1},a_{2r}\}\}\) such that the value of

$$\begin{aligned} \sum _{i = 1}^r\mathrm{dist}_T(a_{2i-1},a_{i}) \end{aligned}$$

is minimized.

Here, the distance \(\mathrm{dist}_T(\cdot , \cdot )\) is the usual graph-theoretic distance between vertices, that is, the number of edges on a shortest path connecting the two vertices. The Shortest Path Collection problem can be solved in polynomial time not only for trees but also for general graphs. In fact, it can be solved in time \(O(|V||E|+r^4)\) where \(|A| = 2r\), by first computing in time \(O(|V||E|)\) all pairwise vertex distances (this can be done using breadth-first search), and then solving an instance of the minimum weight perfect matching problem in a complete graph with vertex set \(A\) and edge weights given by \(w(xy) = \mathrm{dist}_T(x,y)\) for all pairs of distinct vertices \(x,y\in A\) (this can be done, e.g., using the algorithm by Edmonds 1965). As we show below, the problem can be solved in linear time for trees.

Proposition 1

There exists a linear time algorithm for the Shortest Path Collection problem. Moreover, an optimal collection \(\mathcal{P}\) of shortest paths, each connecting one pair of vertices from the partition of \(A\), can be constructed in linear time.

Proof

Let \((T,A)\) be an instance to the Shortest Path Collection problem. The problem can be solved using a greedy algorithm, traversing the given tree \(T=(V,E)\) bottom up and constructing optimal paths along the way. The algorithm outputs a pair \((\mathcal{A}, \mathcal{P})\), where \(\mathcal{A}\) is a partition of the elements of \(A\) into pairs \(\{a_1,a_2\},\ldots , \{a_{2r-1},a_{2r}\}\), and \(\mathcal{P}\) is the collection of corresponding paths in \(T\) connecting the paired vertices. Traversing the tree bottom up, the algorithm updates two collections \(\mathcal{P}\) and \(\mathcal{Q}\) of paths in \(T\) such that:

  1. (1)

    every path from \(\mathcal{P}\) has exactly two endpoints in \(A\) (in particular, \(\mathcal{P}\) does not contain any trivial, one-vertex paths),

  2. (2)

    every path from \(\mathcal{Q}\) has exactly one endpoint in \(A\) (in particular, \(\mathcal{Q}\) can contain several trivial paths),

  3. (3)

    no path from \(\mathcal{Q}\) has a vertex in common with another path in \(\mathcal{P}\cup \mathcal{Q}\), and

  4. (4)

    every two paths in \(\mathcal{P}\) are edge disjoint, and have at most one vertex in common.

The set \(\mathcal{Q}\) contains all paths that will be eventually extended to a path in the final solution \(\mathcal{P}\). Moreover, for each path \(Q\in \mathcal{Q}\), its endpoints are denoted by \(a(Q)\), \(b(Q)\) in such a way that \(a(Q)\in A\). If \(Q\) is a trivial, one-vertex path then \(a(Q) = b(Q)\).

At every step of the algorithm, a vertex, say \(v_i\), of \(T\) is visited. Paths of \(\mathcal{Q}\) that have a child of \(v_i\) as one of their endpoints are greedily paired and merged, using vertex \(v_i\), to form paths in \(\mathcal{P}\). At the end of this pairing procedure, one path from \(\mathcal{Q}\) that has a child of \(v_i\) as one of its endpoints could be left unpaired, in which case we extend it by the edge connecting one of its endpoints to \(v_i\). If \(v_i\) belongs to \(A\), this extended path is moved from \(\mathcal{Q}\) to \(\mathcal{P}\). On the other hand, if all paths have been paired, then we check whether \(v_i\) belongs to \(A\) and if this is the case, we add to \(\mathcal{Q}\) the trivial one-vertex path consisting of \(v_i\).

Every time a path, say \(P\), is added to the set \(\mathcal{P}\), the set \(\mathcal{A}\) is augmented with the pair containing the two endpoints of \(P\). Moreover, the algorithm keeps at every vertex a Boolean variable \(q(v)\) such that \(q(v) = 1\) if and only if \(v\) is an endpoint of a path in \(\mathcal{Q}\) immediately after \(v\) is visited by the algorithm.

A pseudocode of the algorithm is given below (Algorithm 1). In the description of the algorithm, we denote by \(P_1+P_2\) the path obtained as the union of two edge-disjoint paths \(P_1\) and \(P_2\) meeting at a vertex. Similarly, \(P_1+ P_2+ P_3\) denotes the union of three paths \((P_1+P_2)+P_3\).

figure a

To establish the correctness of the algorithm, we will show that the obtained solution attains a lower bound on the optimal value. For every vertex \(v\) of tree \(T\) rooted at a fixed vertex \(r\), let \(k(v)\) denote the number of subtrees \(T_i\) of \(T\) rooted at the children of \(v\) such that \(|A\cap V(T_i)|\) is odd. Then, for every feasible solution \(\mathcal{A}^{\prime }\) to the problem, the corresponding collection \(\mathcal{P}^{\prime }\) of shortest paths contains at least \(k(v)\) edges connecting \(v\) to its children. In particular, this implies that the optimal value of \(\sum _{i = 1}^r\mathrm{dist}_T(a_{2i-1},a_{i})\) is at least \(\sum _{v\in V(T)}k(v)\).

Now let us verify that the value of \(\sum _{i = 1}^r\mathrm{dist}_T(a_{2i-1},a_{i})\) attained by the solution \(\mathcal{A}\) given by Algorithm 1 is equal to \(\sum _{v\in V(T)}k(v)\). For every \(i = 1,\ldots , n\), let \(\mathcal{P}_i\) and \(\mathcal{Q}_i\) denote the collections of paths \(\mathcal{P}\) and \(\mathcal{Q}\) after \(i\) iterations of the for loop in line 3 (that is, immediately after vertex \(v_i\) has been visited). Properties \((1)\)\((4)\) described above (with \(\mathcal{P}_i\) and \(\mathcal{Q}_i\) in place of \(\mathcal{P}\) and \(\mathcal{Q}\), respectively) can be proved by induction on \(i\). Moreover, for every \(1\le i<j\le n\), it holds that \(\mathcal{P}_i\subseteq \mathcal{P}_j\), every path in \(\mathcal{Q}_i\) is a subpath of some path in \(\mathcal{P}_j\cup \mathcal{Q}_j\), and \(\mathcal{P}_n = \mathcal{P}\), where \(\mathcal{P}\) is the final solution output by the algorithm. Since the paths in \(\mathcal{P}\) are edge-disjoint, the obtained value of \(\sum _{i = 1}^r\mathrm{dist}_T(a_{2i-1},a_{i})\) is equal to the total number of edges that appear in paths in \(\mathcal{P}\). Induction on \(i\) can be used to show that:

  1. (A)

    After vertex \(v_i\) has been processed, \(q(v_i) = 1\) if and only if \(|A\cap V(T_{v_i})|\) is odd, where \(T_{v_i}\) is the subtree of \(T\) rooted at \(v_i\).

  2. (B)

    The number of edges connecting \(v_i\) to one of its children that are contained in a path from \(\mathcal{P}_i\cup \mathcal{Q}_i\) is equal to \(k(v_i)\).

  3. (C)

    The number of edges connecting \(v_i\) to one of its children that are contained in a path from \(\mathcal{P}\) is the same as the number of edges connecting \(v_i\) to one of its children that are contained in a path from \(\mathcal{P}_i\cup \mathcal{Q}_i\).

Since the final value of \(\sum _{i = 1}^r\mathrm{dist}_T(a_{2i-1},a_{i})\) is equal to the total number of edges that appear in paths in \(\mathcal{P}\), this value can be obtained by summing up, over all vertices \(v_i\), the number of edges connecting \(v_i\) to its children that are contained in a path from \(\mathcal{P}\). By \((B)\) and \((C)\), this value is equal to the lower bound \(\sum _{i = 1}^nk(v_i)\). Hence, the proof of correctness is complete.

It remains to analyze the algorithm’s time complexity. A breadth-first traversal from \(r\) takes \(O(n)\) time. A linear time implementation of the iterations of the for loop can be achieved using an appropriate data structure representing the collections of paths \(\mathcal{P}\) and \(\mathcal{Q}\) and their endpoints, and updating it at every iteration of the for loop. Each path in \(\mathcal{P}\cup \mathcal{Q}\) can be represented by a doubly linked list. The number of operations performed by the algorithm during the \(i\)-th iteration of the for loop is then proportional to the degree of \(v_i\). Altogether, this results in linear time complexity.

The last thing to calculate is the number of operations needed to label the edges. We have to take into account three issues.

The first one is the division of \(\mathcal G \) into three sets: a one-element set with the identity element, the set of involutions and the set of pairs \(\{a_i,-a_i\}\) of the remaining elements. In order to do that first we check the parity of all the cyclic subgroups \(\mathcal G _1,\ldots , \mathcal G _k\), which can be done in time \(O(k)=O(\log _2(|\mathcal G |))\). Assume that the groups \(\mathcal G _1,\dots ,\mathcal G _p\) have even order and the groups \(\mathcal G _{p+1},\dots ,\mathcal G _k\) are odd for some \(1\le p\le k\). Each element of \(\mathcal G \) is represented by some \(k\)-tuple \((g_1,\dots ,g_k)\), where \(g_j\in \mathcal G _j\), \(1\le j\le k\) and \(0\le g_j\le |\mathcal G _j|-1\). The identity element of \(\mathcal G \) is represented by \(0_\mathcal G =(0,\dots ,0)\). The involutions have the form \((g_1,\dots ,g_p,0,\dots ,0)\), where \(g_j\in \{0,|\mathcal G _j|/2\}\) for \(1\le j\le p\). The number of involutions is equal to \(2^p-1\). Finally, the pairs \(\{a_i,-a_i\}\) have the form \(\{(g_1,\dots ,g_p,g_{p+1},\dots ,g_k),(|\mathcal G _1|-g_1,\dots ,|\mathcal G _p|-g_p,|\mathcal G _{p+1}|-g_{p+1},\dots ,|\mathcal G _k|-g_k)\}\), where \(g_j\in \{0,\dots ,|\mathcal G _j|-1\}\) for \(1\le j\le k-1\), \(g_k\in \{0,\dots ,\lfloor |\mathcal G _k|\rfloor /2\}\) and for at least one \(j\), \(g_j\not \in I_j\), where \(I_j=\{0,|\mathcal G _j|/2\}\) for \(1\le j\le p\) and \(I_j=\{0\}\) for \(p+1\le j\le k\). It is easy to observe that no search is necessary and the number of assignments is exactly \(|\mathcal G |\).

The second issue is to find (if necessary) the set of involutions (plus identity element in some cases) that sum up to \(0\). The constructive proof of Lemma 4 (see Anholcer and Cichacz 2013) gives the method of choosing such a subset with time complexity linear in the number of involutions. If the required number of elements \(r\in \{0,1,2^p-1,2^p\}\), then \(R=\emptyset \) or \(R=\{0\}\) or \(R=I\setminus \{0\}\) or \(R=I\), respectively. If \(3\le r\le 2^{p-1}\), then we select \(r-1\) elements one by one in the lexicographic order (here \(0_j\) denotes the identity element of \(\mathcal G _j\), in other words the \(0\) on \(j_th\) position of the \(k\)-tuple): \((0_1,\dots ,0_p,0_{p+1},\dots ,0_k)\), \((0_1,\dots ,|\mathcal G _p|/2,0_{p+1},\dots ,0_k)\), \((0_1,\dots ,|\mathcal G _{p-1}|/2,0_p,0_{p+1},\dots ,0_k)\), \((0_1,\dots ,|\mathcal G _{p-1}|/2,|\mathcal G _{p}|/2,0_p,0_{p+1},\dots ,0_k)\) and so on. Now we calculate the sum of all chosen elements. It has the form \(s=(0_1,g_2\dots ,g_p,0_{p+1},\dots ,0)\), similarly to all the elements of the list. If \(s\) is not on the list, then we add it to the list and we are done. Otherwise we choose another element \(s_1\) of the list, (if \(s\ne 0_\mathcal G \) then the one preceding \(s\), otherwise the one following it), and we change the first coordinate of both \(s\) and \(s_1\) from \(0_1\) to \(|\mathcal G _1|/2\) and we are done. The last case is when \(2^{p-1}+1\le r\le 2^p-3\). In such a case we construct the \((2^p-r)\)-element set \(R_1\) and then take \(R=I\setminus R_1\). As it can be easily seen, the complexity is at most \(r-1\) (choosing the elements) plus \(r-2\) (sum) plus \(r-1\) (checking if \(s\) is on the list) plus eventually \(2\) additional summations, what gives in total \(O(|\mathcal G |)\).

The third issue is the assignment of labels to the paths. If \(G\) is not a star, then it is equal to the sum of the numbers of edges in the optimal solutions of the Shortest Path Collection for \(A=V_0\), \(A=V_1\setminus V_0\) and \(A=V_2\setminus V_0\), where \(V_0\) is either an empty set or some subset of \(V(G)\) with at most \(8\) elements, while \(V_1\) and \(V_2\) are the color classes of the spanning tree \(T(G)\) of \(G\). As all the paths in the optimal solution of Shortest Path Collection are edge disjoint and we assign \(0\) to all the edges in \(E(G)\setminus E(T(G))\), the total number of assignments does not exceed \(2|E(T(G))|+|E(G)|< 2|V(G)|+|E(G)|\).

All the above calculations make sense if \(|\mathcal G |\) fulfills all the necessary conditions. Obviously they can be checked in constant time. Hence the following corollary is true.

Corollary 1

The Irregular Labeling problem can be solved in time \(O(|E(G)|+|\mathcal G |)\).

Observe that in the case of \(|\mathcal G |=s_g(G)\) the complexity reduces to \(O(|E(G)|)\). Note also that instead of the list of orders of prime-power cyclic groups, \(\mathcal G \) can be represented with the minimum-length list of the orders of cyclic groups (e.g. \((2,6)\) instead of \((2,2,3)\), as \(\mathbb Z _6\cong \mathbb Z _2\times \mathbb Z _3\)), and it would not change the method of the division of \(\mathcal G \). It can also be represented as the list of generators with the relations of the form \(n_jg_j=0\) (in the above example: \(\mathcal G =[g_1,g_2|2g_1=6g_2=0]\)) but in such a case the list of multipliers \(n_j\) is equivalent to the list of orders of cyclic groups. Of course, in all those cases the complexity of division remains \(O(|\mathcal G |)\).

5 Final remarks

As we solved the problem for all connected graphs, one next step would be to find the solution for arbitrary graphs.

Problem 1

Determine group irregularity strength \(s_g(G)\) for disconnected graph \(G\) with no connected component of order less than \(3\).

Theorem 2 characterises all the pairs \((G,\mathcal G )\), \(|\mathcal G |>s_g(G)\), such that there exists an irregular-\(\mathcal G \)-labeling of given connected graph \(G\) of order at least \(3\). Thus the following generalisation arises.

Problem 2

Characterise all the pairs \((G,\mathcal G )\), \(|\mathcal G |>s_g(G)\), such that there exists an irregular-\(\mathcal G \)-labeling of given graph \(G\) with no connected components of order less than \(3\).

In the proof of Theorem 1 we often use the fact that we are allowed to use \(0\) on edges. Thus the following problem is of significant interest.

Problem 3

Let \(G\) be a simple graph with no components of order less than \(3\). For any Abelian group \(\mathcal G \), let \(\mathcal G ^* = \mathcal G \setminus \{0\}\). Determine the non-zero group irregularity strength (\(s^*_g(G)\)) of \(G\), i.e., the smallest value of \(s\) such that taking any Abelian group \(\mathcal G \) of order \(s\), there exists a function \(f:E(G)\rightarrow \mathcal G ^*\) such that the sums of edge labels in every vertex are distinct.

All the elements of \(\mathcal G \) can be obtained as some combination of not necessarily all of its elements, in particular of its generators. The question is, how many elements of \(\mathcal G \) we have to use in order to obtain \(\mathcal G \)-irregular labelling.

Problem 4

Assume that for given simple graph \(G\) with no components of order less than \(3\) there exists \(\mathcal G \)-irregular labelling for every group \(\mathcal G \) of order \(s\). What is the minimum number \(k=k(G,s)\) such that for every group \(\mathcal G \) of order \(s\) there is a subset \(S\subseteq \mathcal G \), \(|S|\le k\) such that there exists a \(\mathcal G \)-irregular labelling \(f:E(G)\rightarrow S\)?

We have considered only finite Abelian groups in this paper. Our next question seems to be a natural generalization of ordinary irregularity strength.

Problem 5

Let \(G\) be a simple graph with no component of order less than \(3\). Determine the smallest value of \(k\) such that for any infinite Abelian group \(\mathcal G \) there exists a subset \(S\subseteq \mathcal G \), \(S\le k\) such that there exists a \(\mathcal G \)-irregular labelling \(f:E(G)\rightarrow S\).