1 Introduction

Two groups (G,⋅) and (H,×) are said to be isomorphic if there exists a bijective function f : GH, which is a homomorphism i.e. ∀a,bG,f(ab) = f(a) × f(b). The decision version of this problem is to check whether two input groups (G,⋅) and (H,×) are isomorphic or not. There are multiple ways in which a group can be given as the input. Two of commonly used methods are by a generating set and by the Cayley table. The complexity of the group isomorphism problem varies with the input representation. In this paper we assume that input groups are given by their Cayley tables unless stated otherwise explicitly. Given two elements a and b, the Cayley table can return the product ab in constant time. The inputs are assumed to be Cayley tables of groups and not just any arbitrary dataFootnote 1.

It is not known whether the group isomorphism problem (GrISO) is in P. If it is NP-complete then polynomial hierarchy collapses at the second level [4]. Tarjan(see e.g., [16]) gave an \(n^{\log n + \mathcal {O}(1)}\) algorithm for GrISO. While this still remains the best upper bound for the general group isomorphism problem, progress has been made for restricted classes of groups. For solvable groups, Arvind and Torán showed that the problem is in NPco-NP under a reasonable complexity theoretic assumption [1]. Rosenbaum and Wagner gave a \(n^{1/2(\log n ) + \mathcal {O}(1) }\) algorithm for the isomorphism problem of p-groups [20] and Rosenbaum gave an \(n^{1/2(\log n ) + \mathcal {O}(\log n / \log \log n) }\) time algorithm for solvable groups [19].

The isomorphism problem for various restricted classes of groups has been studied in the past [1,2,3, 9, 10, 17, 23, 24]. Efficient polynomial-time algorithms for the isomorphism problem of abelian groups were designed by Savage [21], and Vikas [24]. Kavitha gave a remarkable linear time algorithm for the isomorphism problem of abelian groups [23]. Kavitha’s paper also provides us with a useful tool for computing the orders of all the elements in any group in linear time.

Polynomial time algorithms have been designed for some classes of non-abelian groups. For example, Le Gall designed an efficient algorithm for groups consisting of a semidirect product of a finite abelian group with a cyclic group of coprime order [8]. Later, Qiao, Sarma, and Tang gave a polynomial time algorithm for the isomorphism problem of groups with normal Hall subgroups [17]. Babai, Codenotti and Qiao gave a polynomial-time algorithm for the class of groups with no normal abelian subgroups [3]. To the best of our knowledge the runtime of these algorithms are superquadratic.

Our goal in this paper is to design linear or nearly linear time algorithm for some nontrivial classes of nonabelian groups.

The isomorphism problem of nilpotent class 2 groupsFootnote 2 is not known to be in polynomial-time. A nonabelian group is Hamiltonian if all of its subgroups are normal. These groups are nilpotent class 2 groups. We design an \(\mathcal {O}(n)\) algorithm for the recognition and the isomorphism problem of the Hamiltonian groups where n is the order of the input groups.

A Hamiltonian group is a direct product of the quaternion group Q8 and an abelian group with certain structure [5]. This motivates us to study the class of groups that can be decomposed as a direct product of any arbitrary nonabelian group of bounded order and an abelian group without any specific structure. We design an \(\tilde {\mathcal {O}}(n)\) algorithm for the recognition and the isomorphism problem of such groups.

Kayal and Nezhmetdinov gave an algorithm to factorize an input group into a direct product of indecomposable factors [14]. We note that this group factorization algorithm combined with any of the polynomial-time isomorphism algorithms for abelian group gives us a polynomial-time isomorphism test for the group classes considered in this paper. However, direct application of the result by Kayal and Nezhmetdinov only gives us superquadratic isomorphism algorithms. One of the contributions of this paper is to use the structure of the input groups to tweak and bypass some of the computation heavy steps of the algorithm by Kayal et al [14]. We note that Wilson gave an algorithm to find the direct factors of permutation groups in polynomial time [26] and of groups given by their Cayley table in time \(\mathcal {O}(n^{2}\log ^{\mathcal {O}(1)}(n))\) [25], where n is the order of the group.

The main results of this paper are stated below.

Theorem 1

There exists an \(\mathcal {O}(n)\) algorithm for the recognition and the isomorphism problem of Hamiltonian groups where n is the order of the input groups.

Theorem 2

There exists an \(\tilde {\mathcal {O}}(n)\) algorithm for the recognition and the isomorphism problem of groups that can be decomposed as a direct product of a nonabelian group of bounded order and an abelian group where n is the order of the input groups.

Many of our algorithms use the fact that a group of order n has a generating set of size \(\log n\). In fact computing small generating set, testing if a given subgroup is normal, computing the center of a group, computing the subgroup generated by a subset of elements of a given group, computing quotient subgroups etc., sometimes come as the building blocks of many of the group theoretic algorithms [11, 22]. We observe that many of these algorithms can be implemented in nearly linear-time and or in linear-time for groups given by their Cayley tables. These results may be of independent interest.

2 Preliminaries

In this section, we describe some of the group-theoretic definitions and background used in the paper. For more details see [6, 12, 15, 23]. For a group G, the number of elements in G or the order of G is denoted by |G|. Let xG be an element of group G, then ordG(x) denotes the order of the element x in G, which is the smallest power i of x such that xi = e, where e is the identity element of the group G. A group G is abelian or commutative if ab = ba for all a,bG. A subgroup AG is said to be normal in G, denoted by \(A \mathrel {\unlhd } G\), if gAg− 1 = A for all gG.

For a subset \(S \subseteq G\), 〈S〉 denotes the subgroup generated by the set S. For a subgroup AG, the centralizer of A, denoted CG(A), is the set {gGag = ga,∀aA}. The centerZ(G) of group G is the subgroup with elements {gGga = ag,∀aG}. Note that for a subgroup AG, Z(A) denotes the subgroup with elements {aA|ab = ba,∀bA}.

Given HG, the normal closure of H in G is the smallest normal subgroup of G containing H and is denoted by 〈HG〉. The commutator subgroup [G,G] of a group G is the subgroup 〈{xyx− 1y− 1∣∀x,yG}〉. Similarly [H,K] = 〈{hkh− 1k− 1hH,kK}〉.

Let G be a finite group and A,B be subgroups of G. Then G is a direct product of A and B, denoted G = A × B, if 1) \(A\mathrel {\unlhd }G\) and \(B\mathrel {\unlhd } G\), 2) |G| = |A||B|, 3) AB = {e}. We say that a group G is decomposable if there exist nontrivial subgroups A and B such that G = A × B and indecomposable otherwise. We say that a subgroup A of G is a direct factor (or factor) of G if there exists another subgroup B of G such that G = A × B and we will call B a direct complement (or complement) of A.

If pk is the highest power of a prime p dividing the order of the group G, then a subgroup of G of order pk is called a Sylow p-subgroup of G. By Sylow theorem such a subgroup always exists. A group G is nilpotent if and only if it is the direct product of its Sylow subgroups.

The fundamental theorem for finitely generated abelian groups implies that a finite group G can be decomposed as a direct product G = G1 × G2 ×… × Gt, where each Gi is a cyclic group of order pj for some prime p and integer j ≥ 1. If ai generates the cyclic group Gi for i = 1,2,3,…,t then the elements a1,a2,…,at are called a basis of G. An elementary abelian p-group is an abelian group in which every nontrivial element has order p. Chen and Fu [6], and Karagiorgos and Poulakis [13] gave linear time algorithms for finding a basis of abelian groups.

Theorem 3 (Remak-Krull-Schmidt, see e.g., 12)

Let G be a finite group. If G = G1 × G2 ×… × Gs and G = H1 × H2 ×… × Ht with each Gi, Hj indecomposable, then s = t and after reindexing GiHi for every i, and for any r < t, G = G1 ×… × Gr × Hr+ 1 ×… × Ht.

A Remak-Krull-Schmidt decomposition of a group G is a decomposition such that each direct factor of group G is indecomposable. The following lemma establishes a relationship between two different decompositions of a group G in which one of the factors is same.

Lemma 1 (14)

For a group G, suppose that G = K × H. Then for a \(K^{\prime }\mathrel {\unlhd }G\), \(G = K^{\prime } \times H\) if and only if \(K^{\prime }=\{\alpha \varphi (\alpha ) \mid \alpha \in K\}\), where φ : KZ(H) is a homomorphism.

Proof

Let φ : KZ(H) be a homomorphism and \(K^{\prime } = \{\alpha \varphi (\alpha ) \mid \alpha \in K\}\). We need to to prove that \(G = K^{\prime } \times H\).

First we note that for all kK and hH we have kh = hk. It is also easy to see that gh = hg for all gG and hZ(H). We use these facts multiple times in this proof.

Let a = αφ(α) and b = α1φ(α1) be two elements in \(K^{\prime }\). It is easy to see that \(ab^{-1}\in K^{\prime }\). This proves that \(K^{\prime }\) is a subgroup.

As G = K × H, any gG could be written as g = kh where kK and hH. For arbitrary element \(c = \alpha \varphi (\alpha ) \in K^{\prime }\), we have

$$ \begin{array}{ll} g c g^{-1} &= (kh)(\alpha\varphi(\alpha))(k^{-1}h^{-1}) \\ & =(k \alpha k^{-1})\varphi(\alpha) \\ &=(k \alpha k^{-1})(\varphi(k)\varphi(\alpha)\varphi(k^{-1})) \\ &=(k \alpha k^{-1})\varphi(k\alpha k^{-1}) \end{array} $$

The third equality follows by noting that φ(k) and φ(α) are in Z(H) and commute with each other.

Now we prove that \(K^{\prime } \cap H = \{e\}\). Assume that \(c= \alpha \varphi (\alpha ) \in K^{\prime }\) also belongs to H. Since cH and G = K × H, the K component of c must be e. That is α = e and therefore φ(α) = e. Thus c = e and hence \(K^{\prime } \cap H = \{e\}\). By using the definition of direct product we get, \(G = H \times K^{\prime }\), as required.

For the other direction we need to prove that if \(G = K^{\prime } \times H\) then \(K^{\prime } = \{\alpha \varphi (\alpha ) \mid \alpha \in K\}\), where φ : KZ(H) is a homomorphism.

Claim 1

For any k in K, there exists unique \(k^{\prime }\in K^{\prime }\) and hZ(H) such that \(k^{\prime }=kh\).

Proof Proof of the Claim

We can write \(k=k^{\prime }h^{\prime }\) as \(G=K^{\prime }\times H\). So, \(k^{\prime }=kh^{\prime -1}\). Setting \(h=h^{\prime -1}\) we get \(k^{\prime }=kh\). Since \(h=k^{-1}k^{\prime }\) and element h1H commutes with elements in K as well as elements in \(K^{\prime }\), we infer that hZ(H).

Assume that \(k^{\prime } = kh_{1}\) and \(k^{\prime \prime } = kh_{2}\) where kK and \(h_{1},h_{2} \in Z(H)\subseteq H\). This implies \(k^{\prime }h_{1}^{-1} = k^{\prime \prime }h_{2}^{-1}=k\). Since \(G=K^{\prime }\times H\) this is only possible when \(k^{\prime }=k^{\prime \prime }\) and h1 = h2. □

Let kK. By the claim we know there are unique \(k^{\prime }\in K^{\prime }\) and hZ(H) such that \(k^{\prime }=kh\). This allows us to define a map φ : KZ(H) by the rule φ(k) = h. Thus, \(k^{\prime }=k\varphi (k)\). Note that if kφ(k) = k1φ(k1) then we must have k = k1 as G = K × H. Then, as \(|K|=|K^{\prime }|\) we must have \(K^{\prime }=\{\alpha \varphi (\alpha )\mid \alpha \in K\}\).

It just remains to show that φ is a homomorphism. Let k,k1K and let \(k^{\prime }=kh\) and \(k^{\prime \prime }=k_{1}h_{1}\) be the elements given according to the above claim. Then φ(k) = h and φ(k1) = h1. We note that \(k^{\prime }k^{\prime \prime }=kk_{1}hh_{1}\), with kk1K and hh1Z(H). So, φ(kk1) = hh1. □

Model of Computation

Our model of computation is same as that of many of the algorithms for groups given by Cayley table (e.g., [6, 23]). It is a RAM model where random access can be done in constant time. Each register and memory unit can store \(\mathcal {O}(\log |G|)\) bits. The arithmetic, logic and comparison operations on \(\mathcal {O}(\log |G|)\) bits take constant time. Unless stated otherwise we assume that the elements of the group are encoded as 1,2,…,|G|. The Cayley table of a group with n elements could be viewed is as a 2-dimensional array with n rows and n columns. Given two elements i and j, the (i,j)th entry of the table is the product of i and j. The Cayley table can return the product in constant time.

Given an n × n square matrix, it needs Ω(n2) time for any randomized algorithm just to check if the matrix corresponds to a Cayley table of a group [18]. Thus, for the design of subquadratic algorithms (i.e., an algorithm with runtime o(|G|2)) for group theoretic problems it is necessary to assume that the inputs are indeed Cayley tables of groups and not just some arbitrary data. This is a reasonable and standard assumption which is implicitly or explicitly made by several papers e.g., [6, 13, 23, 24].

2.1 Previous Results

Apart from the results by Kayal and Nezhmetdinov, which we discuss in detail in Section 5, we also use results by Chen and Fu, Karagiorgos and Poulakis, and Kavitha. We summarize these results below.

The first result is due to Chen and Fu [6] (page 4116), and Karagiorgos and Poulakis [13] (page 540)

Theorem 4 (6, 13)

There is an \(\mathcal {O}(|G|)\) algorithm for computing a basis of an abelian group G given by its Cayley table.

Next we list the results proved by Kavitha [23] (page 987,993,995)

Theorem 5

[23]

  1. 1.

    There is an algorithm to compute the order of all the elements in any group G given by it Cayley table in time \(\mathcal {O}(|G|)\).

  2. 2.

    There is an algorithm to check if an input group G is abelian in time \(\mathcal {O}(|G|)\).

  3. 3.

    There is an algorithm to test if two abelian groups G and H given by their Cayley tables are isomorphic in time \(\mathcal {O}(|G|)\).

Organization of the paper

In Section 3, we discuss some basic algorithms for groups given by their Cayley tables. In Section 4 we give algorithms to compute quotient groups in linear time. In Section 5 we discuss some nearly linear-time algorithms for finding complements of certain groups. This results are then used in Section 6 and Section 7. The main results of this article i.e., Theorem 1 is proved in Section 6 and Theorem 2 in Section 7.

3 Nearly Linear Time Algorithms

We say that a group theoretic algorithm is nearly linear-time if it has runtime \(\mathcal {O}(|G|\log ^{\mathcal {O}(1)} |G|)\). We hide the logarithmic factor by using the notation \(\tilde {\mathcal {O}}(|G|)\). We list some useful nearly linear-time algorithms for group theoretic problems for groups given by their Cayley tables in the next lemma. The ideas behind these results are either known as folklores or directly follows from easy observations. We also note that Seress [22] has listed a rich library of nearly linear time algorithms in the context of permutation groups. However, the exponent in the logarithmic factor in those algorithms is usually more than one.

Lemma 2

  1. 1.

    Given \(S \subseteq G\), one can compute the elements of the subgroup 〈S〉 in \(\mathcal {O}(|G| \log |G|)\) time.

  2. 2.

    Finding an \(\mathcal {O}(\log |G|)\) sized generating set can be done in \(\mathcal {O}(|G| \log |G|)\) time.

  3. 3.

    For a group G the center Z(G) can be computed in \(\mathcal {O}(|G| \log |G|)\) time.

  4. 4.

    Given AG, one can check whether \(A\mathrel {\unlhd }G\) in \(\mathcal {O}(|G| \log |G|)\) time.

  5. 5.

    Given two subgroups A and B of G, one can check whether G = A × B in \(\mathcal {O}(|G| \log |G|)\) time.

Proof

We present proofs for the statements 1 and 2. The proofs for the other statements are easy and we just sketch the proofs.

Consider a directed graph X = (V,E), where V = G and E = {(g,gs)|gG,sS}. Let H = 〈S〉. Finding H amounts to computing the set R of vertices reachable from the identity element eG. Notice that R induces a regular directed subgraph with |H||S| edges. This subgraph is also a strongly connected component of X. Note that the group structure implies that the strongly connected components and weakly connected components are same for the graph X. An algorithm similar to depth first search from the vertex corresponding to e can find R in time \(\mathcal {O}(|H||S|)\). This proves 1) if \(|S|\leq \log |G|\). We use similar ideas as in the proof of 2 to handle the case when \(|S|>\log |G|\). Hence, we first prove 2).

For 2, we pick an element aG ∖{e} and set S1 = {a}. The algorithm keeps on computing sets S1,S2,… in stages as follows. At the i th stage we have the set Si. If we discover G = 〈Si〉 we stop the algorithm and output Si. Otherwise we pick gG ∖〈Si〉 and let Si+ 1 = Si ∪{g}. Note that 2|〈Si〉|≤|〈Si+ 1〉| as 〈Si+ 1〉 contains the disjoint cosets 〈Si〉 and 〈Sig. Thus, if the last set is Sr, then \(r\leq \log |G|\). Let 〈Si〉 = Hi and ni = |Hi|. Computing Hi via finding a suitable strongly connected component in a graph as mentioned above takes time \(\mathcal {O}(|H_{i}||S_{i}|)=\mathcal {O}(i|H_{i}|)\). Furthermore, we note that nr = |G| and ninr/2ri. Thus, computing all the His together takes \(\mathcal {O}(|G|\log |G|)\) time.

Finding an element gG ∖〈Si〉 takes time \(\mathcal {O}(|G|)\) and this too happens at most \(\log |G|\) times. Thus, the runtime of the algorithm is \(\mathcal {O}(|G|\log |G|)\). The pseudocode to compute an \(\mathcal {O}(\log |G|)\) sized generating set is given below.

figure a

To complete the proof of 1, we modify the algorithm for finding a logarithmic sized generating set by setting S1 = {a} for any aS and then picking the new elements g from S ∖〈Si〉 instead of G ∖〈Si〉.

For 3 compute a generating set S of G of size \(O(\log |G|)\) and then select g as a member of Z(G) if gs = sg for all sS.

To show 4 compute a generating set S of G of size \(O(\log |G|)\) and for each gS and check whether \(As \subseteq sA\) for each sS.

For the last statement 5 we need to check if \(A,B\trianglelefteq G\), AB is identity, and |G| = |A||B|. The last two conditions take time \(\mathcal {O}(|G|)\) to check and the first condition needs \(\mathcal {O}(|G|\log |G|)\) time. □

4 Algorithms in Quotient Groups

Suppose we have the list of elements of a group G and a black-box for the group multiplication. Let N be a normal subgroup of G (also given as a list or array). In this section we show how to construct the quotient structure G/N in linear-time. More precisely, we describe a linear-time algorithm to build a data structure that can serve as a black-box to compute multiplications in G/N. Once we have the data structure, a multiplication query in G/N can be processed in constant time with just one query to the black-box for G.

Many of the algorithms for groups given by their Cayley table work in the same running time if the algorithm has access to the list of group elements and a group multiplication black-box. As a consequence of this quotient black-box construction we can see that the algorithms by Kavitha [23], Chen and Fu [6], and Karagiorgos and Poulakis [13] still run in linear-time in quotient groups.

Suppose the list of elements of a group G and a normal subgroup N of G are given along with a black-box for G. We construct lists Li for i = 1,…,|G/N|, each containing the elements of different cosets of N in G in Algorithm 2. We also compute the minimum elements mi (in the input order) of the list Li for each i.

figure b

Run-Time Analysis of Algorithm 2

In the algorithm flag[g] = 1 line 6 indicates that we have already processed the coset containing g and no further action is required. If flag[g] = 0 then the algorithm spends \(\mathcal {O}(|G/N|)\) time within the “if” condition. But in the process it also discovers all the elements of the coset Ng for which the “if” condition will not be executed in future. This shows that the run-time of Algorithm 2 is \(\mathcal {O}(|G|)\).

It is easy to see that in linear-time we can compute an array S of size G and indexed by the elements of G such that S[g] = i, where Li is the list produced by by Algorithm 2 containing the elements of Ng. The Algorithm 3 given below is the pseudocode for computing the array S.

figure c

The data structure for the quotient group G/N consists of the lists Li’s, the sequence m1,m2,…,m|G/N| and the array S along with an access to the black-box for G. The elements of G/N will be, as usual, 1,2,…,|G/N|. The element i corresponds to the list Li, which in turn corresponds to one of the cosets of N in G. If we need to compute the product of i and j, we first compute m = mimj using the multiplication black-box for G and then return S[m]. By construction S[m] is the index of the list containing the coset elements of the coset Nm.

We notice that any bounded number of repeated quotient construction can be done in linear-time using the above method.

5 Algorithms for Finding Complements

Given a group G and a normal subgroup D of G, a complement of D in G is a subgroup B such that G = D × B. It is important to note that a complement of a subgroup may or may not exist, and even if a complement exists it may not be unique. Kayal and Nezhmetdinov [14] gave an algorithm for finding a complement of a given normal subgroup D of G. Their algorithm is divided into two cases: G/D is abelian and G/D is nonabelian.

Algorithm 4 given below finds a complement of a subgroup D of a group G when G/D is abelian. The algorithm is from [14] (page 591)

figure d

A careful analysis of the complement finding algorithm given above shows that it takes \(\tilde {\mathcal {O}}(|G|)\) time to find a complement of the subgroup D in G (if it exists). Note that step 3 in Algorithm 4 can be done in linear-time using a basis finding algorithm [6, 13] combined with results from Section 4. Similarly, in step 4 of the Algorithm 4 the orders can be computed in linear-time using the results from [23] but again combined with results from Section 4 in a quotient structure. The step 5 of above algorithm can be performed in \(\tilde {\mathcal {O}}(|G|)\) time (see Lemma 2)

The result for the first case can be stated as follows.

Theorem 6 (14)

There is an algorithm to check if a complement of a normal subgroup D of a group G exists in \(\tilde {\mathcal {O}}(|G|)\) time, when G/D is abelian. The algorithm also returns a complement if it exists.

In the second case when G/D is nonabelian, it is not clear how to make the algorithm by Kayal and Nezhmetdinov [14] run in nearly linear-time in general. Fortunately, for the purpose of this paper, as we would see in comming paragraph that, we only need to deal with the subcase when D is a subgroup of the center Z(G) of G. During its execution the algorithm in [14] computes a quotient group which can be done in linear-time using results in Section 4.

The following complement finding algorithm for the case when G/D is nonabelian is from [14]. In our case DZ(G), which allows us to modify the original algorithm.

figure e

The Algorithm 5 computes a group T = 〈{aga− 1g− 1aCG(D),gG}〉. We will verify in the later part that, all other steps in the algorithm can be made to run in \(\tilde {\mathcal {O}}(|G|)\) time without the assumption DZ(G). It is the computation of T where we use a different approach using the fact that DZ(G) to obtain the desired nearly linear runtime. We first mention an easy observation.

Observation 1

If DZ(G) then CG(D) = G.

From Observation 1, it is immediate that T = 〈{aga− 1g− 1aG,gG}〉 which is nothing else but the commutator subgroup [G,G] of G. Lemma 3 gives us a way to compute T efficiently.

Lemma 3 (see e.g., 15)

If G = 〈S〉 then [G,G] = 〈[S,S]〉G, where S is a generating set of G and [S,S] = {aga− 1g− 1a,gS}.

We can compute a generating set S of size \(\mathcal {O}(\log |G|)\) of G in time \(\mathcal {O}(|G|\log |G|)\) by Lemma 2. Again by Lemma 2 we can compute an \(\mathcal {O}(\log |G|)\) sized generating set for the group 〈[S,S]〉 in \(\mathcal {O}(|G|\log |G|)\) time. Let us denote this set by Tgen. Algorithm 6 given below computes a generating set for [G,G] (see [15]).

figure f

Runtime Analysis of Algorithm 6

Each time a new generator is added to Tgen the order of the group K = 〈Tgen〉 is at least doubled, which implies that the number of iterations of the while loop is \(\mathcal {O}(\log |G|)\). We maintain the group K as an array AK indexed by the group elements gG such that AK[g] = 1 if and only if gK. Thus, for any aS and bTgen, we can check if a− 1baK in \(\mathcal {O}(1)\) time. It takes \(\mathcal {O}(|G| \log |G|)\) time to compute the group 〈Tgen〉. Now it is easy to verify that the overall runtime of Algorithm 6 is \(\mathcal {O}(|G| (\log |G|)^{3})\). \(\hfill \Box \)

It is important to note that the inverse of an element aG can be found in \(\mathcal {O}(|G|)\) time (step 4). However since the number of iterations is only \(\mathcal {O}(\log |G|)\), we would need to compute the inverse of \(\mathcal {O}(\log |G|)\) many elements, which implies that the overall runtime to find inverses is \(\mathcal {O}(|G| \log |G|)\).

For the sake of completeness we make some more remarks. Computing \(\tilde {G}\) can be done in \(\mathcal {O}(|G|)\) time as discussed in Section 4. \(\tilde {D}\) can also be computed in \(\mathcal {O}(|G|)\) time. It is easy to see that Step 7 of the above algorithm can be done in \(\tilde {\mathcal {O}}(|G|)\) time with the techniques discussed in the Section 4 along with algorithms by Kavitha in [23], and Chen and Fu in [6] or Karagiorgos and Poulakis in [13].

Summarising the above discussion we obtain:

Theorem 7

There exists an algorithm to find a complement of a subgroup D of the center Z(G) of a groups G in time \(\tilde {\mathcal {O}}(|G|)\) whenever a complement exists.

6 Hamiltonian Group Recognition and Isomorphism

A Hamiltonian group is a nonabelian group all of whose subgroups are normal. Since every subgroup of such a group is normal, it follows that there is a unique Sylow subgroup of any fixed order. In this section we consider the following problem.

Hamiltonian Group Recognition Input : Given a group (G,⋅) by its Cayley table. Find : Is G a Hamiltonian group?

The following structure theorem is one of the main ingredients for our result.

Theorem 8 ([5, page 114])

Let G be a Hamiltonian group. Then - G is the quaternion group Q8; or, - G is the direct product of Q8 and B, or of Q8 and A, or of Q8,B and A, where A is an abelian group of odd order and B is an elementary 2-group. Moreover, every such direct product is a Hamiltonian group.

We recall that the quaternion group Q8 is a nonabelian group with eight elements and it is generated by two elements a and b with the conditions a4 = 1,a2 = (ab)2 = b2 (see e.g., [5]). An elementary 2-group is isomorphic to \(\mathbb {Z}_{2}^{k}\) for some k. Thus, from Theorem 8 we can see that the Sylow 2-subgroup of a Hamiltonian group is \(Q_{8} \times \mathbb {Z}_{2}^{k}\) for some nonnegative integer k and the other Sylow subgroups are all abelian. The theorem also implies that Hamiltonian groups are nilpotent. The Sylow decomposition can be computed in \(\mathcal {O}(|G|)\) time using methodsFootnote 3 described in [6]. Next we decompose the Sylow 2-subgroup using Algorithm 7. If we find that the Sylow 2-subgroup is not of the form \(Q_{8} \times \mathbb {Z}_{2}^{k}\) for some k, then we can immediately conclude that the input group is not Hamiltonian. Otherwise, we can use the techniques developed by Kavitha [23] to test if the odd order Sylow subgroups are abelian. If that is the case then we know that the input group is Hamiltonian. Moreover, since the odd order Sylow subgroups are abelian, Theorem 4 give us a Remak-Krull-Schmidt decomposition of the odd order Sylow subgroups. The decomposition of the Sylow 2-subgroup obtained from Algorithm 7 along with the decomposition of the odd order abelian Sylow subgroups gives us a Remak-Krull-Schmidt decomposition of the input Hamiltonian group.

Given a Sylow 2-subgroup as input, Algorithm 7 checks if it is Hamiltonian and also returns a Remak-Krull-Schmidt decomposition isomorphic to \(Q_{8}\times \mathbb {Z}_{2}^{k}\) if the input is indeed Hamiltonian. We use the next lemma in the algorithm.

Lemma 4

Any two non-commutating elements in a Hamiltonian 2-group generate a quaternion group which is also a direct factor.

Proof

Let G be a Hamiltonian 2-group and let \(g,g^{\prime } \in G\) be two non-commutating elements. To show that \(\langle g,g^{\prime } \rangle \cong Q_{8}\) it is enough to show that \(g^{4} =1, g^{2} =(gg^{\prime })^{2} ={g^{\prime }}^{2}\). As G is a Hamiltonian 2-group, \(G=Q_{8}\times \mathbb {Z}_{2}^{k}\) for some k. Thus, we can write g = (a1,b1) and \(g^{\prime } = (a_{2},b_{2})\), where a1,a2Q8 and \(b_{1},b_{2} \in \mathbb {Z}_{2}^{k}\). It is easy to verify that \(g^{4} =1, g^{2} =(gg^{\prime })^{2} ={g^{\prime }}^{2}\). Now we prove that \(\langle g,g^{\prime }\rangle \) is also a factor of G. Set a homomorphism \(\varphi : Q_{8} \longrightarrow \mathbb {Z}_{2}^{k}\) that maps the generators a1 and a2 of Q8 to b1 and b2 respectively and let C = {αφ(α)∣αQ8}. Now using Lemma 1, we can see that \(G=C \times \mathbb {Z}_{2}^{k}\). Next we prove that \(C= \langle g,g^{\prime } \rangle \). Notice that |C| = |Q8|. Thus it is enough to prove that \(\langle g,g^{\prime } \rangle \subseteq C\). For this we note that generators g = a1φ(a1) ∈ C and \(g^{\prime }=a_{2}\varphi (a_{2})\in C\). This completes the proof. □

A Hamiltonian 2-group may have multiple quaternion subgroups. Lemma 4 states that every quaternion subgroup of a Hamiltonian 2-group is also a direct factor of the Hamitlonian 2-group. This allows us to design an algorithm to find a quaternion factor in \(\mathcal {O}(|G|)\) time as given in the pseudocode below.

figure g

We now prove the correctness of the algorithm and give the run-time analysis. Checking whether GQ8 or not can be done in \(\mathcal {O}(1)\) time. From now on, we assume that \(G\ncong Q_{8}\). In a Hamiltonian 2-group, all non-central elements are of order 4 and constitutes the set P. Since we are interested in elements of order 4, P can be computed in linear-time even without using results in [23].

Since the picked element gP (Line 6) is non-central, there must exist an element \(g^{\prime } \in P\) such that \(gg^{\prime }\neq g^{\prime }g\). If no such pair is found in P then G is not a Hamiltonian 2-group. Otherwise by Lemma 4, \(\langle g,g^{\prime }\rangle \cong Q_{8}\) and will also be direct factor of G. Thus, if the check \(\langle g ,g^{\prime } \rangle \cong Q_{8}\) fails we conclude that G is not a Hamiltonian 2-group.

Using Kavitha’s result given in [23], we can test whether C is abelian in time \(\mathcal {O}(|G|)\) (Line 10). If C is abelian and all the elements of C have order 2, then we conclude that C is an elementary abelian 2-group and the algorithm returns the complement C.

Finally we argue that we can also compute a complement of \(\langle g,g^{\prime }\rangle \) in time \(\mathcal {O}(|G|)\) in Line 9. We can use the result of Theorem 6 to find a complement. However, a direct application of Theorem 6 would only give us an \(\tilde {\mathcal {O}}(|G|)\) upper bound. Below we show that the structure of Hamiltonian group could be used to get an \(\mathcal {O}(|G|)\) upper bound.

The major time consuming computation tasks inside the complement finding algorithm of Theorem 6 are computing the quotient group \(G/\langle g,g^{\prime }\rangle \), computing the center and testing normality (see [14]).

Since \(\langle g,g^{\prime }\rangle \) is the quaternian group of order 8, testing its normality in time \(\mathcal {O}(|G|)\) is trivial. We can compute \(G/\langle g ,g^{\prime } \rangle \) in \(\mathcal {O}(|G|)\) time using techniques discussed in Section 4. If G is a Hamiltonian 2-group, then \(G/\langle g ,g^{\prime } \rangle \) will be an abelian group. The task of checking whether \(G/\langle g ,g^{\prime } \rangle \) is abelian can be performed in \(\mathcal {O}(|G|)\) time using the algorithm described in [23]. If G is a Hamiltonian 2-group, then the center of the group G consists of all order 2 elements along with the identity. One can find all these elements in \(\mathcal {O}(|G|)\) time. If the original group is not a Hamiltonian 2-group then the final test (Line 5, Algorithm 4), which is to confirm if we have actually computed a valid decomposition will identify any error that might have occurred in the computation of the center. This final test can be performed in time \(\mathcal {O}(|G|)\) exploiting the structure of Hamiltonian 2-groups as described below.

Let g1,g2,…,gt are elements in the center of the group G such that ordG(gi) = ord\(_{G/ \langle g,g^{\prime } \rangle }(g_{i}), \forall i \in [t]\). We now show that checking \(G = \langle g,g^{\prime } \rangle \times \langle g_{1} \rangle \times \langle g_{2} \rangle \times {\ldots } \times \langle g_{t} \rangle \) can be performed in \(\mathcal {O}(|G|)\) time. It is easy to verify that the second and third condition of direct product (see preliminary) can be checked in \(\mathcal {O}(|G|)\) time. The first condition of direct product which is to check whether \(\langle g,g^{\prime } \rangle \) and each 〈gi〉, i ∈ [t] is normal or not normal in G. Checking whether \(\langle g,g^{\prime } \rangle \unlhd G\) can be done in \(\mathcal {O}(|G|)\) time as order of subgroup \(\langle g,g^{\prime } \rangle \) is eight. Note that if G is a Hamiltonian 2-group then \(G = \langle g,g^{\prime },g_{1},\ldots ,g_{t} \rangle \) (see Theorem 8). To check 〈gi〉, is normal in G can be performed in \(\mathcal {O}(|G|)\) time (see Lemma 2) as we have an \(\mathcal {O}(\log |G|)\) sized generating set of G. Failing in any of the checks will imply that the input group is not a Hamilotinian 2-group. These observations shows that Theorem 6 can be modified to find a complement of \(\langle g ,g^{\prime } \rangle \) in G in \(\mathcal {O}(|G|)\) time.

Once we have the Remak-Krull-Schmidt decompositions of two Hamiltonian groups the isomorphism test is trivial.

Theorem 9

There exists an algorithm that given two Hamiltonian groups G and H tests if they are isomorphic in time \(\mathcal {O}(|G|)\).

7 Groups with a Bounded Nonabelian Direct Factor

Taking motivation from Hamiltonian groups, which are direct product of the non-abelian quaternion group Q8 and an abelian group, we study the recognition and the isomorphism problem of a more general class of groups which can be decomposed as a direct product of a nonabelian group of bounded order and an abelian group. For a fixed d, let \(\mathcal {G}_{d}=\{G \mid G=A\times B, \text { where } |A|\leq d \text { and } B \text { is abelian} \}\). It is easy to see that the isomorphism problem for groups in \(\mathcal {G}_{d}\) can be solved in linear-time once we have a decomposition of each of the input groups as a direct product of a small nonabelian group with no cyclic factor and an abelian group.

In this section we show that given a nonabelian group G, it can be decomposed as a direct factor of a nonabelian group with no cyclic factor and an abelian group in nearly linear-time. We note that for this algorithm we do not need any upper bound on the order of the nonabelian factor. The idea is to keep on peeling off direct cyclic factors from the given group as long as possible. Each time we factor out a cyclic group, the order of the other factor decreases by at least half. Thus, the process of factoring out cyclic groups can happen for at most \(\log |G|\) iterations. Next we define the Cyclic Factor problem below.

Cyclic Factor Input : A group (G,⋅) given by its Cayley table. Find : A cyclic factor 〈b〉 and \(H\mathrel {\unlhd }G\) (if they exist) such that G = H ×〈b〉.

We show that the Cyclic Factor problem can be solved in \(\tilde {\mathcal {O}}(|G|)\) time. From this result and the above discussion we can immediately obtain the following theorem.

Theorem 10

There is an algorithm that takes the Cayley table of a nonabelian group G as input and in time \(\tilde {O}(|G|)\) returns two groups A and B, such that G = A × B where A is a nonabelian group with no cyclic factor and B is abelian.

In the rest of the section we focus on the Cyclic Factor problem. The following lemma helps us to solve the problem.

Lemma 5

If G has a cyclic factor then for any basis {b1,b2,…,b} of Z(G), there is i ∈ [] such that 〈bi〉 is a factor of G.

Proof

Let G = A × B, where A is nonabelian with no cyclic factor and B is abelian. Notice that Z(G) = Z(A) × B = B × Z(A). Let B = 〈c1〉×… ×〈ck〉 and Z(A) = 〈d1〉×… ×〈dr〉 be a basis decomposition of B and Z(A). This gives a basis decomposition of Z(G) as Z(G) = 〈c1〉×… ×〈ck〉×〈d1〉×… ×〈dr〉. Let b1,…,bk,bk+ 1,…,bk+r be an another basis of Z(G), where bis are ordered to satisfy the following conditions from Remak-Krull-Schmidt theorem:

  1. 1.

    bi〉≅〈ci〉,∀i ∈ [k] and 〈bk+j〉≅〈dj〉,∀j ∈ [r], and

  2. 2.

    Z(G) = Bp ×〈d1〉×… ×〈dr〉 = Bp × Z(A)

where Bp = 〈b1〉×… ×〈bk〉. Therefore, we have Z(G) = B × Z(A) = Bp × Z(A). By Lemma 1, we have Bp = {αφ(α)∣αB} for some homomorphism φ : BZ(Z(A)) = Z(A).

Thus, we have G = A × B = B × A and Bp = {αφ(α)|αB} for the homomorphism φ : BZ(A). In this setting another application of Lemma 1 shows that G = Bp × A = A × Bp.

It is clear that for some i ∈ [k] the subgroup 〈bi〉 is a factor of G. □

The above lemma immediately suggests an algorithm to solve the Cyclic Factor problem for a given group G. The pseudocode of the algorithm for the Cyclic Factor problem is given below. The algorithm can be used recursively to find all the cyclic factors of the group G.

figure h

We now discuss the runtime of the algorithm. We can use Kavitha’s result to check if G is abelian in linear-time [23]. If G is abelian, then cyclic factors of G can be found in \(\mathcal {O}(|G|)\) time using results from [6]. Let us assume that input group G is nonabelian. We can compute the center of a group in nearly linear-time using Lemma 2. Thus, step 4 of the algorithm takes \(O(|G|\log |G|)\) time.

Since Z(G) is abelian we can use Theorem 4 for step 5 of the algorithm. Notice that the number of basis elements of Z(G) is at most \(\log |G|\). Thus, the maximum number of iterations in step 9 is at most \(\log |G|\). In general, we do not know how to compute a complement of a subgroup in nearly linear time. However, the fact that each 〈bi〉 is a subgroup of the center of the group allows us to use Theorem 7. Thus, the runtime of step 9 as well as the whole algorithm is \(\tilde {O}(|G|)\).