Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I topologically sort a DAG, can I drop half the adjacency matrix?

Tags:

graph-theory

I think I have understood a particular situation as described below, but I lack the theoretical knowledge to conduct a proof and I couldn't find any source that mentions it. If my understanding is correct, I can save half the space on my adjacency matrix, if it isn't I'm likely to have pretty weird bugs. So I'd like to be sure, and I'd appreciate if someone with a more solid background could review my reasoning.

Say I represent a DAG of n vertices in an n * n adjacency matrix such that the entry i,j is 1 if there is an edge from vertex i to vertex j, 0 otherwise. Because the graph is directed and acyclic, it follows that, if i,j = 1, then j,i = 0. If I now sort the nodes in the matrix such that the topological level of the node at in is equal to or greater than the node at in-1, then it seems to me that half of the adjacency matrix will always only contain 0s, as it is the case in the following example:

      V 1           V 2     from V    1 2 3 4 5 6 7 8
      / \           / \ 
     /   \         /   \      to V 1  0 0 0 0 0 0 0 0
    /     \       /     \          2  0 0 0 0 0 0 0 0
 e1/     e2\   e3/     e4\         3  1 0 0 0 0 0 0 0
  /         \   /         \        4  1 1 0 0 0 0 0 0
V 3          V 4          V 5      5  0 1 0 0 0 0 0 0
             /|\          /        6  0 0 0 1 0 0 0 0
            / | \        /         7  0 0 0 1 0 0 0 0
           /  |  \      /          8  0 0 0 1 1 0 0 0
        e5/ e6| e7\  e8/
         /    |    \  /
       V 6   V 7   V 8

Maybe I'm just right, but is there a formal way to check this?

like image 979
Hanno Fietz Avatar asked Apr 22 '09 14:04

Hanno Fietz


1 Answers

Let adj[i][j] be the adjacency entry from node i to node j and you've sorted it such that for all nodes i < j, node i is higher up the topological hierarchy than node j.

Let's assume for a moment that your assumption was incorrect: that we have a counter-example for which adj[i][j] == 1 for i > j (i.e., a one in the upper-right half of your matrix representation). This implies that there must be a cycle containing i and j, since our sorting guarantees that node j is higher up than node i yet we have adj[i][j] == 1 implies we can "climb" up the hierarchy. This is a contradiction, since we know we have a DAG. Therefore we have proven that your assumption is correct.

like image 161
moinudin Avatar answered Oct 31 '22 09:10

moinudin