Eularian Path

来源:互联网 发布:金兰软件怎么样 编辑:程序博客网 时间:2024/05/22 00:21

For Eulerian graph, every edge is visited exactly once.

Eulerian graph, the number of odd degree edge is either 0 or 2.

Eulerian circuit, all vertex's degree are even.  

Algorithm for finding a Eulerian circuit.

Start with an empty stack and an empty circuit (eulerian path).

If all vertices have even degree: choose any of them. This will be the current vertex.

If there are exactly 2 vertices having an odd degree: choose one of them. This will be the current vertex.

Otherwise no Euler circuit or path exists.

Repeat step 2 until the current vertex has no more neighbors and the stack is empty.


If current vertex has no neighbors:

Add it to circuit,

Remove the last vertex from the stack and set it as the current one.

Otherwise:


Add the vertex to the stack,

Take any of its neighbors, remove the edge between selected neighbor and that vertex, and set that neighbor as the current vertex.

ref: http://stackoverflow.com/questions/17467228/looking-for-algorithm-finding-euler-path

Hamiltonian graph.

Every vertex is visited exactly once.  

0 0
原创粉丝点击