Module 1 · 17 min read · Free chapter
Graph theory: connectivity, matching and colouring
The sum of degrees is twice the number of edges. A connected graph has an Euler circuit exactly when all degrees are even. Kₙ has nⁿ⁻² spanning trees. A connected planar graph satisfies v − e + f = 2 and e ≤ 3v − 6. Odd cycles need 3 colours and bipartite graphs need 2.
Start from zero: stations and tracks
Look at a railway map of a state. There are stations, and some pairs of stations are joined directly by a track. To answer "can I go from Patna to Gaya without passing through Jehanabad?", you do not need distances, timings or the shape of the tracks. You only need to know which stations are joined.
That bare structure is a graph: a set of points called vertices and a set of links called edges. The number of tracks leaving a station is its degree. A junction whose closure cuts the network into pieces is exactly what network engineers fear most.
Graphs model road networks, computer networks, friendships on social media, dependencies between tasks and even the clash table of an exam timetable. This chapter builds the main ideas: degrees, connectivity, special walks, trees, planarity, matching and colouring.
Why it matters. Nearly every algorithm on networks starts from these definitions. GATE asks for edge counts, Euler's formula, chromatic numbers and matching sizes in short numerical questions that reward a sound grip on the basics.
Graphs, degrees and special families
A graph has a vertex set and an edge set , where each edge joins two vertices. A simple graph has no loops and no repeated edges, while a multigraph allows repeated edges. In a directed graph each edge has a direction, and each vertex has an in-degree and an out-degree.
The most useful fact about degrees is the handshaking lemma: the sum of all degrees equals , because each edge adds 1 to the degree of both its ends. So the number of vertices of odd degree is always even. If a graph has degrees 3, 3, 2, 2, 2, the degree sum is 12 and the graph has 6 edges.
A simple graph on vertices has at most edges, one for every pair. Since each pair is either an edge or not, there are labelled simple graphs on vertices.
| Graph | Vertices | Edges |
|---|---|---|
| Complete graph | ||
| Cycle | ||
| Complete bipartite | ||
| k-regular graph | ||
| Hypercube |
The complement of has the same vertices and an edge exactly where has none. So and its complement together have edges. A graph equal in shape to its complement is called self-complementary, and it must have edges.
Worked example. Can a simple graph have degrees 3, 3, 3, 1? The sum is 10, which is even, but three vertices of degree 3 must each be joined to all others, so the last vertex would need degree 3. Hence no such simple graph exists, which shows that an even degree sum is necessary but not sufficient.
Why it matters. Degree counting is the quickest check in many GATE questions. It also explains why a 3-regular graph must have an even number of vertices, since must be a whole number.
Paths, connectivity, cut vertices and bridges
A walk is a sequence of vertices where each consecutive pair is an edge. A path is a walk with no repeated vertex, and a cycle is a closed walk with no repeated vertex except the first and last. A graph is connected if every two vertices are joined by a path, and its maximal connected pieces are its components.
Edge counts give quick tests for connectivity. A connected graph on vertices needs at least edges. At the other end, a simple graph with vertices and components has at most edges, reached by putting vertices in one complete piece and leaving the rest isolated.
From that bound, a simple graph on vertices with more than edges must be connected. For , any simple graph with more than 36 edges is connected, while 36 edges are not enough, since plus one isolated vertex has exactly 36.
A cut vertex is a vertex whose removal increases the number of components, and a bridge is an edge whose removal does so. An edge is a bridge exactly when it lies on no cycle, so every edge of a tree is a bridge. The vertex connectivity is the fewest vertices whose removal disconnects , and the edge connectivity is the fewest edges.
These numbers obey , where is the minimum degree. The right inequality is easy, because removing all edges at a vertex of minimum degree isolates it. For , all three equal .
Why it matters. Cut vertices and bridges are single points of failure in a network. Designers add links until is at least 2 so that no single router failure can split the network, and depth-first search finds all such weak points in linear time.
Euler and Hamiltonian graphs
In 1736 the people of Königsberg asked whether they could walk across each of their seven bridges exactly once. Euler turned the town into a graph and gave the answer. An Euler circuit uses every edge exactly once and returns to the start, and an Euler path uses every edge exactly once but may end elsewhere.
The test is entirely about degrees. A connected graph has an Euler circuit exactly when every vertex has even degree. It has an Euler path that is not a circuit exactly when it has exactly two vertices of odd degree, and the path must start at one of them and end at the other.
A Hamiltonian cycle visits every vertex exactly once and returns to the start. Unlike the Euler case, no simple test is known, and deciding whether one exists is a hard problem. Two sufficient conditions are standard: Dirac's theorem says that a simple graph on vertices with every degree at least is Hamiltonian, and Ore's theorem needs only for every non-adjacent pair , .
Worked example. How many distinct Hamiltonian cycles does have? Fix a starting vertex and arrange the other 4 in orders. Each cycle is counted twice, once in each direction, so there are distinct Hamiltonian cycles.
The bipartite graph with has no Hamiltonian cycle, because a cycle must alternate between the two sides and so uses equal numbers from each. This parity argument is a quick way to rule out Hamiltonian cycles in many GATE options.
Why it matters. Euler paths model route inspection, such as a road-sweeper covering every street once. Hamiltonian cycles model the travelling salesman problem, and the gap between "easy degree test" and "no known fast test" is a first glimpse of NP-completeness.
Trees and spanning trees
A tree is a connected graph with no cycle. Several conditions are equivalent for a graph on vertices: is a tree; is connected with edges; has no cycle and has edges; every two vertices of are joined by exactly one path. Any one of these can serve as the definition.
Every tree with at least two vertices has at least two leaves, vertices of degree 1. A forest is a graph with no cycle, so each component is a tree, and a forest with vertices and components has edges.
A spanning tree of a connected graph is a tree that uses all the vertices of and some of its edges. Every connected graph has one, found by deleting edges from cycles until none are left. Cayley's formula says that the complete graph has spanning trees, which is also the number of labelled trees on vertices.
Worked example. has spanning trees, and has . The cycle has exactly spanning trees, because removing any one of its edges leaves a path. For a general graph, the matrix-tree theorem gives the count as any cofactor of its Laplacian matrix.
Worked example 2. A tree has 4 vertices of degree 3 and the rest are leaves. How many leaves does it have? If there are leaves, then and the degree sum is , so .
Why it matters. Spanning trees are the backbone of network design and of the broadcast protocol that switches use to avoid loops. Minimum spanning trees, built by greedy algorithms, are covered in greedy algorithms and minimum spanning trees.
Planar graphs and Euler's formula
A graph is planar if it can be drawn in the plane with no two edges crossing. Such a drawing cuts the plane into regions called faces, including the unbounded outer face. A cube's graph, for example, can be drawn flat with 8 vertices, 12 edges and 6 faces.
Euler's formula links these counts. For a connected planar graph, , where , and are the numbers of vertices, edges and faces. If the planar graph has components, the formula becomes .
Each face of a simple graph with at least 3 vertices is bounded by at least 3 edges, and each edge borders at most 2 faces. So , and putting this into Euler's formula gives . If the graph has no triangle, each face has at least 4 edges, and the bound tightens to .
These bounds prove non-planarity at once. has and , but , so is not planar. has no triangle, and , but , so is not planar either. Kuratowski's theorem says a graph is planar exactly when it contains no subdivision of or .
Worked example. A connected planar graph has 10 vertices, each of degree 3. Then , and . Another consequence of is that every simple planar graph has a vertex of degree at most 5.
Why it matters. Planarity decides whether a circuit can be laid out on one layer of a printed board without wires crossing. GATE regularly asks for the number of faces or for the largest number of edges in a planar graph.
Bipartite graphs and matchings
A graph is bipartite if its vertices split into two sides and so that every edge joins to . Job applicants and jobs, students and projects, and machines and tasks are natural bipartite graphs. A graph is bipartite exactly when it has no cycle of odd length, which gives a quick test: try to 2-colour it by breadth-first search.
A matching is a set of edges no two of which share a vertex. A maximum matching has as many edges as possible, and a perfect matching covers every vertex, which needs an even number of vertices. In the job picture, a matching is a valid allocation of applicants to jobs, one each.
When can every applicant get a job? Hall's theorem answers this exactly. A bipartite graph with sides and has a matching that covers all of if and only if every subset of has at least neighbours, that is . If three applicants between them can do only two jobs, Hall's condition fails and no full allocation exists.
Counting perfect matchings is a common GATE question. has perfect matchings, since the first left vertex has partners, the next , and so on. The complete graph has perfect matchings, so has 3 and has 15.
Worked example. In a bipartite graph, König's theorem says that the size of a maximum matching equals the size of a minimum vertex cover. So if you find a matching of size 4 and a vertex cover of size 4, both are optimal. In any graph, every vertex cover must touch each matching edge at a different vertex, so a matching is never larger than a vertex cover.
Why it matters. Matching algorithms allocate seats, pair interns with mentors and schedule jobs on machines. The augmenting-path method grows a matching one edge at a time and is the basis of maximum-flow algorithms.
Colouring, independent sets and cliques
A proper vertex colouring gives each vertex a colour so that adjacent vertices get different colours. The chromatic number is the fewest colours needed. Exam timetabling is the classic use: subjects are vertices, an edge joins two subjects that share a student, and colours are time slots.
Some values are worth memorising. , for any bipartite graph with an edge, and is 2 when is even and 3 when is odd. A greedy colouring never uses more than colours, where is the maximum degree, so . The four colour theorem says that every planar graph has .
An independent set is a set of vertices with no edge between any two of them, and the independence number is the size of the largest one. A clique is a set of vertices that are all joined to each other, and the clique number is the size of the largest one. A vertex cover is a set of vertices that touches every edge, and is the size of the smallest one.
These numbers are tied together. The complement of an independent set is a vertex cover, so . A clique of size needs different colours, so . Each colour class is an independent set, so .
Worked example. Take the cycle . Its largest independent set has 2 vertices, so and . Its largest clique is an edge, so , but , which also follows from .
The chromatic polynomial counts proper colourings with at most colours. For a tree on vertices it is , since the root has choices and each later vertex avoids its parent's colour. For it is .
Why it matters. Colouring is behind register allocation in compilers, frequency assignment for mobile towers and exam scheduling. Finding , or exactly is hard in general, so exams test the bounds and the special families.
Descriptive lens: how written papers ask this
Written papers for scientist posts and university-level tests ask about graphs in four ways:
- Prove a basic result, such as the handshaking lemma or the fact that a tree on vertices has edges.
- Apply a criterion, such as Euler's degree test, Hall's condition or the planarity bounds, to a given graph.
- Derive a bound, such as for simple planar graphs, from Euler's formula.
- Model a real problem, such as timetabling or job allocation, as colouring or matching.
Practice questions (our own, not previous-year questions).
- Prove that every simple planar graph with has , and use it to show that is not planar. (12 marks)
- State Hall's theorem and use it to decide whether five applicants can each be given a different job from a given list. (10 marks)
- Model the scheduling of seven exams with given clashes as a colouring problem, and find the fewest slots needed. (8 marks)
Answer plan for question 1.
- State Euler's formula for a connected planar graph, and note that a disconnected graph only has more room.
- Argue that each face of a simple graph with is bounded by at least 3 edges.
- Note that each edge borders at most two faces, so counting edge–face incidences gives .
- Substitute into Euler's formula to get , which rearranges to .
- Apply it to , where but , and conclude that is not planar.
Quick revision
- The degree sum is , so odd-degree vertices come in an even number.
- has edges, has edges and has edges.
- More than edges force a simple graph to be connected.
- An edge is a bridge exactly when it lies on no cycle, and .
- An Euler circuit needs all degrees even, and an Euler path needs exactly two odd vertices.
- has Hamiltonian cycles, and Dirac's condition is every degree at least .
- A tree on vertices has edges, and has spanning trees.
- Euler's formula is , with and without triangles.
- Hall's condition is for every , and has perfect matchings.
- is 2 or 3 by parity, , and .