简体   繁体   English

在无向图中找到欧拉路径的最佳时间复杂度

[英]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.

相关问题 在无向图中寻找循环的O复杂度很高 - Big O complexity of finding cycles in an Undirected graph 使无向图中的所有节点组合对的最佳算法(需要提高时间复杂度) - Best algorthm to get all combination pair of nodes in an undirected graph (need to improve time complexity) 在有向图中找到循环的最佳算法(时间复杂度)是哪一种? - Which is the best (in time complexity) algorithm for finding a cycle in directed graph? 无向图复杂度上的 DFS? - DFS on undirected graph complexity? 在加权无向图中找到一条具有多项式时间最大代价的简单路径吗? 是NP吗? - Is finding a simple path in a weighted undirected graph with maximum cost in polynomial time? Is it NP? 在无向图中查找长度为 n 的循环数的算法的时间复杂度 - Time Complexity of algorithm to find the number of cycles of length n in an undirected graph 在无向图中查找路径 - Finding paths in a Undirected Graph 是否有一种算法可以在无向图中找到成本最高的长度为 k 的路径 - Is there an algorithm for finding the path of length k with the highest cost in a undirected graph 在完整的无向加权图中找到哈密顿路径 vs 哈密顿回路 - Finding Hamiltonian path vs Hamiltonian circuit in a complete undirected weighted graph 查找树中两个顶点之间的简单路径(无向简单图) - Finding simple path between two vertices in a tree (undirected simple graph)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM