Bipartite Graph

Context: FIT1058_MOC · vertices split into two sides with edges only across · equivalent to 2-colourability and to having no odd cycle · FIT2004_MOC · the W5 applied decision problem — testing it is one DFS in , and counting the colourings is Parent Framework: Graph

Quick Revision

  • 🎯 Objective: , every edge crosses ➔ a two-sided graph ➔ decided by a greedy traversal, because the first colour in a component forces every other one.
  • 📦 Core Components: three equivalent views — parts / 2-colouring / no odd cycle | test ➔ DFS | count ➔ for components.
  • ⚡ Key Constraint: a single odd cycle disproves it, and the triangle is the smallest non-bipartite graph — to prove bipartite exhibit the colouring, to disprove exhibit one odd cycle.

📝 How It Works

1. The Definition

  • Bipartite ➔ with every edge having one end in and one in .
  • Partition ➔ if has an edge, both parts are nonempty (Set Partition).

2. Three Equivalent Views

  • Parts ➔ .
  • 2-colouring ➔ adjacent vertices differ; the parts are the colour preimages.
  • No odd cycle ➔ equivalently, no odd closed walk.

3. Bipartite Two-Colourable — the Two-Way Argument (applied P8)

  • Bipartite 2-colourable ➔ colour every vertex of white and every vertex of black; every edge runs between the parts, so no edge joins two vertices of one colour.
  • 2-colourable bipartite ➔ take the white vertices and the black ones; no edge joins two whites or two blacks, so every edge crosses ⟹ the colouring is the partition.
  • Consequence for the exam ➔ “determine whether is bipartite” and “determine whether is two-colourable” are the same question, so the same algorithm answers both — say this explicitly rather than inventing a second algorithm.

4. Why No Odd Cycle

  • Walks alternate ➔ ⟹ a closed walk must have even length.
  • Distance-parity colouring ➔ colour each vertex by the parity of its distance from a ground vertex in its component.

5. Testing It — the Greedy DFS Colouring (applied P1)

  • The forcing observation ➔ once one vertex is coloured, all of its neighbours’ colours are determined, and theirs in turn ⟹ after the first choice there are no further decisions to make; the algorithm is therefore purely greedy, never a search.
  • The first choice is free ➔ starting a component white instead of black just swaps every colour in it, so it never changes whether a valid colouring exists — which is what licenses picking arbitrarily.
  • The algorithm ➔ DFS over all vertices; for each still-uncoloured pick a colour and recursively colour every neighbour the opposite. If a neighbour already carries the same colour as the vertex being expanded, no valid colouring exists ⟹ return False.
  • What the failure means ➔ the clash is a closed walk of odd length, i.e. the odd cycle obstruction, surfaced constructively.
  • The outer loop is mandatory ➔ a disconnected graph has several components, each needing its own seed colour; a single seeded DFS reports on one component only.
  • BFS works equally well ➔ colour by the parity of distance, matching the distance-parity argument in §4; the FIT2004 sheet writes it as DFS.

6. Counting the Valid Two-Colourings (applied P2)

  • Step 1 ➔ run §5. If the graph is not two-colourable the count is — no partial credit for components that would have worked.
  • Step 2 ➔ within a component, fixing one vertex fixes every other, so each component admits exactly two colourings: the one you found and its complete swap.
  • Step 3 ➔ components are coloured independently, so the choices multiply:
  • Getting ➔ the same DFS — count how many times the outer loop has to start a fresh traversal ➔ Connectivity.
  • Isolated vertices count ➔ a degree- vertex is its own component and doubles the answer; forgetting them is the standard arithmetic slip.
  • Total cost ➔ still : one traversal decides colourability and counts components in the same pass.

7. Maximum Matching Is a Flow Problem (FIT2004 W11 lecture)

  • The step up from testing ➔ the parts , become the middle layer of a flow network, , every edge capacity ➔ max flow maximum matching, matched pairs saturated middle edges.
  • Construction, quotas and proof ➔ Network Flow Reductions §3.

⚙️ Core Implementation

🔹 TWO_COLOUR — decide and colour in one DFS

🔹 Counting the colourings

⚖️ Complexity

TaskTraversalTimeAuxiliary spaceOutput
Is bipartite / two-colourable?one DFS or BFS colour array stackboolean a witness colouring
Exhibit the parts the same runthe two colour classes
Count the two-colouringsthe same run, or
Disprove bipartiteness by hand———one odd cycle suffices
  • Adjacency-list bound ➔ on an adjacency matrix the neighbour scan makes it .
  • Nothing is paid for the colouring ➔ the colour array is work per vertex on a traversal already costing ➔ Uninformed Search (BFS and DFS).

📊 Exam Execution Trace & Applied Exercises

Manual Execution Trace

2-colour by distance parity from vertex :

Step / StateVertexDistance parityColour
0 (Init)1 (ground)evenBlack
12oddWhite
23evenBlack
34oddWhite

Applied Exercise

Problem: has vertices in three components — a -cycle, a -vertex path, and two isolated vertices. How many valid two-colourings?

Final Extracted Output: . Replace the -cycle with a -cycle and the answer collapses to — one odd cycle anywhere in the graph kills every colouring, not just its own component’s.

⚠️ Common Mistakes

  • 💡 One odd cycle disproves it ➔ to prove bipartite exhibit the parts / 2-colouring; to disprove, exhibit an odd cycle (e.g. a triangle).
  • 💡 Treating an already-coloured neighbour as a failure ➔ the test is same colour as me, not coloured at all; the looser test rejects every graph with a cycle, even an even one.
  • 💡 Seeding the colouring at one vertex ➔ a disconnected graph needs a fresh arbitrary colour per component, and the component count is also what the counting question needs.
  • 💡 Forgetting isolated vertices in ➔ a degree- vertex is a component and doubles the count.

🧠 Active Recall