Isomorphism and Subgraphs

Study Sheet

Isomorphism and Subgraphs

When two graphs are the same, and the invariants that prove they are not

Subgraphs and Complements

Concept
Subgraph, induced subgraph, complement

A graph HH is a subgraph of GG, written H⊆GH\subseteq G, if V(H)⊆V(G)V(H)\subseteq V(G) and E(H)⊆E(G)E(H)\subseteq E(G). HH is spanning if V(H)=V(G)V(H)=V(G), and HH is the subgraph induced by S⊆V(G)S\subseteq V(G), written G[S]G[S], if E(H)E(H) consists of ALL edges of GG with both ends in SS (not just some of them). The complement G‾\overline G has the same vertices as GG, with uv∈E(G‾)  ⟺  uv∉E(G)uv\in E(\overline G) \iff uv\notin E(G).

An induced subgraph is the one subgraph on a vertex set SS you get "for free": pick the vertices and every edge that survives comes along automatically. A general subgraph is weaker — you may also delete edges inside SS — so induced subgraphs are the most informative kind, and the ones invariants in this topic will lean on. The complement flips every potential edge of the complete graph KnK_n at once, so GG and G‾\overline G partition the (n2)\binom n2 pairs of vertices: ∣E(G)∣+∣E(G‾)∣=(n2)|E(G)| + |E(\overline G)| = \binom n2, and G‾‾=G\overline{\overline G} = G.

Example
An induced subgraph
12345
G with S = 1,2,3,4 shaded; G[S] keeps every edge among the shaded vertices.

Let GG have vertices 1,…,51,\ldots,5 and edges 12,13,23,34,4512, 13, 23, 34, 45 (a triangle on 1,2,31,2,3 with a path hanging off through 44 to 55). The subgraph induced by S={1,2,3,4}S=\{1,2,3,4\} keeps every edge of GG with both ends in SS: that is 12,13,23,3412, 13, 23, 34 — the triangle plus the edge to 44, but nothing touching 55. Compare the spanning subgraph HH with V(H)={1,…,5}V(H)=\{1,\ldots,5\} and edges 12,34,4512, 34, 45 only: HH is spanning (it has all 5 vertices) but NOT induced by anything, since 1,2,31,2,3 are all present yet edge 1313 and 2323 are missing even though both ends lie in HH.

Example
The complement of a complete bipartite graph
abcde
The complement of K_2,3: an edge and a disjoint triangle.

Take K2,3K_{2,3} with parts {a,b}\{a,b\} and {c,d,e}\{c,d,e\}: every cross pair is an edge, ac,ad,ae,bc,bd,beac,ad,ae,bc,bd,be, six edges in all. Of the (52)=10\binom52=10 possible pairs on 5 vertices, the four NOT used are abab (within the first part) and cd,ce,decd,ce,de (within the second). So K2,3‾\overline{K_{2,3}} has exactly those four edges — a single edge abab together with a disjoint triangle cdecde: K2,3‾≅K2∪K3\overline{K_{2,3}} \cong K_2 \cup K_3, two cliques with no edges between them. The same argument shows Km,n‾≅Km∪Kn\overline{K_{m,n}} \cong K_m \cup K_n for any complete bipartite graph.

Example
Counting spanning subgraphs of K3K_3

How many spanning subgraphs does the triangle K3K_3 (vertices 1,2,31,2,3, edges 12,13,2312,13,23) have? A spanning subgraph keeps all 3 vertices and any subset of the 3 edges, and every edge subset is allowed since removing edges can never break the "both ends present" rule. So the count is the number of subsets of a 3-element set, 23=82^3=8: the empty graph, three graphs with one edge, three with two edges (each a path on all 3 vertices), and K3K_3 itself, and 1+3+3+1=81+3+3+1=8 checks against 232^3.

Side note
Where it goes wrong

Spanning is not the same as induced. The spanning subgraph HH above (edges 12,34,4512,34,45) has every vertex of GG but is missing edges (1313, 2323) whose endpoints are both still there — so H≠G[{1,…,5}]=GH \ne G[\{1,\ldots,5\}] = G. "Induced by SS" is a strong promise: ALL edges inside SS survive, not merely some choice of them.

Try it
Try it: complement of a 4-cycle

Let G=C4G = C_4 have vertices 1,2,3,41,2,3,4 and edges 12,23,34,1412,23,34,14. Find G‾\overline G.

Show the answer

Of the (42)=6\binom42=6 pairs on 4 vertices, the cycle uses 4 (12,23,34,1412,23,34,14), leaving 2: 1313 and 2424 — the two diagonals. So C4‾\overline{C_4} has edges {13,24}\mathbf{\{13, 24\}}, a single pair of disjoint edges: C4‾≅2K2\overline{C_4} \cong 2K_2.

Graph Isomorphism

Concept
Isomorphism

Graphs GG and HH are isomorphic, written G≅HG \cong H, if there is a bijection φ:V(G)→V(H)\varphi: V(G) \to V(H) such that uv∈E(G)  ⟺  φ(u)φ(v)∈E(H)uv \in E(G) \iff \varphi(u)\varphi(v) \in E(H) for all u,vu, v. Such a φ\varphi is an isomorphism; an isomorphism from GG to itself is an automorphism.

A drawing of a graph names its vertices and places them on the page, but neither the names nor the positions are part of the graph itself — only who is adjacent to whom. Isomorphism makes that precise: it says two drawings describe the same adjacency pattern after relabeling, in BOTH directions at once ("  ⟺  \iff"), so edges never appear or vanish under φ\varphi. Because φ\varphi is a bijection, it in particular matches ∣V(G)∣|V(G)| to ∣V(H)∣|V(H)| and sends each vertex to one of matching degree, which is the first and simplest test the next section builds on.

Example
The same cycle, drawn two ways
12345
G_1: the 5-cycle 1-2-3-4-5-1.

Let G1G_1 have vertices 1,…,51,\ldots,5 and edges 12,23,34,45,1512,23,34,45,15 — the standard pentagon. Let G2G_2 have vertices a,…,ea,\ldots,e and edges listed out of order: ad,dc,cb,be,eaad, dc, cb, be, ea. Reading G2G_2's edges in sequence traces the cycle a-d-c-b-e-aa\text{-}d\text{-}c\text{-}b\text{-}e\text{-}a, so both graphs are 5-cycles. The map φ:1↦a, 2↦d, 3↦c, 4↦b, 5↦e\varphi: 1\mapsto a,\, 2\mapsto d,\, 3\mapsto c,\, 4\mapsto b,\, 5\mapsto e sends 12↦ad12\mapsto ad, 23↦dc23\mapsto dc, 34↦cb34\mapsto cb, 45↦be45\mapsto be, 15↦ea15\mapsto ea — every edge of G1G_1 lands on an edge of G2G_2, and since both have exactly 5 edges none are left over, so φ\varphi is an isomorphism.

Example
Degree sequence already rules it out

The star K1,3K_{1,3} (center xx, leaves p,q,rp,q,r, edges xp,xq,xrxp,xq,xr) and the path P4P_4 (1-2-3-41\text{-}2\text{-}3\text{-}4, edges 12,23,3412,23,34) both have 4 vertices and 3 edges. But K1,3K_{1,3} has a vertex of degree 3 and three of degree 1, while every vertex of P4P_4 has degree 1 or 2 — no vertex of P4P_4 has degree 3. Since an isomorphism would have to send the degree-3 vertex of K1,3K_{1,3} to a vertex of the same degree in P4P_4, and none exists, K1,3≇P4K_{1,3} \not\cong P_4.

Example
Counting the automorphisms of C4C_4
1234
C_4: 8 automorphisms, the symmetries of a square.

How many automorphisms does C4C_4 (vertices 1,2,3,41,2,3,4, edges 12,23,34,1412,23,34,14) have? An automorphism is a relabeling of 1,2,3,41,2,3,4 that preserves this exact edge set. Rotating the labels around the cycle (1,2,3,4↦2,3,4,11,2,3,4 \mapsto 2,3,4,1, etc.) gives 4 automorphisms, and reflecting (e.g. fixing 1,31,3 and swapping 2,42,4) gives 4 more — 8 in total, matching the 8 symmetries (4 rotations, 4 reflections) of a square. No other relabeling can work: a vertex and its two cycle-neighbors must go to a vertex and its two neighbors, which pins down the whole map once one edge's image is chosen, and there are exactly 4×2=84 \times 2 = 8 ways to choose it.

Side note
Where it goes wrong

Matching degree sequences do not guarantee an isomorphism. P5P_5 (1-2-3-4-51\text{-}2\text{-}3\text{-}4\text{-}5, edges 12,23,34,4512,23,34,45) and C3∪K2C_3 \cup K_2 (a triangle on 1,2,31,2,3 plus a disjoint edge 4545: edges 12,23,13,4512,23,13,45) both have degree sequence 2,2,2,1,12,2,2,1,1 and both have 4 edges — yet P5P_5 is a single connected path with no triangle, while C3∪K2C_3\cup K_2 is disconnected and does contain a triangle. They cannot be isomorphic: an isomorphism would have to carry P5P_5's connectedness and triangle-free-ness over unchanged.

Try it
Try it: find the isomorphism

Are G1G_1 (vertices 1,2,3,41,2,3,4, edges 12,13,14,2312,13,14,23) and G2G_2 (same vertices, edges 12,13,14,3412,13,14,34) isomorphic?

Show the answer

In G1G_1, vertex 11 has degree 3 (a universal vertex), the edge 2323 joins two of its neighbors, and 44 is a pendant attached only to 11. In G2G_2, vertex 11 again has degree 3, the edge 3434 joins two of its neighbors, and 22 is the pendant. Matching universal-to-universal, pendant-to-pendant, and the remaining two neighbors to each other gives φ:1↦1, 4↦2, 2↦3, 3↦4\varphi: 1\mapsto1,\ 4\mapsto2,\ 2\mapsto3,\ 3\mapsto4. Check: 12↦1312\mapsto13, 13↦1413\mapsto14, 14↦1214\mapsto12, 23↦3423\mapsto34 — all four land in E(G2)E(G_2). **Yes, isomorphic, via 1↦1, 2↦3, 3↦4, 4↦21\mapsto1,\ 2\mapsto3,\ 3\mapsto4,\ 4\mapsto2.**

Invariants That Tell Graphs Apart

Concept
Graph invariant

A graph invariant is any quantity computed from a graph that is equal for isomorphic graphs — ∣V∣|V|, ∣E∣|E|, the degree sequence, the number of connected components, and the number of triangles are all invariants. If two graphs differ in some invariant, they are NOT isomorphic; matching every invariant you check is never a proof that they ARE, only growing evidence.

Checking an invariant is cheap — count something — while checking isomorphism directly means searching among all n!n! bijections (or finding a clever one, as the last section did by hand). Invariants turn "prove these are different" into a one-line computation, which is why they are the first tool reached for. They cannot certify isomorphism, though: no finite checklist of simple invariants captures a graph completely, which is part of why deciding isomorphism in general is a genuinely hard problem. This section builds a working toolkit — components, triangles, and the degree sequence itself used systematically — and the next section shows its limits.

Example
Components separate two 2-regular graphs
123456
2C_3: two triangles, two components.

C6C_6 (vertices 1,…,61,\ldots,6, edges 12,23,34,45,56,1612,23,34,45,56,16) and 2C32C_3 (two disjoint triangles 123123 and 456456: edges 12,23,13,45,56,4612,23,13,45,56,46) both have 6 vertices, 6 edges, and every vertex of degree 2 — identical degree sequences. But C6C_6 is a single connected cycle, while 2C32C_3 splits into two components. "Number of connected components" is an invariant (an isomorphism maps components to components), and 1≠21 \ne 2, so C6≇2C3C_6 \not\cong 2C_3.

Example
Triangles separate two cubic graphs
123456
The triangular prism: 2 triangles, unlike K_3,3.

The complete bipartite graph K3,3K_{3,3} (parts {1,2,3}\{1,2,3\}, {4,5,6}\{4,5,6\}, all 9 cross edges) and the triangular prism (two triangles 123123, 456456 joined by a matching 14,25,3614,25,36, also 9 edges) are both 3-regular on 6 vertices — same ∣V∣|V|, ∣E∣|E|, and degree sequence. K3,3K_{3,3} has no triangle at all: every edge runs between the two parts, so three vertices forming a triangle would need an edge within a part, and there is none. The prism has exactly 2 triangles (123123 and 456456; the matching edges join the triangles but create no new one, e.g. 1,2,51,2,5 has edges 12,2512,25 but not 1515). Since 0≠20 \ne 2, the graphs are not isomorphic even though every invariant checked so far agreed.

Example
Sorting all graphs with 4 vertices and 3 edges by degree sequence

Up to isomorphism there are only 3 graphs on 4 vertices with exactly 3 edges, and the degree sequence sorts them instantly: (3,1,1,1)(3,1,1,1) is the star K1,3K_{1,3}; (2,2,1,1)(2,2,1,1) is the path P4P_4; (2,2,2,0)(2,2,2,0) is the triangle K3K_3 plus an isolated vertex. Every other way of placing 3 edges on 4 vertices is a relabeling of one of these three, since there is no room left for a fourth shape once these degree sequences are fixed.

Side note
Where it goes wrong

Even a long list of matching invariants can fail to force an isomorphism. The two trees on 6 vertices 1-2,1-3,1-4,4-5,5-61\text{-}2, 1\text{-}3, 1\text{-}4, 4\text{-}5, 5\text{-}6 (a "spider" with legs of length 1,1,31,1,3 from center 11) and 1-2,2-3,1-4,4-5,1-61\text{-}2, 2\text{-}3, 1\text{-}4, 4\text{-}5, 1\text{-}6 (a spider with legs 1,2,21,2,2 from center 11) have the same degree sequence (3,2,2,1,1,1)(3,2,2,1,1,1), both are trees (one component, zero triangles) — yet they are not isomorphic, because an isomorphism of these "spiders" would have to match up their leg lengths as a set, and {1,1,3}≠{1,2,2}\{1,1,3\} \ne \{1,2,2\}.

Try it
Try it: an invariant that settles it instantly

The "bowtie" (two triangles sharing one vertex: center 55 joined to 1,2,3,41,2,3,4, plus edges 1212 and 3434) and the "house" (a square 1-2-3-4-11\text{-}2\text{-}3\text{-}4\text{-}1 with a roof vertex 55 joined to 11 and 22) both have 5 vertices and 6 edges. Are they isomorphic?

Show the answer

The bowtie's center 55 has degree 4 (joined to all of 1,2,3,41,2,3,4), and the other four vertices each have degree 2, giving degree sequence (4,2,2,2,2)(4,2,2,2,2). In the house, the two roof-corners 1,21,2 have degree 3 (two square edges plus the roof) and the rest have degree 2, giving (3,3,2,2,2)(3,3,2,2,2). **Not isomorphic: (4,2,2,2,2)≠(3,3,2,2,2)(4,2,2,2,2) \ne (3,3,2,2,2).**

Self-Complementary Graphs

Concept
Self-complementary

A graph GG on nn vertices is self-complementary if G≅G‾G \cong \overline G. If so, ∣E(G)∣=∣E(G‾)∣|E(G)| = |E(\overline G)|, and since ∣E(G)∣+∣E(G‾)∣=(n2)|E(G)| + |E(\overline G)| = \binom n2 (Section 1), (n2)\binom n2 must be even — which forces n≡0n \equiv 0 or 1(mod4)1 \pmod 4.

A self-complementary graph is a fixed point of the complement operation up to relabeling: exactly half the possible edges of KnK_n are present, arranged so that filling in the OTHER half gives back something indistinguishable from the start. That "exactly half" is a strict headcount, so it rules out most nn immediately — no self-complementary graph can exist on 3, 6, or 7 vertices, since (32)=3\binom32=3, (62)=15\binom62=15, (72)=21\binom72=21 are all odd. It is also true, though harder to show, that a self-complementary graph exists for EVERY n≡0,1(mod4)n \equiv 0, 1 \pmod 4; the next two examples build the smallest two by hand.

Example
P4P_4 is self-complementary
1234
P_4, self-complementary.

Let G=P4G = P_4: vertices 1,2,3,41,2,3,4, edges 12,23,3412,23,34. Of the (42)=6\binom42=6 pairs, the 3 not used are 13,14,2413,14,24, so G‾\overline G has edges 13,14,2413,14,24. Those three edges form the path 3-1-4-23\text{-}1\text{-}4\text{-}2 (consecutive pairs 13,14,2413,14,24 share endpoints in a chain) — a path on 4 vertices, the same shape as GG. The relabeling φ:1↦3, 2↦1, 3↦4, 4↦2\varphi: 1\mapsto3,\,2\mapsto1,\,3\mapsto4,\,4\mapsto2 carries GG's edges 12,23,3412,23,34 to 31,14,4231,14,42, exactly G‾\overline G's edge set. So P4≅P4‾P_4 \cong \overline{P_4}.

Example
C5C_5 is self-complementary
12345
The complement of C_5, redrawn: also a 5-cycle.

Let G=C5G = C_5: vertices 1,…,51,\ldots,5, edges 12,23,34,45,1512,23,34,45,15. The (52)=10\binom52=10 pairs split into these 5 and the other 5: 13,14,24,25,3513,14,24,25,35. Tracing adjacencies in G‾\overline G — 11 to 3,43,4; 33 to 1,51,5; 55 to 2,32,3; 22 to 4,54,5; 44 to 1,21,2 — links up into the single cycle 1-3-5-2-4-11\text{-}3\text{-}5\text{-}2\text{-}4\text{-}1, another 5-cycle. So C5‾≅C5\overline{C_5} \cong C_5 as well: C5C_5 is the smallest self-complementary graph with no isolated structure to exploit, unlike P4P_4.

Example
Which nn from 3 to 8 can have one?

Check (n2)\binom n2 for n=3,…,8n=3,\ldots,8: 3,6,10,15,21,283,6,10,15,21,28. Only the even values survive the necessary condition: 66 (n=4n=4), 1010 (n=5n=5), and 2828 (n=8n=8); the odd values 3,15,213,15,21 (at n=3,6,7n=3,6,7) are impossible. That matches n≡0,1(mod4)n\equiv0,1\pmod4 exactly: 4≡04\equiv0, 5≡15\equiv1, 8≡08\equiv0, while 3,6,7≡3,2,3(mod4)3,6,7\equiv3,2,3\pmod4.

Side note
Where it goes wrong

Every graph is automatically edge-disjoint from its complement — that is just the definition, true for K4K_4 and the empty graph on 4 vertices as much as for P4P_4. It does NOT make them self-complementary. K4K_4 has 6 edges and its complement (the empty graph on 4 vertices) has 0; they are not remotely isomorphic. Self-complementary demands the much stronger ISOMORPHISM G≅G‾G \cong \overline G, not merely that GG and G‾\overline G share no edge.

Try it
Try it: ruling one out by counting

Is the "paw" graph (triangle 1,2,31,2,3 plus a pendant edge 3434) self-complementary?

Show the answer

The paw has 4 vertices and 4 edges. A self-complementary graph on 4 vertices needs exactly half of (42)=6\binom42=6 edges, namely 3 — but the paw has 4. **No: the edge count 4≠34 \ne 3 already rules it out, with no isomorphism check needed.**

Counting Graphs

Concept
Labeled vs. unlabeled counts

A simple graph on labeled vertices {1,…,n}\{1,\ldots,n\} is exactly a choice of which of the (n2)\binom n2 possible edges to include, so there are 2(n2)2^{\binom n2} labeled graphs on nn vertices. Relabeling never changes the graph up to isomorphism, so these 2(n2)2^{\binom n2} labeled graphs fall into far fewer isomorphism classes (unlabeled graphs) — but not 2(n2)/n!2^{\binom n2}/n! many, since graphs with extra symmetry get over-counted less by the relabelings.

The labeled count is easy because the (n2)\binom n2 possible edges are independent, all-or-nothing choices — a direct instance of counting subsets of a set (proved in full in "Why It Works"). The unlabeled count is a genuinely different, harder question: the n!n! relabelings of a labeled graph often produce the SAME labeled graph back (whenever the relabeling is an automorphism), so dividing by n!n! overcorrects for symmetric graphs and undercorrects for asymmetric ones. The worked examples below total both counts directly for small nn to see exactly where the naive division goes wrong.

Example
All labeled graphs on 3 vertices, sorted by shape

On vertices 1,2,31,2,3 there are 2(32)=23=82^{\binom32}=2^3=8 labeled graphs (independently include or exclude 12,13,2312,13,23), and every one of them is a relabeling of exactly one of 4 shapes: the empty graph (1 labeled copy), a single edge (3 labeled copies — one for each edge choice), a path on all 3 vertices (3 labeled copies — one for each choice of the missing edge), or the full triangle (1 labeled copy). These counts total 1+3+3+1=81+3+3+1=8, matching 232^3 exactly, and there are 4\mathbf{4} shapes up to isomorphism.

Example
Labeled and unlabeled graphs on 4 vertices

On 4 vertices, (42)=6\binom42=6, so there are 26=642^6=64 labeled graphs. Sorting these 64 by isomorphism class (by hand or by computer, checking every candidate pair of graphs for a relabeling) gives exactly 11 shapes — far fewer than 64/4!=64/24≈2.6764/4! = 64/24 \approx 2.67, which is not even an integer, let alone the right answer.

Example
Graphs on 5 vertices with exactly 3 edges
12345
P_3 ∪ K_2: one of the 4 shapes with 5 vertices and 3 edges.

How many labeled graphs on 5 vertices have exactly 3 edges, and how many shapes do they represent up to isomorphism? There are (103)=120\binom{10}{3}=120 ways to choose 3 of the (52)=10\binom52=10 possible edges, so 120 labeled graphs. Up to isomorphism there are exactly 4 shapes: a triangle plus 2 isolated vertices, a path P4P_4 plus 1 isolated vertex, a star K1,3K_{1,3} plus 1 isolated vertex, and a disjoint path-plus-edge P3∪K2P_3 \cup K_2 using all 5 vertices with none isolated — every other placement of 3 edges on 5 vertices is a relabeling of one of these.

Side note
Where it goes wrong

Dividing the labeled count by n!n! does not give the unlabeled count, and the 3-vertex case shows it fails outright: 8/3!=8/6=4/38/3! = 8/6 = 4/3, not even a whole number, while the true unlabeled count is 4. The division assumes every graph is turned into n!n! DIFFERENT labeled graphs by relabeling, which is false exactly when a graph has a nontrivial automorphism — the empty graph and the triangle are each fixed by all 3!=63!=6 relabelings, contributing only 1 labeled graph apiece instead of 6, which is why 1+3+3+1=81+3+3+1=8 and not something closer to 4×6=244\times6=24.

Try it
Try it: labeled graphs on 6 vertices

How many labeled simple graphs are there on 6 vertices?

Show the answer

There are (62)=15\binom62=15 possible edges, each independently in or out, so the count is 2152^{15}. 210=10242^{10}=1024 and 25=322^5=32, so 215=1024×32=327682^{15} = 1024 \times 32 = \mathbf{32768}.

Why It Works

Reflexive: the identity map id:V(G)→V(G)\mathrm{id}: V(G)\to V(G) is a bijection with uv∈E(G)  ⟺  id(u)id(v)∈E(G)uv\in E(G) \iff \mathrm{id}(u)\mathrm{id}(v)\in E(G) trivially, so G≅GG\cong G. Symmetric: if φ:V(G)→V(H)\varphi: V(G)\to V(H) is an isomorphism then φ−1:V(H)→V(G)\varphi^{-1}: V(H)\to V(G) is also a bijection, and applying the iff in both directions, xy∈E(H)  ⟺  φ−1(x)φ−1(y)∈E(G)xy\in E(H) \iff \varphi^{-1}(x)\varphi^{-1}(y)\in E(G) (substitute x=φ(u),y=φ(v)x=\varphi(u), y=\varphi(v) into the defining property of φ\varphi), so H≅GH\cong G. Transitive: if φ:V(G)→V(H)\varphi: V(G)\to V(H) and ψ:V(H)→V(K)\psi: V(H)\to V(K) are isomorphisms, their composite ψ∘φ:V(G)→V(K)\psi\circ\varphi: V(G)\to V(K) is a bijection (a composite of bijections is a bijection), and uv∈E(G)  ⟺  φ(u)φ(v)∈E(H)  ⟺  ψ(φ(u))ψ(φ(v))∈E(K)uv\in E(G) \iff \varphi(u)\varphi(v)\in E(H) \iff \psi(\varphi(u))\psi(\varphi(v))\in E(K), so G≅KG\cong K. All three properties hold, so ≅\cong partitions every collection of graphs into isomorphism classes.

Suppose G≅G‾G\cong\overline G on nn vertices. Isomorphic graphs have the same number of edges, so ∣E(G)∣=∣E(G‾)∣|E(G)|=|E(\overline G)|; combined with ∣E(G)∣+∣E(G‾)∣=(n2)|E(G)|+|E(\overline G)|=\binom n2 (every pair is an edge of exactly one of G,G‾G,\overline G), this gives (n2)=2∣E(G)∣\binom n2 = 2|E(G)|, an even number. Now (n2)=n(n−1)2\binom n2 = \frac{n(n-1)}2, so n(n−1)≡0(mod4)n(n-1) \equiv 0 \pmod 4. Since nn and n−1n-1 are consecutive, exactly one is even. If nn is even: n−1n-1 is odd, so 4∣n(n−1)4\mid n(n-1) forces 4∣n4\mid n, i.e. n≡0(mod4)n\equiv0\pmod4 (if instead n≡2(mod4)n\equiv2\pmod4 then n(n−1)≡2×odd≡2(mod4)n(n-1)\equiv2\times\text{odd}\equiv2\pmod4, not 00). If nn is odd: n−1n-1 is even, so by the same argument 4∣(n−1)4\mid(n-1), i.e. n≡1(mod4)n\equiv1\pmod4 (if instead n−1≡2(mod4)n-1\equiv2\pmod4, i.e. n≡3(mod4)n\equiv3\pmod4, then again n(n−1)≡2(mod4)n(n-1)\equiv2\pmod4). So in every case n≡0n\equiv0 or 1(mod4)1\pmod4.

A simple graph on vertex set {1,…,n}\{1,\ldots,n\} is, by definition, a set of edges E⊆({1,…,n}2)E\subseteq\binom{\{1,\ldots,n\}}2, the set of all (n2)\binom n2 unordered pairs — nothing more, since the vertex set is fixed and simple graphs forbid loops and repeated edges. Conversely every subset of ({1,…,n}2)\binom{\{1,\ldots,n\}}2 is a valid edge set. So labeled graphs on {1,…,n}\{1,\ldots,n\} correspond exactly, one-to-one, to subsets of a set of size (n2)\binom n2. A set of size mm has exactly 2m2^m subsets (each of the mm elements is independently in or out, by the product rule), so there are exactly 2(n2)2^{\binom n2} labeled graphs on nn vertices.

Reminder — The differentiation rules:  (xn)′=nxn−1,(fg)′=f′g+fg′,(fg)′=f′g−fg′g2,(f(g(x)))′=f′(g(x))g′(x)(x^{n})'=nx^{n-1},\quad (fg)'=f'g+fg',\quad \left(\tfrac{f}{g}\right)'=\frac{f'g-fg'}{g^{2}},\quad \big(f(g(x))\big)'=f'(g(x))g'(x)