-
Notifications
You must be signed in to change notification settings - Fork 0
Graph
adjList Adjacency List represented by Hashmap containing Integer keys representing each node, ArrayList of integer values connected to the key
components ArrayList containing an ArrayList of nodes in each component of the graph
Both variables a private to maintain the security and integrity of the project.
The constructor generates the graph from the edge files and identifies each component of the graph.
generateGraph(String path) takes a string parameter that is the path to a file containing a list of edges. This method iterates through each row of the file and adds the node to adjList accordingly. A binary search is used to check if a node already exists as a key or value, and deals with it accordingly.
addConnection(int u, int v) is a private helper method used by generateGraph that takes two nodes represented by integer parameters. This adds the nodes accordingly to adjList and keeps the values sorted at all times to allow a binary search to be performed.
contains(ArrayList<Integer> list, int item) runs a binary search on a given list for a given item.
identifyComponents() runs a Breadth First Search on a graph to identify multiple components and stores each list of nodes in components.
getConnectedNodes(int u) returns all connected nodes to the specified node u. This is the value to the key u in adjList.