Given an undirected graph with V nodes (say numbered from 1 to V) and E edges, the task is to check whether the graph is an Euler Graph or not and if so then convert it into a Directed Euler Circuit.
A Directed Euler Circuit is a directed graph such that if you start traversing the graph from any node and travel through each edge exactly once you will end up on the starting node.
Note: While traversing a Euler circuit every edge is traversed exactly once. A node can be traversed more than once if needed but an edge cannot be traversed more than once.
First, we need to make sure the given Undirected Graph is Eulerian or not. If the undirected graph is not Eulerian we cannot convert it to a Directed Eulerian Graph.
- To check it we just need to calculate the degree of every node. If the degree of all nodes is even and not equal to 0 then the graph is Eulerian.
We will be using Depth First Search Traversal to assign the directions.
- While traversing we will set the direction of an edge from parent to child. We will maintain a map to make sure an edge is traversed only once.
Below is the implementation of the above algorithm:
1 2 2 5 5 1 2 4 4 3 3 2
Time Complexity: O(( V + E ) * log( E ))
Space Complexity: O(max( V, E ))
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Euler Circuit in a Directed Graph
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Eulerian path and circuit for undirected graph
- Program to find Circuit Rank of an Undirected Graph
- Convert undirected connected graph to strongly connected directed graph
- Minimum edges required to add to make Euler Circuit
- Number of Triangles in Directed and Undirected Graphs
- Hierholzer's Algorithm for directed graph
- Detect Cycle in a Directed Graph using BFS
- Check if a directed graph is connected or not
- Convert Directed Graph into a Tree
- Detect Cycle in a Directed Graph
- Clone a Directed Acyclic Graph
- Clone an Undirected Graph
- Longest Path in a Directed Acyclic Graph | Set 2
- Shortest Path in Directed Acyclic Graph
- Find if there is a path between two vertices in a directed graph
- Find dependencies of each Vertex in a Directed Graph
- Longest Path in a Directed Acyclic Graph
- Path with minimum XOR sum of edges in a directed graph
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.