Computer Science and IT‹›⌂ 0:00 studied

Module 1 · 16 min read · Free chapter

Monoids and groups

In short

A semigroup is closed and associative, a monoid adds an identity and a group adds inverses. By Lagrange's theorem the order of a subgroup divides the order of the group. A cyclic group of order n has φ(n) generators, and the smallest non-abelian group has order 6.

What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: arithmetic on a clock

A train leaves at 20:00 and the journey takes 7 hours. When does it arrive? Not at 27:00, because the station clock wraps round after 24, so the answer is 03:00. Adding hours on a clock is a new kind of arithmetic, where 20+7=320 + 7 = 3.

This clock addition keeps some familiar habits. Adding 0 changes nothing, every time has a "go back" time that returns you to 00:00, and the order of brackets in a chain of additions does not matter. Ordinary multiplication of whole numbers keeps some of these habits too, but not all, since you cannot undo multiplication by 2 inside the whole numbers.

This chapter asks a simple question: which rules does an operation obey? Collections of rules give names to structures: semigroup, monoid and group. Once you know the structure, a whole set of results comes free.

Why it matters. Groups are the mathematics of symmetry and of reversible operations. They are behind error-correcting codes, the arithmetic of public-key cryptography and the hashing of strings, and GATE asks short but sharp questions on them.

Binary operations and closure

A binary operation ∗\ast on a set SS takes two elements a, bb of SS and returns one element a∗ba \ast b, which must again be in SS. That last requirement is closure. Addition is a binary operation on the integers, but subtraction is not a binary operation on the natural numbers, because 2−52 - 5 is not natural.

A set with one binary operation is sometimes called a groupoid or magma. Two properties are checked first. The operation is associative if (a∗b)∗c=a∗(b∗c)(a \ast b) \ast c = a \ast (b \ast c) for all a, bb, cc, and commutative if a∗b=b∗aa \ast b = b \ast a for all a, bb.

On a finite set, a binary operation is just a filled-in table. A set of nn elements gives an n×nn \times n table with n2n^2 cells, and each cell can hold any of the nn elements. So there are nn2n^{n^2} binary operations on it. A commutative operation is fixed by the diagonal and the cells above it, which number n(n+1)2\dfrac{n(n + 1)}{2}, so there are nn(n+1)2n^{\frac{n(n + 1)}{2}} commutative ones.

Worked example. On a set of 2 elements there are 24=162^4 = 16 binary operations, and 23=82^3 = 8 of them are commutative. On a set of 3 elements there are 39=19,6833^9 = 19{,}683 binary operations, and 36=7293^6 = 729 are commutative.

Why it matters. Closure is the most common reason a candidate structure fails in a GATE question. The table view also shows why so few operations are associative, since that property must be checked for every triple.

Semigroups, monoids and groups

Structures are built by adding one rule at a time. A semigroup is a set with a closed and associative operation. A monoid is a semigroup with an identity element ee, such that a∗e=e∗a=aa \ast e = e \ast a = a for every a. A group is a monoid in which every element a has an inverse a−1a^{-1}, with a∗a−1=a−1∗a=ea \ast a^{-1} = a^{-1} \ast a = e.

If the operation of a group is also commutative, the group is abelian. So the ladder is: closed, then associative (semigroup), then identity (monoid), then inverses (group), then commutative (abelian group).

Structure Semigroup? Monoid? Group?
(N,+)(N, +) with NN from 1 yes no identity no
(W,+)(W, +) with WW from 0 yes yes, e=0e = 0 no inverses
(Z,×)(Z, \times) yes yes, e=1e = 1 no, 2 has no inverse
(Z,+)(Z, +) yes yes yes, abelian
nonzero rationals under ×\times yes yes yes, abelian
Strings under concatenation yes yes, empty string no

Note that (Z,−)(Z, -) is not even a semigroup, because (5−3)−1=1(5 - 3) - 1 = 1 but 5−(3−1)=35 - (3 - 1) = 3. Also, (Q,×)(Q, \times) is a monoid but not a group, because 0 has no inverse; removing 0 repairs it.

Worked example. Define a∗b=a+b−1a \ast b = a + b - 1 on the integers. It is closed and associative, since both groupings give a+b+c−2a + b + c - 2. The identity is 1, because a+1−1=aa + 1 - 1 = a, and the inverse of a is 2−a2 - a, because a+(2−a)−1=1a + (2 - a) - 1 = 1. So (Z,∗)(Z, \ast) is an abelian group.

Why it matters. The structure names are a shorthand for which algebra is allowed. In a monoid you can combine and have a neutral starting value, which is exactly what a parallel "reduce" or "fold" operation in programming needs.

Basic group laws and group tables

A few laws follow from the group axioms in one or two lines each. The identity is unique: if ee and e′e' are both identities, then e=e∗e′=e′e = e \ast e' = e'. Each element has a unique inverse, (a−1)−1=a(a^{-1})^{-1} = a, and the inverse of a product reverses the order: (ab)−1=b−1a−1(ab)^{-1} = b^{-1}a^{-1}.

The cancellation laws say that ab=acab = ac implies b=cb = c, and ba=caba = ca implies b=cb = c. Multiply on the left or right by a−1a^{-1} to see this. As a result, the equation ax=bax = b always has exactly one solution, x=a−1bx = a^{-1}b.

Cancellation has a striking effect on the operation table of a finite group. In each row, the entries a∗xa \ast x for different xx are all different, so every element appears exactly once in each row, and likewise in each column. Such a table is a Latin square, which gives a quick test: a table with a repeated entry in a row cannot be a group.

Worked example. Fill the table of a group {e,a,b}\{e, a, b\} of order 3. The row and column of ee copy the headers. In row a, the entry a∗aa \ast a cannot be a (else a=ea = e) and cannot be ee (else a∗ba \ast b would have to be bb, giving a=ea = e), so a∗a=ba \ast a = b and a∗b=ea \ast b = e. The rest is then forced, and the group is cyclic: a, a2=ba^2 = b, a3=ea^3 = e.

A useful fact for GATE: if every element satisfies a2=ea^2 = e, the group is abelian. The reason is that each element is its own inverse, so ab=(ab)−1=b−1a−1=baab = (ab)^{-1} = b^{-1}a^{-1} = ba.

Why it matters. These laws let you solve equations in any group as if it were ordinary algebra, except that you must keep the order of factors. The Latin-square test lets you reject a non-group table in seconds.

Order of an element and groups of integers mod n

The order of a group, written ∣G∣\lvert G\rvert, is its number of elements. The order of an element a is the smallest positive integer mm with am=ea^m = e. In a finite group every element has a finite order, and an element and its inverse have the same order.

The most common finite groups in exams are built from remainders. (Zn,+n)(Z_n, +_n) is the set {0,1,…,n−1}\{0, 1, \dots, n - 1\} under addition  mod n\bmod n, and it is an abelian group of order nn. In Z6Z_6, the element 2 has order 3, because 2+2+2=6≡02 + 2 + 2 = 6 \equiv 0, while 1 and 5 have order 6.

Multiplication  mod n\bmod n is trickier. The set {0,1,…,n−1}\{0, 1, \dots, n - 1\} under ×n\times_n is never a group, because 0 has no inverse. The units  mod n\bmod n, the numbers a with gcd⁡(a,n)=1\gcd (a, n) = 1, do form a group under ×n\times_n, and its order is Euler's φ(n)\varphi (n). When n=pn = p is prime, every non-zero remainder is a unit, so {1,2,…,p−1}\{1, 2, \dots, p - 1\} under ×p\times_p is a group of order p−1p - 1.

Worked example. In {1,2,3,4,5,6}\{1, 2, 3, 4, 5, 6\} under multiplication mod 7, find the order of 3. The powers are 3, 9≡29 \equiv 2, 6, 18≡418 \equiv 4, 12≡512 \equiv 5 and 15≡115 \equiv 1. So 3 has order 6, which equals the order of the group, and 3 generates the whole group.

By contrast, {1,2,3,4,5}\{1, 2, 3, 4, 5\} under multiplication mod 6 is not a group. For example 2×3=6≡02 \times 3 = 6 \equiv 0, which is not in the set, so closure already fails. The units mod 6 are only {1,5}\{1, 5\}, a group of order φ(6)=2\varphi (6) = 2.

Why it matters. The group of units  mod n\bmod n is the stage on which RSA and Diffie–Hellman key exchange are performed. Element orders decide how secure such schemes are, and GATE often asks which of several mod-n structures is a group.

Subgroups and Lagrange's theorem

A subgroup HH of a group GG is a subset that is itself a group under the same operation. Every group has the two trivial subgroups {e}\{e\} and GG. In Z12Z_{12}, the set {0,4,8}\{0, 4, 8\} is a subgroup, because sums of its elements mod 12 stay inside and each has an inverse inside.

Checking all the axioms is not needed. The one-step test says that a non-empty subset HH is a subgroup exactly when ab−1∈Hab^{-1} \in H for all a, bb in HH. For a finite non-empty subset, closure alone is enough, because the powers of each element eventually return to ee.

Two subgroups always meet in a subgroup, since their intersection passes the one-step test. Their union, however, is usually not a subgroup. In Z6Z_6, {0,3}\{0, 3\} and {0,2,4}\{0, 2, 4\} are subgroups, but their union {0,2,3,4}\{0, 2, 3, 4\} is not, because 2+3=52 + 3 = 5 is missing. In fact the union is a subgroup only when one subgroup contains the other.

Lagrange's theorem is the main counting tool. If HH is a subgroup of a finite group GG, then ∣H∣\lvert H\rvert divides ∣G∣\lvert G\rvert. The reason is that the cosets aH, the copies of HH shifted by each a, all have ∣H∣\lvert H\rvert elements and split GG into ∣G∣∣H∣\dfrac{\lvert G\rvert}{\lvert H\rvert} disjoint blocks.

Worked example. A group of order 12 can only have subgroups of order 1, 2, 3, 4, 6 or 12. A group of order 7, a prime, can have only {e}\{e\} and itself as subgroups, so every non-identity element generates the whole group and the group is cyclic.

The converse of Lagrange's theorem is false. The alternating group A4A_4, the 12 even permutations of four objects, has no subgroup of order 6, even though 6 divides 12. For cyclic groups, however, the converse does hold, as the next section shows.

Why it matters. Lagrange's theorem rules out impossible answers in seconds. It also gives Fermat's little theorem, ap−1≡1 mod pa^{p-1} \equiv 1 \bmod p, which is used in primality tests and in cryptography.

Cyclic groups and generators

A group GG is cyclic if some element a produces every element as a power, G=⟨a⟩={ak:k∈Z}G = \langle a\rangle = \{a^k : k \in Z\}. Such an a is a generator. (Z,+)(Z, +) is cyclic with generator 1, and (Zn,+n)(Z_n, +_n) is cyclic with generator 1 as well.

Cyclic groups are the simplest groups. Every cyclic group is abelian, since ajak=aj+k=akaja^j a^k = a^{j+k} = a^k a^j. Every subgroup of a cyclic group is again cyclic. And for each divisor dd of nn, a cyclic group of order nn has exactly one subgroup of order dd, so here the converse of Lagrange's theorem holds.

How many generators are there? In ZnZ_n the element kk generates the group exactly when gcd⁡(k,n)=1\gcd (k, n) = 1. So a cyclic group of order nn has φ(n)\varphi (n) generators, and more generally it has φ(d)\varphi (d) elements of order dd for each divisor dd of nn.

Worked example. In Z12Z_{12}, the generators are the kk with gcd⁡(k,12)=1\gcd (k, 12) = 1, namely 1, 5, 7 and 11, so there are φ(12)=4\varphi (12) = 4 of them. The element 8 has order 12gcd⁡(8,12)=3\dfrac{12}{\gcd (8, 12)} = 3 and generates the subgroup {0,4,8}\{0, 4, 8\}. The divisors of 12 are 1, 2, 3, 4, 6 and 12, so Z12Z_{12} has exactly six subgroups.

For a group of prime order pp, every element except ee has order pp, so every such element is a generator and there are p−1p - 1 generators. A non-cyclic example is the Klein four-group V4={e,a,b,c}V_4 = \{e, a, b, c\}, in which every non-identity element has order 2, so no single element produces all four.

Why it matters. Cyclic groups model anything that repeats, from clock arithmetic to the rotation of a circular buffer. The φ(n)\varphi (n) count of generators is the most common group question in GATE.

GATE-style questions on structures

GATE questions on this topic follow a few patterns, and a fixed checklist answers most of them. Check closure first, then associativity, then the identity, then inverses, and finally commutativity. Stop at the first failure and name the structure that the earlier steps give.

Pattern 1: an unusual operation. Let a∗b=max⁡(a,b)a \ast b = \max (a, b) on the natural numbers {1,2,3,… }\{1, 2, 3, \dots \}. It is closed and associative, and the identity is 1, since max⁡(a,1)=a\max (a, 1) = a for every a. But no element above 1 has an inverse, because max⁡(a,b)=1\max (a, b) = 1 forces a=1a = 1. So it is a commutative monoid, not a group.

Pattern 2: small groups. Every group of order 1, 2, 3 or 5 is cyclic, since these orders are prime or 1. A group of order 4 is either the cyclic group Z4Z_4 or the Klein four-group V4V_4, and both are abelian. So every group of order at most 5 is abelian, and the smallest non-abelian group is S3S_3, the 6 permutations of three objects.

Pattern 3: counting. The symmetric group SnS_n has n!n! elements and is non-abelian for n≥3n \ge 3. The number of elements of order 2 in Z10Z_{10} is φ(2)=1\varphi (2) = 1, namely the element 5. The number of generators of Z18Z_{18} is φ(18)=6\varphi (18) = 6.

Worked example. On the set {1,3,5,7}\{1, 3, 5, 7\} under multiplication mod 8, the table shows 3×3=9≡13 \times 3 = 9 \equiv 1, 5×5≡15 \times 5 \equiv 1 and 7×7≡17 \times 7 \equiv 1. Every element is its own inverse, so the group is abelian with every non-identity element of order 2. It is therefore a copy of the Klein four-group, not of Z4Z_4, even though it has 4 elements.

Why it matters. A clear checklist turns a confusing definition into four quick tests. It also guards against the most common slip, which is declaring a group without checking that every element has an inverse.

Descriptive lens: how written papers ask this

Written papers for scientist posts and university-level tests ask about groups in four ways:

  1. Verify that a given set and operation form a semigroup, monoid or group, showing each axiom.
  2. Prove a standard result, such as the uniqueness of the identity or (ab)−1=b−1a−1(ab)^{-1} = b^{-1}a^{-1}.
  3. State and prove Lagrange's theorem using cosets, and draw a consequence from it.
  4. Find the generators and subgroups of a given cyclic group.

Practice questions (our own, not previous-year questions).

  1. Show that the integers form an abelian group under a∗b=a+b+1a \ast b = a + b + 1, and find the identity and the inverse of a. (8 marks)
  2. State and prove Lagrange's theorem for finite groups, and deduce that a group of prime order is cyclic. (12 marks)
  3. List all generators and all subgroups of Z18Z_{18} and draw the subgroup diagram. (10 marks)

Answer plan for question 2.

  • State the theorem: if HH is a subgroup of a finite group GG, then ∣H∣\lvert H\rvert divides ∣G∣\lvert G\rvert.
  • Define the left coset aH as the set of all products ah with hh in HH, and show that each coset has exactly ∣H∣\lvert H\rvert elements because ah1=ah2ah_1 = ah_2 forces h1=h2h_1 = h_2.
  • Show that two cosets are either equal or disjoint, so the cosets split GG into blocks of equal size.
  • Conclude that ∣G∣\lvert G\rvert equals the number of cosets times ∣H∣\lvert H\rvert, so ∣H∣\lvert H\rvert divides ∣G∣\lvert G\rvert.
  • Deduce that in a group of prime order pp, the subgroup generated by any a≠ea \ne e has order dividing pp and greater than 1, so it is the whole group and GG is cyclic.

Quick revision

  • A binary operation must be closed, and a set of nn elements has nn2n^{n^2} of them.
  • Semigroup means closed and associative, monoid adds an identity, and group adds inverses.
  • (N,+)(N, +) is a semigroup, (Z,×)(Z, \times) is a monoid, and (Z,+)(Z, +) is an abelian group.
  • The identity and inverses are unique, and (ab)−1=b−1a−1(ab)^{-1} = b^{-1}a^{-1}.
  • Each element appears once in every row and column of a group table.
  • {1,…,p−1}\{1, \dots, p - 1\} under ×p\times_p is a group exactly when pp is prime.
  • Lagrange's theorem says that ∣H∣\lvert H\rvert divides ∣G∣\lvert G\rvert, but A4A_4 has no subgroup of order 6.
  • A cyclic group of order nn has φ(n)\varphi (n) generators and one subgroup for each divisor of nn.
  • Groups of order at most 5 are abelian, and S3S_3 of order 6 is the smallest non-abelian group.
  • If a2=ea^2 = e for every element, the group is abelian.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 15 answered

  1. How many binary operations can be defined on a set of 2 elements?

  2. How many commutative binary operations are there on a set of 3 elements?

  3. A monoid is a semigroup that also has:

  4. (Z,×)(Z, \times), the integers under multiplication, is:

  5. Which of these is NOT a semigroup?

  6. In any group, (ab)−1(ab)^{-1} equals:

  7. If every element of a group GG satisfies a2=ea^2 = e, then GG must be:

  8. The order of the element 3 in {1,2,3,4,5,6}\{1, 2, 3, 4, 5, 6\} under multiplication mod 7 is:

  9. Which set is a group under multiplication modulo the given number?

  10. In Z6Z_6, the union of the subgroups {0,3}\{0, 3\} and {0,2,4}\{0, 2, 4\} is:

  11. A group of order 12 CANNOT have a subgroup of order:

  12. Which statement is true?

  13. The number of generators of the cyclic group Z12Z_{12} is:

  14. The smallest order of a non-abelian group is:

  15. In GATE CS, monoids and groups appear under:

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

What is the difference between a monoid and a group?

Both are associative with an identity, but a group also needs an inverse for every element.

Is (Z, ×) a group?

No, it is a monoid, because 2 has no integer inverse.

How many generators does Z₁₂ have?

φ(12) = 4, namely 1, 5, 7 and 11.

Is the converse of Lagrange's theorem true?

No; A₄ has order 12 but no subgroup of order 6. It is true for cyclic groups.

More in this module: Discrete mathematics

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Discrete Mathematics (IIT Ropar, 106106183): algebraic structures, monoids and groups