VOOZH about

URL: https://www.geeksforgeeks.org/dsa/conversion-of-an-undirected-graph-to-a-directed-euler-circuit/

⇱ Conversion of an Undirected Graph to a Directed Euler Circuit - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Conversion of an Undirected Graph to a Directed Euler Circuit

Last Updated : 12 Jul, 2025

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.

Example: 

Input: 
 

👁 Image


Output: 
1 2 
2 5 
5 1 
2 4 
4 3 
3 2 
Explanation: 
The Directed Euler Circuit for the given undirected graph will be: 
 

👁 Image


 

Approach: 
 

  1. 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.
  2. 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:


Output: 
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 ))
 

Comment
Article Tags:
Article Tags: