Euler Circuit in an Undirected Graph | Practice | GeeksforGeeks

Eulerian Path is a path in a graph that visits every edge exactly once. Eulerian Circuit is an Eulerian Path that starts and ends on the same vertex. Given the number of vertices V and adjacency list adj denoting the graph. Your task is to find that there exists the Euler circuit or not
Note that: Given graph is connected.

Example 1:
Input: 

Output: 1
Explanation: One of the Eularian circuit 
starting from vertex 0 is as follows:
0->1->3->2->0

 
Your Task:
You don't need to read or print anything. Your task is to complete the function isEularCircuitExist() which takes V and adjacency list adj as input parameter and returns boolean value 1 if Eular circuit exists otherwise returns 0.
 
Expected Time Complexity: O(V + E)
Expected Space Complexity: O(V)
 
Constraints:
1 <= V <= 105
1 <= E <= 2*105
0
shyamprakash8071 week ago
Time Taken : 0.23 / 5.18
 
class Solution:def isEularCircuitExist(self, V, adj): #Code here odd = 0 for i in range(V):     if len(adj[i])%2==1:         odd += 1    if odd == 0:        return 1    return 0
0
puranjanprithu2 months ago
def isEularCircuitExist(self, V, adj): #Code here inedge=[0 for _ in range(V)]  for i in range(V):     for s in adj[i]:         inedge[s]+=1          odd=0 for i in range(V):     if inedge[i]%2==1:         odd+=1 if odd>0:     return 0 return 1
0
lindan1233 months ago
bool isEularCircuitExist(int V, vector<int>adj[]){
	    
	    for(int i=0;i<V;i++)
	    {
	        if(adj[i].size()%2!=0)
	        {
	            return false;
	        }
	    }
	    return true;
	}
Very Easy Solution : 
Cpp
Time Taken : 0.1sec
0
razhagarrix3 months ago
Where is the practice page for Euler Circuit in a directed graph ?
0
anutiger6 months ago
	bool isEularCircuitExist(int V, vector<int>adj[]){
	    for(int i = 0 ; i < V ; i ++){
	       if(adj[i].size() % 2 != 0) return false;
	    }
	    return true;
	}
+1
Saksham Jain8 months ago
Saksham Jain
There should be a test case which contains two components in a graph.Sir, please update the test cases.
0
Saksham Jain
This comment was deleted.
+1
Manhar Joshi9 months ago
Manhar Joshi
Logic:- All nodes must have even degree for graph to be Euler circuit
 https://uploads.disquscdn.c...
I might add, the above code should fail if the graph has disconnected components containing more edges(Although it doesn't fail here. So we might be assuming a connected graph).
0
Manhar Joshi
This comment was deleted.
0
Sandip Dutta9 months ago
Sandip Dutta
Code is successful even if we do not check Connected Components
bool isEularCircuitExist(int V, vector<int>adj[]){(int i = 0; i < V; ++i)  (adj[i].size() % 2) return false;return true;}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.