[英]Best time complexity for finding an Eulerian Path in an undirected graph
I managed to create an algorithm that finds an eulerian path(if there is one) in an undirected connected graph with time complexity O(k^2 * n) where: 我设法创建了一种算法,该算法在时间复杂度为O(k ^ 2 * n)的无向连接图中找到欧拉路径(如果有)。
k: number of edges k:边数
n: number of nodes n:节点数
I would like to know if there is a better algorithm, and if yes the idea behind it. 我想知道是否有更好的算法,如果可以,它背后的想法是什么。
Thanks in advance! 提前致谢! :)
:)
Hierholzer's algorithm runs in O(k) time: https://en.wikipedia.org/wiki/Eulerian_path#Hierholzer.27s_algorithm Hierholzer的算法在O(k)时间运行: https ://en.wikipedia.org/wiki/Eulerian_path#Hierholzer.27s_algorithm
First you find a path between the two vertices with odd degree. 首先,您找到两个具有奇数度的顶点之间的路径。 Then as long as you have a vertex on the path with unused edges, follow unused edges from that vertex until you get back to that vertex again, and then merge in the new path.
然后,只要路径上具有未使用边的顶点,就可以跟随该顶点的未使用边,直到再次回到该顶点,然后合并到新路径中。
If there are no vertices with odd degree then you can just start with an empty path at any vertex. 如果没有奇数度的顶点,则可以从任何顶点处的空路径开始。
If the number of vertices with odd degree is not 0 or 2, then there is no Eulerian path. 如果具有奇数度的顶点数不为0或2,则不存在欧拉路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.