I am traveling through math&algorithms since two days, but I don't have more ideas. I have adjacency matrix and I have laplasjan matrix. I want to check is this graph consistent OR does it have spanning tree.
I was working with Kirchoff's Theorem and it works for me but it is too slow (more than second with 10x10 matrix). Can I modify Kirchoff's Theorem to check has my matrix spanning tree (NOT how many)?
I am trying to learn something new, so I don't want to use DFS and I really want to use adjacency matrix.
Here is an algorithm to find out whether a graph has at least one spanning tree.
find_root
, which follows a chain of 'par' pointers until it reaches a node for which par[node] == node
for i in nodes: for j in nodes: if i!=j: if adjacent[i][j] then
:
k = find_root(i)
par[k] = l
// this puts the tree of i as a sibling to j in j's tree This way, one or more trees are constructed. These trees can be used to cluster the nodes into connected groups.
To the basic algorithm, an important speed-up is to not only set par[k] = l
but also par[i] = l
and par[j] = l
. The root will be found earlier the next time. If the graph is not directional, only one of adjacent[i][j]
or adjacent[j][i]
needs to be handled.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.