Store two unsorted lists

  • A vertex sequence with a list of vertices
  • An edge sequence with a list of vertex pairs

Where is the # of vertices, is the # of edges

Use a doubly linked list as the container for and for optimal time complexity

Using an array is easier but things like removeEdge will become due to increased deletion time complexity

Time complexities

Where is the # of vertices, is the # of edges

OperationComplexityNotes
SpaceTwo lists
insertVertex(x)Add to V sequence
insertEdge(u,v,x)Add to E sequence
removeVertex(v)Need to traverse edges to remove incident edges
removeEdge(e)Remove from sequence - given doubly-LL
degree(v)Traverse all edges to count
incidentEdges(v)Traverse all edges to return incident one
getEdge(u,v)Traverse all edges to return pointer to matching pair
endVerticesOf(e)Edge pointer given - return the relevant vertex pointers
opposite(v,e)Edge pointer given - return other vertex
vertices()Traverse V
edges()Traverse E
numVertices()Dependent on a counter variable
numEdges()Dependent on a counter variable
  • Can be implemented as a pair of Doubly-linked list where the nodes store two pointers to the connected vertices
  • Array can also be used - the array can store tuples of vertex pointers. Worse time complexity

Directed graph information

See this link