简体   繁体   English

无向图中的访问边,顶点

[英]Visiting edges, vertices in an undirected graph

Problem: You have an Undirected graph G = (V, E) (V = vertices, E = edges) and you must visit each vertex and pass each edge in both directions. 问题:您有一个无向图G = (V, E) (V =顶点,E =边),您必须访问每个顶点并在两个方向上传递每个边。

The only algorithms I know for graphs are DFS, BFS, and a few MST's (Kruskal, etc.) My friend and I were discussing this problem, if it were directed I would simply DFS, and then DFS the transpose but the graph is unfortunately undirected. 我所知道的关于图形的唯一算法是DFS,BFS和一些MST(例如Kruskal等)。我和我的朋友正在讨论这个问题,如果直接解决,我会简单地选择DFS,然后再转置DFS,但不幸的是,图形无向的。 My friend proposed we perform an MST and DFS the MST and then find the remaining edges by iterating through those that arent in MST. 我的朋友建议我们先执行MST,然后再执行DFS DST,然后通过迭代遍历MST的边找到剩余的边。 I sort of see what he means but I am not sure this is a good approach? 我有点明白他的意思,但是我不确定这是一个好方法吗? opinions? 意见? Also, how would I be able to pass by an edge in both directions if it is undirected? 另外,如果它是无向的,我怎么能在两个方向上都经过一条边?

It doesn't matter if the graph is directed or undirected. 图形是有向的还是无向的都没有关系。 You could just replace every undirected edge with two directed edges and perform whatever algorithm you have for a directed graph. 您可以只用两个有向边替换每个无向边,然后执行有向图的任何算法。 Both DFS and BFS will traverse the whole vertices and edges. DFS和BFS都将遍历整个顶点和边缘。

I think what you are looking for is called Graph Traversal . 我认为您正在寻找的是图遍历 BFS and DFS are two graph traversal algorithms and they do not require the graph to be directed. BFS和DFS是两种图形遍历算法,它们不需要对图形进行定向。 MST on the other hand, is not a graph traversal algorithm. 另一方面,MST不是图遍历算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM