Basic adjacency list graph data structure
Each vertex stores its own sequence of vertices it is adjacent to
USYD content
This is not the adjacency list covered at The University of Sydney. Refer to: “Modern” adjacency list with incidence containers
Time complexities
Where is the # of vertices, is the # of edges
Operation | Complexity | Notes |
---|---|---|
Space | n elements for each vertex, then at most 2m elements for each endpoint of the m vertices | |
insertVertex(x) | Add a new vertex list | |
insertEdge(u,v,x) | Add adjacent vertex element to 2 places | |
removeVertex(v) | Remove the vertex from the adjacency list and also remove all edges connected to that vertex | |
removeEdge(e) | Search for and remove the edge from both vertices’ adjacency lists | |
degree(v) | Track size of vertex’s adjacency list | |
incidentEdges(v) | Traverse adjacency list | |
get/isEdge(u,v) | Get degree of the 2 vertices, traverse adjacency list of smaller to check existence of edge | |
endVerticesOf(e) | N/A | |
opposite(v,e) | N/A | |
vertices() | Traverse V | |
edges() | Traverse all the adjacency lists - O(2m) reduces | |
numVertices() | Dependent on a counter variable | |
numEdges() | Dependent on a counter variable |
The above time complexities are not double-checked