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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents an edge in a graph. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an edge between two vertices.booleanAdds a vertex to the graph.default voidbfs(V start, VertexVisitor<V> visitor) Performs breadth-first search (BFS) traversal.intReturns the degree (number of edges) of a vertex.default voiddfs(V start, VertexVisitor<V> visitor) Performs depth-first search (DFS) traversal.Set<Graph.Edge<V>> edges()Returns all edges in this graph.booleanChecks if this graph is directed.Returns neighbors of a vertex.intReturns the number of vertices in the graph.vertices()Returns all vertices in this graph.
-
Method Details
-
vertices
-
edges
-
addVertex
Adds a vertex to the graph.- Parameters:
vertex- the vertex to add- Returns:
- true if vertex was added, false if already present
-
addEdge
-
neighbors
-
degree
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
Performs depth-first search (DFS) traversal.- Parameters:
start- the starting vertexvisitor- the visitor to call for each vertex
-
bfs
Performs breadth-first search (BFS) traversal.- Parameters:
start- the starting vertexvisitor- the visitor to call for each vertex
-
vertexCount
int vertexCount()Returns the number of vertices in the graph.- Returns:
- the number of vertices
-