简体   繁体   中英

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.

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. 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. 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.

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. MST on the other hand, is not a graph traversal algorithm.

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.

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