Looking for algorithm finding euler path

后端 未结 5 758
终归单人心
终归单人心 2021-02-05 13:45

I\'m looking for an algorithm to find an Euler path in a graph.

I\'ve seen a good one a couple of weeks ago but I can\'t find it now, I remember there was tagging edges

5条回答
  •  时光取名叫无心
    2021-02-05 14:32

    An euler path exists if a graph has exactly two vertices with odd degree.These are in fact the end points of the euler path.

    So you can find a vertex with odd degree and start traversing the graph with DFS:As you move along have an visited array for edges.Don't traverse an edge twice.

    If you there is no edge left from a vertex, check if all edges have been visited, if so you are done.

    To store the actual euler path, you could keep a predecessor array, which stores previous vertex in the path.

提交回复
热议问题