zoukankan      html  css  js  c++  java
  • Graph | Eulerian path

    In graph theory, a Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge exactly once. Similarly, an Eulerian circuit or Eulerian cycle is an Eulerian trail which starts and ends on the same vertex. 

    Hierholzer's algorithm 可以在O(E)的时间下给出解。

    算法:

    • Choose any starting vertex v, and follow a trail of edges from that vertex until returning to v. It is not possible to get stuck at any vertex other than v, because the even degree of all vertices ensures that, when the trail enters another vertex w there must be an unused edge leaving w. The tour formed in this way is a closed tour, but may not cover all the vertices and edges of the initial graph.
    • As long as there exists a vertex u that belongs to the current tour but that has adjacent edges not part of the tour, start another trail from u, following unused edges until returning to u, and join the tour formed in this way to the previous tour.

    当然,需要用到双向链表不断地把边删掉,如果最终所有边都被访问了,那么就可以退出了。但是如果找不到点继续扩展,而且边又还有的话,那么就说明给不出回路。

  • 相关阅读:
    k3d安装k3s
    python自动目录环境
    http状态码
    linux下切换jdk版本
    pycharm py代码默认模板设置
    kubectl命令
    国内安装k3s
    minikube安装
    hmac-md5
    abstract class 与 interface
  • 原文地址:https://www.cnblogs.com/linyx/p/4082227.html
Copyright © 2011-2022 走看看