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

前端 未结 2 1442
醉梦人生
醉梦人生 2021-02-14 20:29

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

2条回答
  •  既然无缘
    2021-02-14 21:21

    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.

提交回复
热议问题