Eulerian path

In graph theory, an Eulerian trail (or Eulerian path) is a trail in a finite graph that visits every edge exactly once (allowing for revisiting vertices). Similarly, an Eulerian circuit or Eulerian cycle is an Eulerian trail that starts and ends on the same vertex. They were first discussed by Leonhard Euler while solving the famous Seven Bridges of Königsberg problem in 1736. The problem can be stated mathematically like this:

Given the graph in the image, is it possible to construct a path (or a cycle; i.e., a path starting and ending on the same vertex) that visits each edge exactly once?
Euler proved that a necessary condition for the existence of Eulerian circuits is that all vertices in the graph have an even degree, and stated without proof that connected graphs with all vertices of even degree have an Eulerian circuit. The first complete proof of this latter claim was published posthumously in 1873 by Carl Hierholzer.[1] This is known as Euler’s Theorem:

A connected graph has an Euler cycle if and only if every vertex has even degree.
The term Eulerian graph has two common meanings in graph theory. One meaning is a graph with an Eulerian circuit, and the other is a graph with every vertex of even degree. These definitions coincide for connected graphs.[2]

For the existence of Eulerian trails it is necessary that zero or two vertices have an odd degree; this means the Königsberg graph is not Eulerian. If there are no vertices of odd degree, all Eulerian trails are circuits. If there are exactly two vertices of odd degree, all Eulerian trails start at one of them and end at the other. A graph that has an Eulerian trail but not an Eulerian circuit is called semi-Eulerian.

在这里插入图片描述

Multigraphs of both Königsberg Bridges and Five room puzzles have more than two odd vertices (in orange), thus are not Eulerian and hence the puzzles have no solutions.

在这里插入图片描述

Every vertex of this graph has an even degree. Therefore, this is an Eulerian graph. Following the edges in alphabetical order gives an Eulerian circuit/cycle.

Contents
1 Definition
2 Properties
3 Constructing Eulerian trails and circuits
3.1 Fleury’s algorithm
3.2 Hierholzer’s algorithm
4 Counting Eulerian circuits
4.1 Complexity issues
4.2 Special cases
5 Applications
6 In infinite graphs
7 Undirected Eulerian graphs
8 Directed Eulerian graphs
9 Mixed Eulerian graphs
10 See also

很抱歉,作为一个文本AI助手,我无法提供视频资源。但是我可以为您提供欧拉回路算法的编程示例。以下是一个使用Python实现的欧拉回路算法的示例代码: ```python from collections import defaultdict class Graph: def __init__(self): self.graph = defaultdict(list) def add_edge(self, u, v): self.graph[u].append(v) self.graph[v].append(u) def dfs(self, v, visited): visited[v] = True for i in self.graph[v]: if visited[i] == False: self.dfs(i, visited) def is_connected(self): visited = [False] * (max(self.graph) + 1) for i in self.graph: if len(self.graph[i]) > 0: self.dfs(i, visited) break for i in self.graph: if visited[i] == False and len(self.graph[i]) > 0: return False return True def is_eulerian(self): if self.is_connected() == False: return False odd_degree_count = 0 for i in self.graph: if len(self.graph[i]) % 2 != 0: odd_degree_count += 1 if odd_degree_count == 0: return True elif odd_degree_count == 2: return True else: return False def eulerian_path(self): if self.is_eulerian() == False: return "No Eulerian path exists." else: return "Eulerian path exists." # 创建一个图对象 g = Graph() # 添加边 g.add_edge(1, 2) g.add_edge(1, 3) g.add_edge(2, 3) g.add_edge(2, 4) g.add_edge(3, 4) # 判断是否存在欧拉回路 print(g.eulerian_path()) ``` 这段代码使用了邻接表来表示图的存储结构,并使用深度优先搜索算法来判断图是否连通。然后,根据图的度数来判断是否存在欧拉回路。最后,根据判断结果输出相应的信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值