IAE Academy

GATE CS

Graph theory

Connectivity, matching and colouring

Graph theory studies vertices and edges and the structure they force: how many edges a graph can have, when it is connected and how strongly, when vertices can be paired off (matching), how many colours a proper colouring needs, and when it can be drawn without crossings. The working tools are a handful of counting results (handshaking, tree and planar bounds, chromatic numbers of standard graphs) and a few theorems (Hall, König, Euler, Dirac) applied to a given graph.

14 previous-year questions · 14 solved · 6 practice questions

Terminology, degrees and the handshaking lemma

Convention: a simple graph has no loops and no parallel edges; graphs are simple unless a question says otherwise. A multigraph allows parallel edges (and sometimes loops). In a directed graph each edge is an ordered pair. is the number of vertices, the number of edges. The degree of a vertex is the number of edge-ends at it (a loop adds 2). A graph is -regular if every vertex has degree . The degree sequence lists the degrees, usually in non-increasing order.

HANDSHAKING LEMMA

Holds for every undirected graph (loops count 2). So the number of odd-degree vertices is always even.

DIRECTED HANDSHAKING

In a directed graph, total out-degree equals total in-degree equals the number of edges.

MOST EDGES IN A SIMPLE GRAPH

Attained exactly by the complete graph . A -regular simple graph on vertices has edges, so it can exist only if is even and .

A walk is a sequence of vertices with consecutive ones adjacent (vertices and edges may repeat). A trail repeats no edge. A path repeats no vertex. A cycle is a closed path of length at least 3 in a simple graph. A degree sequence is graphical if some simple graph has it: the sum must be even, and each degree must be at most ; beyond this, further tests are needed (for example, has even sum but is not graphical, since three vertices of degree 3 would each be adjacent to all others, forcing the last vertex to have degree 3).

Havel-Hakimi test for a graphical sequence

  1. Sort the sequence .

  2. Delete and subtract 1 from each of the next entries; the original is graphical exactly when the new sequence is.

  3. Repeat. If a negative entry appears, or exceeds the number of remaining entries, the sequence is not graphical; if all entries become 0, it is graphical.

  4. Example: , a negative entry, so not graphical.

EXAM TIP

To show a degree sequence is impossible, first check parity of the sum, then try the largest degree: a vertex of degree is adjacent to everything, so no vertex can have degree 0.

Connectivity, cut vertices, bridges and trees

A graph is connected if there is a path between every pair of vertices; otherwise it splits into components. A cut vertex is a vertex whose removal (with its edges) increases the number of components. A bridge is an edge whose removal increases the number of components; an edge is a bridge exactly when it lies on no cycle. A tree is a connected graph with no cycle; a forest is a graph with no cycle.

EDGES NEEDED FOR $K$ COMPONENTS

A graph with vertices and components has at least edges; so a connected graph has at least edges. Equality holds exactly for forests.

MOST EDGES IN A DISCONNECTED SIMPLE GRAPH

Simple graph on vertices with at least 2 components. Attained by plus one isolated vertex. With exactly components the maximum is .

MINIMUM-DEGREE TEST FOR CONNECTIVITY

For a simple graph on vertices with minimum degree : any two non-adjacent vertices then have a common neighbour. This is sufficient, not necessary.

VERTEX AND EDGE CONNECTIVITY

The vertex connectivity is the fewest vertices whose removal disconnects or leaves a single vertex; the edge connectivity is the fewest edges whose removal disconnects . . A connected graph on vertices has a cut vertex exactly when , and a connected graph on vertices has a bridge exactly when .

Equivalent descriptions of a tree on $n$ vertices

  1. Connected and acyclic.

  2. Connected and has exactly edges.

  3. Acyclic and has exactly edges.

  4. There is exactly one path between any two vertices.

  5. Connected, and removing any edge disconnects it (every edge is a bridge).

LEAVES OF A TREE

For a tree with vertices. In particular every such tree has at least 2 leaves (vertices of degree 1).

CAYLEY'S FORMULA

Number of labelled trees on vertices, which equals the number of spanning trees of . Also and .

Matrix-tree idea. Let be the Laplacian ( the diagonal matrix of degrees, the adjacency matrix). The number of spanning trees of a connected graph equals any cofactor of : delete one row and the same-numbered column, then take the determinant. The multiplicity of eigenvalue 0 of equals the number of components.

Special graphs, bipartite graphs, isomorphism and complements

Graph

Vertices

Edges

Notes

(complete)

Every pair adjacent; -regular

(cycle, )

2-regular, connected

(path on vertices)

A tree

Complete bipartite

Wheel (hub + cycle on rim vertices)

Hub has degree , rim vertices degree 3; some questions write for the wheel with vertices in total, so check which

Hypercube

-regular, bipartite

Petersen graph

10

15

3-regular, shortest cycle has length 5, not planar

A graph is bipartite if its vertices split into two sets with every edge between the sets. Test: a graph is bipartite exactly when it has no odd cycle (equivalently, it can be 2-coloured). A bipartite simple graph on vertices has at most edges, attained by . Every tree and every even cycle is bipartite.

Isomorphism. Graphs are isomorphic if a bijection of vertices preserves adjacency. To show two graphs are not isomorphic, find an invariant that differs: number of vertices, number of edges, degree sequence, number of cycles of a given length, connectedness, bipartiteness. Equal invariants do not prove isomorphism; for that, exhibit the bijection.

COMPLEMENT EDGE COUNT

For a simple graph , the complement has the same vertices and exactly the non-edges of . Degrees satisfy .

SELF-COMPLEMENTARY GRAPHS

Necessary conditions on the order and size of a simple self-complementary graph. Examples: (4 vertices, 3 edges) and (5 vertices, 5 edges).

For any simple graph, at least one of and is connected.

Matchings, vertex covers and independent sets

A matching is a set of edges, no two sharing a vertex. A maximum matching has the most edges; a perfect matching covers every vertex (so is even and it has edges). A vertex cover is a set of vertices touching every edge. An independent set is a set of pairwise non-adjacent vertices. Write for the maximum matching size, for the minimum vertex cover size and for the maximum independent set size. Always .

INDEPENDENT SET AND VERTEX COVER

Holds for every simple (loopless) graph: a set is independent exactly when its complement is a vertex cover.

KÖNIG'S THEOREM

Every vertex cover needs a distinct vertex for each matching edge, so always; equality is guaranteed only for bipartite graphs. (The triangle has , .)

HALL'S CONDITION

A bipartite graph with parts has a matching covering every vertex of if and only if this holds, where is the set of neighbours of . When , this is the condition for a perfect matching.

GALLAI: MATCHING AND EDGE COVER

For a graph with no isolated vertex, the minimum edge cover size plus the maximum matching size equals .

Useful facts about matchings

  1. A -regular bipartite graph with has a perfect matching (it satisfies Hall's condition).

  2. has perfect matchings; has .

  3. with has and .

  4. A tree has at most one perfect matching.

  5. The Petersen graph has a perfect matching.

WORKED EXAMPLE

A bipartite graph is . Find the size of a maximum matching, a minimum vertex cover and a maximum independent set.

Solution
  1. has 10 vertices; each vertex of the smaller side can be matched to a distinct vertex of the larger side, and no matching can use more than the 4 vertices of that side, so .

  2. The graph is bipartite, so by König's theorem (the 4-vertex side is a cover).

  3. By , (the 6-vertex side).

Answer: Maximum matching 4, minimum vertex cover 4, maximum independent set 6.

EXAM TIP

To disprove a perfect matching in a bipartite graph, find a set with . If the two sides have different sizes, there is no perfect matching at once.

Colouring and planar graphs

A proper colouring gives adjacent vertices different colours. The chromatic number is the fewest colours needed. The clique number is the size of the largest complete subgraph, and . Each colour class is an independent set, so .

Graph

Chromatic number

Cycle , even

2

Cycle , odd

3

Any graph with at least one edge that is bipartite (including trees on 2 or more vertices)

2

Edgeless graph

1

Wheel with hub and rim cycle of even length

3

Wheel with hub and rim cycle of odd length

4

Petersen graph

3

GREEDY COLOURING BOUND

For every graph, where is the maximum degree. By Brooks' theorem, a connected graph that is neither a complete graph nor an odd cycle has .

CHROMATIC POLYNOMIALS

is the number of proper colourings of using at most colours, with the colours and vertices labelled. is any tree on vertices; needs . Check: . is the least with .

EDGE COLOURING

The chromatic index is the fewest colours that give edges sharing a vertex different colours. The bounds hold for every simple graph (Vizing). A bipartite graph has . for even and for odd .

Four-colour theorem: every loopless planar graph has . A graph is planar if it can be drawn in the plane with no edge crossings; a drawing divides the plane into faces, including the outer face. The degree of a face is the length of the closed walk around its boundary, with a bridge counted twice.

EULER'S FORMULA

For a connected planar graph (drawn without crossings). With components the right side is .

EDGE BOUND FOR SIMPLE PLANAR GRAPHS

For a simple planar graph with . If the graph also has no triangle (for example, it is bipartite), . Reason: in a simple connected planar graph with , every face has degree at least 3 (at least 4 with no triangle), and . More generally, if every cycle has length at least , then .

Planarity facts

  1. and are not planar (for : ; for : ).

  2. Kuratowski: a graph is planar exactly when it has no subdivision of or as a subgraph.

  3. is planar exactly when ; is planar exactly when .

  4. Every simple planar graph has a vertex of degree at most 5.

  5. Subgraphs of planar graphs are planar.

WORKED EXAMPLE

A connected planar simple graph is 3-regular with 8 vertices. How many faces does a planar drawing have? Is satisfied?

Solution
  1. By handshaking, , so .

  2. Euler: .

  3. Bound: , consistent. (The cube graph is such a graph.)

Answer: 6 faces; the bound holds.

Euler and Hamiltonian graphs, and the adjacency matrix

Property

Condition (all edges in one connected piece; isolated vertices ignored)

Euler circuit (closed trail using every edge once), undirected

All degrees even

Euler trail that is not closed, undirected

Exactly 2 vertices of odd degree (the trail starts at one and ends at the other)

Directed Euler circuit

In-degree equals out-degree at every vertex, and the vertices with edges form one strongly connected piece

Directed Euler trail that is not closed

One vertex has out-degree minus in-degree equal to 1 (the start), one has in-degree minus out-degree equal to 1 (the end), all others have in-degree equal to out-degree, and the edges form one connected piece when directions are ignored

A Hamiltonian cycle visits every vertex exactly once and returns to the start; a Hamiltonian path visits every vertex once. Unlike Euler, no simple exact test exists; only sufficient conditions.

DIRAC'S THEOREM

Simple graph with . Ore's generalisation: if for every pair of non-adjacent , then is Hamiltonian. Both are sufficient only.

HAMILTONIAN CYCLES IN $K_N$

For , labelled vertices, counting a cycle and its reverse as the same. is Hamiltonian exactly when , and () has Hamiltonian cycles (1 for , 6 for ).

A Hamiltonian cycle in a bipartite graph alternates between the parts, so a bipartite graph with parts of unequal size has no Hamiltonian cycle. A Hamiltonian path in a bipartite graph needs part sizes that differ by at most 1, so if they differ by 2 or more there is no Hamiltonian path.

POWERS OF THE ADJACENCY MATRIX

For the adjacency matrix of a graph (directed or undirected; in a multigraph counts parallel edges, and a loop is entered as 1 in ). Walks may repeat vertices.

What $A$ tells you (simple undirected graph)

  1. Row sums of are the degrees, so .

  2. , so the eigenvalues of sum to 0.

  3. .

  4. .

  5. is symmetric, so its eigenvalues are real; for a -regular graph the largest eigenvalue is .

  6. For a bipartite graph the spectrum is symmetric about 0: if is an eigenvalue, so is , with the same multiplicity.

EXAM TIP

Counting edges from : the number of non-zero entries of a simple undirected graph's is , not . Counting trails or paths (rather than walks) cannot be done from directly.

PREVIOUS-YEAR QUESTIONS

14 questions from the CS papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE CSE 2026 Set 1 · GATE CSE 2024 Set 1 · GATE CSE 2024 Set 2 · GATE CSE 2022 · GATE CSE 2020 · GATE CSE 2018

GATE 2026 CS1 Q.47

GATE 2026 · CS1Q.47 · 2 marks · MSQ

Let be a simple, undirected graph. A vertex cover of is a subset such that for every , or . Let the size of the smallest vertex cover in be . Let be any vertex cover of size .

For a vertex , which of the following constraints will always ensure that ?

  1. (A)

    The degree of is at least

  2. (B)

    The vertex is on a path of length

  3. (C)

    The vertex is on a cycle of length

  4. (D)

    The vertex is a part of a clique of size

Answer and solution
See the question in the paper
GATE 2026 CS1 Q.47: answer and solution

GATE 2024 CS1 Q.51

GATE 2024 · CS1Q.51 · 2 marks · MSQ

The chromatic number of a graph is the minimum number of colours used in a proper colouring of the graph. Let be any graph with vertices and chromatic number . Which of the following statements is/are always TRUE?

  1. (A)

    contains a complete subgraph with vertices

  2. (B)

    contains an independent set of size at least

  3. (C)

    contains at least edges

  4. (D)

    contains a vertex of degree at least

Answer and solution
See the question in the paper
GATE 2024 CS1 Q.51: answer and solution

GATE 2024 CS2 Q.60

GATE 2024 · CS2Q.60 · 2 marks · NAT

The chromatic number of a graph is the minimum number of colours used in a proper colouring of the graph. The chromatic number of the following graph is ______.

GATE 2024 CS2 question 60: A graph on 8 vertices drawn at the corners of an octagon, labelled in order around the outline: v0 top-left, v1…Tap to open full size
Figure from the GATE 2024 CS2 paper. It is part of the question.
Figure description

A graph on 8 vertices drawn at the corners of an octagon, labelled in order around the outline: v0 top-left, v1 top-right, v2 right-upper, v3 right-lower, v4 bottom-right, v5 bottom-left, v6 left-lower, v7 left-upper. Edges: the slanted and side outline edges v1-v2, v2-v3, v3-v4, v5-v6, v6-v7, v7-v0; the two verticals v0-v5 and v1-v4; the two horizontals v7-v2 and v6-v3; and the four diagonals v0-v3, v1-v6, v7-v4, v2-v5. The short edges between the two top vertices (v0-v1) and between the two bottom vertices (v4-v5) do not clearly appear in the picture; the answer is the same whether or not they are present.

Answer and solution
GATE 2024 CS2 Q.60: answer and solution

GATE 2022 CS Q.50

GATE 2022 · CSQ.50 · 2 marks · MSQ

The following simple undirected graph is referred to as the Peterson graph. Which of the following statements is/are TRUE?

GATE 2022 CS question 50: Top figure: the Peterson graph drawn as an outer regular pentagon with 5 vertices and an inner pentagram (five-pointed…Tap to open full size
Figure from the GATE 2022 CS paper. It is part of the question.
Figure description

Top figure: the Peterson graph drawn as an outer regular pentagon with 5 vertices and an inner pentagram (five-pointed star) with 5 vertices. Each outer vertex is joined to the nearest inner star tip; the inner 5 vertices are joined as a pentagram (each inner vertex to the two inner vertices two steps away). 10 vertices, 15 edges. Option (C) figure: a graph on 10 vertices: 9 vertices on the boundary of a nonagon (top, upper-right, right, lower-right, bottom-right, bottom-left, lower-left, left, upper-left), joined in a 9-cycle, plus one centre vertex. Chords: top to centre (vertical line), left to right (horizontal line), upper-left to bottom-right, upper-right to bottom-left, and centre to lower-left and centre to lower-right. 15 edges in all.

  1. (A)

    The chromatic number of the graph is 3.

  2. (B)

    The graph has a Hamiltonian path.

  3. (C)

    The following graph is isomorphic to the Peterson graph. [Figure — a 9-cycle of boundary vertices plus a centre vertex, with six chords as described]

  4. (D)

    The size of the largest independent set of the given graph is 3. (A subset of vertices of a graph form an independent set if no two vertices of the subset are adjacent.)

Answer and solution
GATE 2022 CS Q.50: answer and solution

GATE 2022 CS Q.52

GATE 2022 · CSQ.52 · 2 marks · MSQ

Which of the properties hold for the adjacency matrix of a simple undirected unweighted graph having vertices?

  1. (A)

    The diagonal entries of are the degrees of the vertices of the graph.

  2. (B)

    If the graph is connected, then none of the entries of can be zero.

  3. (C)

    If the sum of all the elements of is at most , then the graph must be acyclic.

  4. (D)

    If there is at least a 1 in each of 's rows and columns, then the graph must be connected.

Answer and solution
See the question in the paper
GATE 2022 CS Q.52: answer and solution
Show the other 4 questions

GATE 2022 CS Q.58

GATE 2022 · CSQ.58 · 2 marks · NAT

Let be a directed graph, where is the set of vertices and is the set of directed edges, as defined by the following adjacency matrix .

indicates a directed edge from node to node . A directed spanning tree of , rooted at , is defined as a subgraph of such that the undirected version of is a tree, and contains a directed path from to every other vertex in . The number of such directed spanning trees rooted at vertex is ______.

Answer and solution
See the question in the paper
GATE 2022 CS Q.58: answer and solution

GATE 2018 CS Q.18

GATE 2018 · CSQ.18 · 1 mark · NAT

The chromatic number of the following graph is ________.

GATE 2018 CS question 18: An undirected graph on six vertices a, b, c, d, e, f.Tap to open full size
Figure from the GATE 2018 CS paper. It is part of the question.
Figure description

An undirected graph on six vertices a, b, c, d, e, f. Layout: a top-left, e top-right, c and d in the middle (c left of centre, d right of centre), b bottom-left, f bottom-right. Ten edges: a-e, a-c, a-b, e-c, e-f, c-d, c-b, d-b, d-f, b-f.

Answer and solution
GATE 2018 CS Q.18: answer and solution

GATE 2018 CS Q.43

GATE 2018 · CSQ.43 · 2 marks · NAT

Let be a graph with vertices, with each vertex labelled by a distinct permutation of the numbers . There is an edge between vertices and if and only if the label of can be obtained by swapping two adjacent numbers in the label of . Let denote the degree of a vertex in , and denote the number of connected components in . Then, ______.

Answer and solution
See the question in the paper
GATE 2018 CS Q.43: answer and solution

OTHER EXAMS

ISRO: 4 questions

From ISRO's Scientist/Engineer written test: ISRO CS 2025, ISRO CS 2023. They are not counted in the GATE numbers on this page.

ISRO CS 2025 Q.5

ISRO 2025 · CSQ.5 · 1 mark · MCQ

There are 20 shopping malls in a city interconnected by roads. Each shopping mall can be reached through 3 different roads. It is assumed that (i) only one park is planned to be constructed in a region, (ii) roads do not cross each other, (iii) road(s) do not pass through a park. What is the maximum number of parks that can be constructed in the regions enclosed by roads?

  1. (A)

    12

  2. (B)

    30

  3. (C)

    60

  4. (D)

    11

Answer and solution
See the question in the paper
ISRO CS 2025 Q.5: answer and solution

ISRO CS 2025 Q.6

ISRO 2025 · CSQ.6 · 1 mark · MCQ

What is the chromatic number of the graph shown below?

ISRO CS 2025 question 6: Undirected graph on 8 vertices a, b, c, d, e, f, g, h.Tap to open full size
Figure from the ISRO CS 2025 paper. It is part of the question.
Figure description

Undirected graph on 8 vertices a, b, c, d, e, f, g, h. Edges: a-f, a-e, e-d, e-f, e-g, f-g, f-h, f-b, g-h, g-c, g-d, h-b, h-c. Layout: a top-left, f top-centre, b top-right, e left-middle, h right-middle, d bottom-left, g bottom-centre, c bottom-right. Triangles e-f-g and f-g-h share edge f-g; e and h are not adjacent.

  1. (A)

    3

  2. (B)

    4

  3. (C)

    5

  4. (D)

    6

Answer and solution
ISRO CS 2025 Q.6: answer and solution

ISRO CS 2023 Q.42

ISRO 2023 · CSQ.42 · 1 mark · MCQ

42. Which of the following are true?
(i) In a graph G with 'n' vertices and 'e' edges, sum of degrees of vertices = 2*e
(ii) Eccentricity of a connected graph can never be equal to radius of the graph
(iii) Girth of a graph is the total number of edges in the shortest cycle of the graph
(iv) Graph with equal degree for all vertices is multigraph

  1. (A)

    (i), (ii), (iii)

  2. (B)

    (ii), (iii), (iv)

  3. (C)

    (i), (iii), (iv)

  4. (D)

    None of the above

Answer and solution
See the question in the paper
ISRO CS 2023 Q.42: answer and solution

PRACTICE

6 questions to test yourself

PRACTICE 11 mark · MCQ

A simple undirected graph has 11 vertices and is not connected. What is the largest possible number of edges it can have?

  1. (A)

    45

  2. (B)

    55

  3. (C)

    36

  4. (D)

    50

Answer and solution

Answer: (A)

  1. For a disconnected simple graph the maximum is , from plus an isolated vertex.

  2. With : .

  3. 55 is , which is the complete graph and is connected.

PRACTICE 22 marks · NAT

A connected simple planar graph has 9 vertices, and in a plane drawing every face (including the outer face) has degree exactly 4 (its boundary walk has 4 edges). How many edges does the graph have?

Answer and solution

Answer:

  1. Each face has degree 4, and the sum of face degrees is , so and .

  2. Euler: , so and (with ).

  3. Check: , the bound for triangle-free planar graphs, met with equality. drawn with 7 four-sided faces is such a graph.

PRACTICE 32 marks · MSQ

The Petersen graph has 10 vertices, is 3-regular and has 15 edges, with shortest cycle of length 5. Which of the following statements are true?

  1. (A)

    Its chromatic number is 3.

  2. (B)

    It is planar.

  3. (C)

    It has a perfect matching.

  4. (D)

    It is bipartite.

Answer and solution

Answer: (A), (C)

  1. It contains 5-cycles, so it is not bipartite (D false) and ; it can be coloured with 3 colours, so (A true).

  2. If it were planar, Euler would give faces, each of degree at least 5, so , that is , which is false. So it is not planar (B false); it contains a subdivision of .

  3. It has a perfect matching of 5 edges (C true).

PRACTICE 41 mark · NAT

A simple self-complementary graph has 9 vertices. How many edges does it have?

Answer and solution

Answer:

  1. .

  2. Since , both have the same number of edges, so (and , as required).

PRACTICE 52 marks · MCQ

A bipartite graph has 12 vertices and a perfect matching. What is the size of its largest independent set?

  1. (A)

    4

  2. (B)

    5

  3. (C)

    6

  4. (D)

    7

Answer and solution

Answer: (C)

  1. A perfect matching has edges, so .

  2. For a bipartite graph, König gives .

  3. Then .

PRACTICE 61 mark · NAT

How many spanning trees does the complete bipartite graph (labelled vertices) have?

Answer and solution

Answer:

  1. Formula: , so .

  2. Check by listing: has 6 edges and 5 vertices, so a spanning tree keeps 4 edges, i.e. removes 2 of the 6: choices.

  3. The remaining 4 edges fail to form a tree exactly when both edges at one of the three degree-2 vertices are removed (3 choices), since 4 edges on 5 vertices form a tree exactly when connected. So .

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE CS

Graphs: connectivity, matching, colouring

Preparing in Kolkata? IAE Academy's course for GATE CSE.