Definition

Graphs are ADTs used to represent connected concepts with nodes/vertices and edges. A graph is an ordered pair of nodes and edges, expressed as

Variations of graphs can have different features, which can be used to model other properties. A few include:

  • Weights
  • Direction of edges
  • Node and/or edge attributes

Signature

name: graph; 
import node, edge, list, integer, boolean;  
ops:
	newGraph:→ graph;
	allNodes:graph → list;
	allEdges:graph → list;
	addNode:graph × node → graph;
	deleteNode:graph × node → graph;
	NodeExists:graph × node → boolean;
	addEdge:graph × edge → graph;
	deleteEdge:graph × edge → graph;
	EdgeExists:graph × edge → boolean;
	neighbours:graph × node → list;
	startNode:edge → node;
	endNode:edge → node;
	incident:graph × node → list;