Skip to content

Instantly share code, notes, and snippets.

@jeewamp
Created December 1, 2012 06:03
Show Gist options
  • Select an option

  • Save jeewamp/4180750 to your computer and use it in GitHub Desktop.

Select an option

Save jeewamp/4180750 to your computer and use it in GitHub Desktop.
Check the graph is Eulerian, Semi-Eulerian or Non-Eulerian.
/**
* @param adjacencyList of the graph
* @return ArrayList of oddVertices. if oddVertices is empty its Eulerian,
* if it has 2 elements its Semi-Eulerian, else its not Eulerian.
*/
public <P extends Integer, Q extends ArrayList<P>> ArrayList<P> checkEulerian(HashMap<P, Q> adjacencyList) {
ArrayList<P> oddVertices = new ArrayList<P>();
Iterator iterator = adjacencyList.keySet().iterator();
while(iterator.hasNext()) {
P key = (P) iterator.next();
int checkEven=adjacencyList.get(key).size()%2;
if(checkEven!=0) {
oddVertices.add(key);
}
}
return oddVertices;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment