Interface Graph<V>

All Known Subinterfaces:
DirectedGraph<V>
All Known Implementing Classes:
DenseGraph, DirectedDenseGraph, DirectedSparseGraph, SparseGraph

public interface Graph<V>
Interface for graphs.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addEdge(V v1, V v2)
    Add an edge between two vertices.
    boolean
    addVertex(V vertex)
    Add a vertex to the graph.
    boolean
    containsVertex(V vertex)
    Check the existence of a vertex in the graph.
    int
    Get the number of edges in the graph.
    int
    countNeighbors(V vertex)
    Get the number of neighbors for a vertex.
    int
    Get the number of vertices in the graph.
    boolean
    existsEdge(V v1, V v2)
    Check the existence of an edge that goes from the first vertex to the second.
    boolean
    existsPath(V source, V destination)
    Does a path exists between source and destination.
    getNeighbors(V vertex)
    Get the neighbors of a vertex
    getPath(V source, V destination)
    Get a path between a source and a destination
     
    Get all the vertices in the graph
    boolean
    removeEdge(V v1, V v2)
    Remove an edge that goes from the first vertex to the second.
    boolean
    removeVertex(V vertex)
    Remove a vertex from the graph
  • Method Details

    • addEdge

      boolean addEdge(V v1, V v2)
      Add an edge between two vertices. Add the two vertices in the graph if they don't exists
      Parameters:
      v1 - first vertex
      v2 - second vertex
      Returns:
      true if the graph has been modified
    • countEdges

      int countEdges()
      Get the number of edges in the graph.
      Returns:
      number of edges
    • getSpanningTree

      Graph<V> getSpanningTree()
    • addVertex

      boolean addVertex(V vertex)
      Add a vertex to the graph.
      Parameters:
      vertex - the vertex to add
      Returns:
      true if the the graph has been modified
    • removeVertex

      boolean removeVertex(V vertex)
      Remove a vertex from the graph
      Parameters:
      vertex - the vertex to remove
      Returns:
      true if the graph has been modified
    • containsVertex

      boolean containsVertex(V vertex)
      Check the existence of a vertex in the graph.
      Parameters:
      vertex - the vertex to check
      Returns:
      true if the graph contains vertex
    • removeEdge

      boolean removeEdge(V v1, V v2)
      Remove an edge that goes from the first vertex to the second.
      Parameters:
      v1 - first vertex
      v2 - second vertex
      Returns:
      true if the graph has been changed
    • existsEdge

      boolean existsEdge(V v1, V v2)
      Check the existence of an edge that goes from the first vertex to the second.
      Parameters:
      v1 - first vertex
      v2 - second vertex
      Returns:
      true if an edge from v1 to v2 exists
    • getVertices

      List<V> getVertices()
      Get all the vertices in the graph
      Returns:
      a list containing all the graph vertices
    • countVertices

      int countVertices()
      Get the number of vertices in the graph.
      Returns:
      number of vertices
    • getNeighbors

      List<V> getNeighbors(V vertex)
      Get the neighbors of a vertex
      Parameters:
      vertex - the specified vertex
      Returns:
      the list of vertices that are neighbors of vertex null if the vertex is not contained in the graph
    • countNeighbors

      int countNeighbors(V vertex)
      Get the number of neighbors for a vertex.
      Parameters:
      vertex - the spefied vertex
      Returns:
      number of neighbors, -1 if vertex does not exists
    • getPath

      List<V> getPath(V source, V destination)
      Get a path between a source and a destination
      Parameters:
      source - source vertex
      destination - destination vertex
      Returns:
      a list containing the vertices that compose the path, in order; an empty LinkedList if there is no path, null if the source and the destination are equals or are not contained in the graph
    • existsPath

      boolean existsPath(V source, V destination)
      Does a path exists between source and destination.
      Parameters:
      source - source vertex
      destination - destination vertex
      Returns:
      true if a path exists