Concept

An AdjacencyGraph is a graph which is concerned only with the vertices and not with the edges. There are no explicit edge objects, adjacent vertices are simply accessed as neighbors(). For many use cases this is sufficient.

Complexity

  • neighbors() is required to be constant time; iterating over the iterable is required to be linear in the number of neighbors
  • degreeOf() is required to be at most linear in the number of neighbors
  • containsEdge() is required to be at most linear in the number of neighbors

Infinite Graphs

The number of vertices may be infinite in which case the user has to take care not to call methods which will not return (this is similar to an Iterable which may contain an infinite number of elements).

The same applies for the number of neighbors of a vertex.

Design Notes

Think about making Vertex (and, in subclasses, Edge) member classes! cf. Graph example here

By: ThorstenSeitz

no type hierarchy

no supertypes hierarchy

Attributes
emptySource Codeshared formal Boolean empty

Answer whether the graph is empty, i.e. contains no vertices.

notEmptySource Codeshared default Boolean notEmpty

Answer whether the graph is not empty, i.e. contains at least one vertex.

Inherited Attributes
Attributes inherited from: Object
Methods
containsEdgeSource Codeshared default Boolean containsEdge(V source, V target)

Answer whether the graph contains an edge from source to target.

degreeOfSource Codeshared Integer degreeOf(V vertex)

Answer the degree of the given vertex, i.e. the number of neighbors.

     This method will (obviously) not return if the vertex has inifinite neighbors.
forEachNeighborSource Codeshared void forEachNeighbor(V vertex, void action(V neighbor))

Apply action for each neighbor of the given vertex.

     This method will (obviously) not return if the vertex has an inifinite number of neighbors.
hasNeighborsSource Codeshared default Boolean hasNeighbors(V vertex)

Answer whether the given vertex has at least one neighbor.

neighborsSource Codeshared formal {V*} neighbors(V vertex)

All neighbor vertices of the given vertex. A neighbor is the target of an outgoing directed edge

     or the other endpoint of an undirected edge.
Inherited Methods
Methods inherited from: Object