Detecting cycles in an adjacency matrix

前端 未结 7 999
走了就别回头了
走了就别回头了 2020-12-14 19:46

Let A be the adjacency matrix for the graph G = (V,E). A(i,j) = 1 if the nodes i and j are connected with an

7条回答
  •  独厮守ぢ
    2020-12-14 20:08

    That is the problem I also found. The explanation, I thought, is the following:
    when we talk about cycle, implicitly we mean directed cycles. The adjacency matrix that you have has a different meaning when you consider the directed graph; it is indeed a directed cycle of length 2. So, the solution of $A^n$ is actually for directed graphs. For undirected graphs, I guess a fix would be to just consider the upper triangular version of the matrix (the rest filled with zero) and repeat the procedure. Let me know if this is the right answer.

提交回复
热议问题