Class AdjacencyListGraph
java.lang.Object
jdg.graph.AdjacencyListGraph
Pointer based implementation of an Adjacency List Representation of a graph.
The graph is assumed to be undirected (with no multiple edges and loops).
- Author:
- Luca Castelli Aleardi (Ecole Polytechnique, INF562)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an edge between two nodesvoidAdd a new node to the graph.booleanCheck whether two nodes are adjacent (slow implementation, without hash maps)intReturn the degree of a nodeCompute and return the connected component containing the vertex v It performs a DFS visit of the graph starting from vertex vintgetEdgeIndex(Node a, Node b) Return the index of the edge having extremities (a, b) if any.int[]Return an array storing all vertex indices, according to the order of verticesgetNeighbors(Node v) getNode(int index) Return the node given its index (between [0..n-1])info()Return a string containing informations and parameters of the graphbooleanCheck whether the graph is connected Remark: the graph is assumed to be undirectedintCompute the maximum vertex index of the graph (a non negative number) Remark: vertices are allowed to have indices between 0..infty This is required when graphs are dynamic: vertices can be removedintCompute the minimum vertex index of the graph (a non negative number) Remark: vertices are allowed to have indices between 0..infty This is required when graphs are dynamic: vertices can be removedvoidremoveEdge(Node a, Node b) Remove the edge between two nodesvoidremoveNode(Node v) intReturn the number of arcs Remark: arcs are not counted twiceintReturn the number of nodes
-
Field Details
-
neighbors
-
edges
-
-
Constructor Details
-
AdjacencyListGraph
public AdjacencyListGraph()Initialize an empty graph
-
-
Method Details
-
addNode
Add a new node to the graph.
Remark:
-) if the label of 'v' is not defined, add the node (without any check)
-) otherwise, before adding the node the function check whether it already exists (expensive test). -
getEdgeIndex
-
getNode
Return the node given its index (between [0..n-1]) -
removeNode
-
addEdge
-
removeEdge
-
adjacent
-
degree
Return the degree of a node- Returns:
- the degree (number of neighbors) of the input node. If the node is not defined (null) return 0.
-
getNeighbors
-
sizeVertices
public int sizeVertices()Return the number of nodes -
sizeEdges
public int sizeEdges()Return the number of arcs Remark: arcs are not counted twice -
getIndices
public int[] getIndices()Return an array storing all vertex indices, according to the order of vertices -
findConnectedComponent
Compute and return the connected component containing the vertex v It performs a DFS visit of the graph starting from vertex vRemark: the graph is assumed to be undirected
- Parameters:
v- the starting node- Returns:
- the list of nodes lying in the same connected component of v
-
isConnected
public boolean isConnected()Check whether the graph is connected Remark: the graph is assumed to be undirected -
minVertexIndex
public int minVertexIndex()Compute the minimum vertex index of the graph (a non negative number) Remark: vertices are allowed to have indices between 0..infty This is required when graphs are dynamic: vertices can be removed -
maxVertexIndex
public int maxVertexIndex()Compute the maximum vertex index of the graph (a non negative number) Remark: vertices are allowed to have indices between 0..infty This is required when graphs are dynamic: vertices can be removed -
info
Return a string containing informations and parameters of the graph
-