This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param adjacencyList, oddVertices, EulerianPath. | |
*/ | |
public <P extends Integer, Q extends ArrayList<P>> ArrayList<P> | |
hierholzersAlgorithm(HashMap<P, Q> adjacencyList, ArrayList<P> oddVertices, ArrayList<P> path) { | |
P currentVertex=null; | |
//If path is not empty, the start vertex should be in the path. | |
//Check if Semi-Eulerian. If yes, start traversing from one of them. | |
if(oddVertices.size()==2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BreadthFirstSearch<K> { | |
final Integer WHITE=0; //Not yet discovered | |
final Integer GRAY=1; //Discovered by not all adjacent vertices are discovered. | |
final Integer BLACK=2; //Discovered and all adjacent vertices are discovered. | |
HashMap<K,Integer> colour = new HashMap<K, Integer>(); | |
HashMap<K,Integer> distance = new HashMap<K, Integer>(); | |
HashMap<K, K> predecessor = new HashMap<K, K>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a Non-Eulerian to Semi-Eulerian. If graph is Eulerian or Semi-Eulerian, the graph will be | |
* immediately returned. | |
* @param adjacencyList, ArrayList of odd Vertices | |
* @return | |
*/ | |
public <P extends Integer, Q extends ArrayList<P>> HashMap<P, Q> | |
convertToEulerian(HashMap<P, Q> adjacencyList, ArrayList<P> oddVertices){ | |
if(oddVertices.size()<=2) | |
return adjacencyList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HashMap<Integer,ArrayList<Integer>> adjacencyList = new HashMap<Integer,ArrayList<Integer>>; |