Skip to main content

Posts

Showing posts with the label The Crazy Programmer Hierholzer’s Algorithm with Implementation in Java Hierholzer’s Algorithm with Implementation in Java The Crazy Programmer

Hierholzer’s Algorithm with Implementation in Java Vijay Sinha The Crazy Programmer

In this article, will look at an interesting algorithm related to Graph Theory: Hierholzer’s Algorithm. We will discuss a problem and solve it using this Algorithm with examples. We will also discuss the approach and analyze the complexities for the solution. Hierholzer’s Algorithm has its use mainly in finding an Euler Path and Eulerian Circuit in a given Directed or Un-directed Graph. Euler Path (or Euler Trail) is a path of edges that visits all the edges in a graph exactly once. Hence, an Eulerian Circuit (or Cycle) is a Euler Path which starts and ends on the same vertex. Let us understand this with an example, Consider this Graph : In the above Directed Graph, assuming we start from the Node 0 , the Euler Path is : 0 -> 1 -> 4 -> 3 -> 1 -> 2 and the Eulerian Circuit is as follows : 0 -> 1 -> 4 -> 3 -> 1 -> 2 -> 3 -> 0 . We can see that the Eulerian Circuit starts and ends on the same vertex 0. Note: We see some nodes being repeated i