Skip to main content
1 of 3

Why isn't an edge-map graph implementation used in practice?

Wikipedia states that three different graph implementations that are used in practice:

  • Adjacency Lists
  • Adjacency Matrix
  • Incidence Matrix

While I was learning about these structures, another implementation occurred to me that seems to have better asymptotic properties than Wikipedia's. My idea is to create a hash map where the keys are (vertex, vertex) pairs and the values are the cost of their edge.

Given that inserting into and querying from a hash map is $O(1)$, I believe the time complexity would be the following:

  • Store graph: $O(E)$
  • Add vertex: $O(1)$
  • Add edge: $O(1)$
  • Remove vertex: $O(V)$
  • Remove edge: $O(1)$
  • Query cost between vertices: $O(1)$

Since this implementation has strictly better time and space complexity then all three options listed, I'm confused as to why this option isn't.

Why isn't this implementation used in practice?