[Math] How to identify bipartite graph from Adjacency matrix

graph theory

I have attached a picture of a bipartite graph with two different ways of naming vertices. The Adjacency matrix for the two is also attached. As can be seen…Except for zero in diagonals (since no loops)… the Adjacency matrix for the two looks different.

My question is …Is there some property of adjacency matrix from which one can figure out if a graph is bipartite IRRESPECTIVE of how vertices are numbered?enter image description here

Best Answer

You can use a quick algorithm to check whether it's bilateral.

You're given an adjacency matrix of order $2n$ (i.e. a representation of a graph with $2n$ vertices.)

  1. Find the column with the most ones in it; suppose it's column $k$. Let $N_k$ be the list of ones in column $k$ (these are the neighbors of vertex $k$). Initialize a partition $P \equiv N_k$, and a partition $Q=\{k\}$.

  2. [Loop.] Iterate over each column $j$ in the matrix:

    If $P$ has more than $n$ ones in it, the graph can't be bipartite. In that case, quit and return NOT BIPARTITE.

    Compute $N_j$. Now either:

    • $P$ and $N_j$ have no ones in common: $P$ is zero whenever $N_j$ is one, and vice versa. In this case, keep going to the next column.
    • $P$ and $N_j$ have some ones in common. Update $P = P \cup N_j$, and $Q = Q \cup \{j\}$, and go to the next column.
  3. Once again, if $P$ has more than $n$ members, the graph can't be bipartite—quit and return NOT BIPARTITE.

  4. If the graph really is bipartite, $P$ now contains a complete partition of the graph. Permute the adjacency matrix to put all the members of $P$ first, and all of the members of $Q$ last.

  5. If the matrix is now in the canonical form of a bipartite adjacency matrix (where the upper-left and lower-right blocks are all zero), the graph is bipartite; quit and return BIPARTITE. Otherwise, the graph isn't bipartite — quit and return NOT BIPARTITE.


Here's how to use this algorithm. Take your second graph as an example, which has $2n$ vertices with $n=3$.

  • Column 1 has three ones in it. Since this is the maximal number of ones in any column, we can use it as a starting point. Then $N_1 = \{2,4,6\}$, so we initialize $P=\{2,4,6\}$ and $Q=\{1\}$.
  • We begin looping over the columns of the matrix.
  • Column 1 overlaps with $P$, so $P \leftarrow P\cup N_1 = \{2,4,6\}$, and also $Q \leftarrow Q \cup \{1\} = \{1\}$.
  • Column 2 doesn't overlap at all.
  • Column 3 overlaps; $Q \leftarrow Q \cup \{3\} = \{1,3\}$.
  • Column 4 doesn't.
  • Column 5 does. $Q \leftarrow Q \cup \{5\} = \{1,3,5\}$.
  • Column 6 doesn't.
  • If this graph is bipartite (and it is), $P$ should now contain a partition of the graph. In fact, we know $P=\{2,4,6\}$ and $Q=\{1,3,5\}.$ If we permute the adjacency list to put members of $P$ first and members of $Q$ last, we find that it appears in canonical form.