HIERHOLZER'
S
ALGORITHM
Graph Theory
1
OVERVIEW
2
• Purpose
• Steps of Algo
• Code using Python
• Steps of Coding
• Why Hierholzer's
2
PURPOSE
1
2
3
Hierholzer's Algorithm is used to find an Eulerian Circuit in
a graph.
The output is a list of vertices representing the sequence of
nodes in the Eulerian Circuit.
Hierholzer’s Algorithm is faster, simpler, and purpose-built for
Eulerian Circuits, making it the best choice for this specific
problem.
3
3
STEPS OF HIERHOLZER'S ALGO:
3
4
1. Start at any vertex and follow edges until you return to
the starting vertex, forming a cycle.
2. If the cycle doesn't cover all edges, choose a vertex on the
cycle with unused edges and form a new cycle.
3. Merge the cycles into a single Eulerian circuit.
4. Repeat until all edges are used.
EXAMPLE:
3
5
CODE IN PYTHON 4
6
OUTPUT
5
7
STEPS OF CODING
6
The graph is
represented as a
dictionary where
each key is a node
and its value is a list
of connected
neighbors.
1.Input
Graph: The algorithm
works on a copy
of the graph to
ensure we don't
modify the
original graph.
2. Copy Graph:
8
7
• Use a current_path
stack to keep track
of the nodes being
traversed.
• Use a circuit list to
store the final
Eulerian Circuit.
3. Path
Tracking: • Pick a starting node
and traverse until
all edges are visited.
4. Algorithm
Steps:
• If a node has no
neighbors, backtrack
to a previous node
with unused edges.
9
8
• The Eulerian circuit
is returned as a list
of nodes.
5. Output:
10
9
WHY HIERHOLZER'S
1.Specialized: Optimized for Eulerian circuits, handling specific conditions
efficiently.
2. Efficient: visiting each edge exactly once.
3. Simple: Easy to implement with stacks/lists, avoiding recursion overhead.
4. Versatile: Works for both undirected and directed graphs.
5. Guaranteed Output: Always finds a circuit if Eulerian conditions are met.
Why Hierholzer's Algorithm is Better
THANK YOU
ANY QUESTION?
12

HIERHOLZER'S ALGORITHM GRAPH THEORY.pptx

  • 1.
  • 2.
    OVERVIEW 2 • Purpose • Stepsof Algo • Code using Python • Steps of Coding • Why Hierholzer's 2
  • 3.
    PURPOSE 1 2 3 Hierholzer's Algorithm isused to find an Eulerian Circuit in a graph. The output is a list of vertices representing the sequence of nodes in the Eulerian Circuit. Hierholzer’s Algorithm is faster, simpler, and purpose-built for Eulerian Circuits, making it the best choice for this specific problem. 3 3
  • 4.
    STEPS OF HIERHOLZER'SALGO: 3 4 1. Start at any vertex and follow edges until you return to the starting vertex, forming a cycle. 2. If the cycle doesn't cover all edges, choose a vertex on the cycle with unused edges and form a new cycle. 3. Merge the cycles into a single Eulerian circuit. 4. Repeat until all edges are used.
  • 5.
  • 6.
  • 7.
  • 8.
    STEPS OF CODING 6 Thegraph is represented as a dictionary where each key is a node and its value is a list of connected neighbors. 1.Input Graph: The algorithm works on a copy of the graph to ensure we don't modify the original graph. 2. Copy Graph: 8
  • 9.
    7 • Use acurrent_path stack to keep track of the nodes being traversed. • Use a circuit list to store the final Eulerian Circuit. 3. Path Tracking: • Pick a starting node and traverse until all edges are visited. 4. Algorithm Steps: • If a node has no neighbors, backtrack to a previous node with unused edges. 9
  • 10.
    8 • The Euleriancircuit is returned as a list of nodes. 5. Output: 10
  • 11.
    9 WHY HIERHOLZER'S 1.Specialized: Optimizedfor Eulerian circuits, handling specific conditions efficiently. 2. Efficient: visiting each edge exactly once. 3. Simple: Easy to implement with stacks/lists, avoiding recursion overhead. 4. Versatile: Works for both undirected and directed graphs. 5. Guaranteed Output: Always finds a circuit if Eulerian conditions are met. Why Hierholzer's Algorithm is Better
  • 12.