求欧拉回路的算法

zhangdongloveyou 2005-05-14 04:32:41
求欧拉回路的算法
...全文
225 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
husl 2005-05-14
  • 打赏
  • 举报
回复
我 有兴趣 却没能力
55555555555555555
zhang_jiang 2005-05-14
  • 打赏
  • 举报
回复
http://vip.6to23.com/yunyan8/shu/file/oulahuilu.htm
mmmcd 2005-05-14
  • 打赏
  • 举报
回复
来自UASCO:

More formally,to determine a Eulerian circuit of a graph which has one, pick a starting node and recurse on it. At each recursive step:

Pick a starting node and recurse on that node. At each step:
If the node has no neighbors, then append the node to the circuit and return
If the node has a neighbor, then make a list of the neighbors and process them (which includes deleting them from the list of nodes on which to work) until the node has no more neighbors
To process a node, delete the edge between the current node and its neighbor, recurse on the neighbor, and postpend the current node to the circuit.

And here's the pseudocode:
# circuit is a global array
find_euler_circuit
circuitpos = 0
find_circuit(node 1)

# nextnode and visited is a local array
# the path will be found in reverse order
find_circuit(node i)

if node i has no neighbors then
circuit(circuitpos) = node i
circuitpos = circuitpos + 1
else
while (node i has neighbors)
pick a random neighbor node j of node i
delete_edges (node j, node i)
find_circuit (node j)
circuit(circuitpos) = node i
circuitpos = circuitpos + 1

To find an Eulerian tour, simply find one of the nodes which has odd degree and call find_circuit with it.

33,028

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧