Interface Graph<V>

All Known Subinterfaces:
Tree<V>, WeightedGraph<V,W>
All Known Implementing Classes:
BayesianBeliefNetwork, DirectedWeightedGraph, MolecularGraph, NetworkGraph, Polyhedron, RootedTree, SocialNetwork, Story, UndirectedGraph

public interface Graph<V>
Represents a mathematical graph G = (V, E).

A graph consists of vertices (nodes) and edges connecting them. Supports both directed and undirected graphs.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents an edge in a graph.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    addEdge(V source, V target)
    Adds an edge between two vertices.
    boolean
    addVertex(V vertex)
    Adds a vertex to the graph.
    default void
    bfs(V start, VertexVisitor<V> visitor)
    Performs breadth-first search (BFS) traversal.
    int
    degree(V vertex)
    Returns the degree (number of edges) of a vertex.
    default void
    dfs(V start, VertexVisitor<V> visitor)
    Performs depth-first search (DFS) traversal.
    Returns all edges in this graph.
    boolean
    Checks if this graph is directed.
    neighbors(V vertex)
    Returns neighbors of a vertex.
    int
    Returns the number of vertices in the graph.
    Returns all vertices in this graph.
  • Method Details

    • vertices

      Set<V> vertices()
      Returns all vertices in this graph.
      Returns:
      unmodifiable set of vertices
    • edges

      Set<Graph.Edge<V>> edges()
      Returns all edges in this graph.
      Returns:
      unmodifiable set of edges
    • addVertex

      boolean addVertex(V vertex)
      Adds a vertex to the graph.
      Parameters:
      vertex - the vertex to add
      Returns:
      true if vertex was added, false if already present
    • addEdge

      boolean addEdge(V source, V target)
      Adds an edge between two vertices.
      Parameters:
      source - the source vertex
      target - the target vertex
      Returns:
      true if edge was added
    • neighbors

      Set<V> neighbors(V vertex)
      Returns neighbors of a vertex.
      Parameters:
      vertex - the vertex
      Returns:
      set of adjacent vertices
    • degree

      int degree(V vertex)
      Returns the degree (number of edges) of a vertex.
      Parameters:
      vertex - the vertex
      Returns:
      degree of vertex
    • isDirected

      boolean isDirected()
      Checks if this graph is directed.
      Returns:
      true if directed, false if undirected
    • dfs

      default void dfs(V start, VertexVisitor<V> visitor)
      Performs depth-first search (DFS) traversal.
      Parameters:
      start - the starting vertex
      visitor - the visitor to call for each vertex
    • bfs

      default void bfs(V start, VertexVisitor<V> visitor)
      Performs breadth-first search (BFS) traversal.
      Parameters:
      start - the starting vertex
      visitor - the visitor to call for each vertex
    • vertexCount

      int vertexCount()
      Returns the number of vertices in the graph.
      Returns:
      the number of vertices