Disambiguation

We refer to the ‘modern’ adjacency matrix where adjacent vertices have a reference to their edge object in their corresponding cell and otherwise hold null

  • The other option is for the matrix to be True/False values

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

OperationComplexityNotes
Space2D matrix, indices 0 to n-1
insertVertex(x)Even with a Dynamic array, worst case we have to copy/realloc entire matrix when full. Average can be O(2n) though
insertEdge(u,v,x)Add 2 pointers to the relevant indexes
removeVertex(v)Copy and reallocate - we might remove a vertex in the middle row/col, unavoidable worst-case
removeEdge(e)Go to the [u][v] and [v][u] (edge obj storing vertex info)
degree(v)O(n) usually but we could keep a counter for each vertex
incidentEdges(v)Traverse corresponding vertex row/column
getEdge(u,v)Go to [u][v]
endVerticesOf(e)Return the stored values (assume edge obj stores)
opposite(v,e)Return other stored value
vertices()Traverse axis
edges()Traverse all indices1
numVertices()Dependent on a counter variable
numEdges()Dependent on a counter variable

Directed graph information

See this link

Footnotes

  1. Unsure, linked document says O(m)