Wikipedia states that three different graph implementations are used in practice:
- Adjacency Lists
- Adjacency Matrix
- Incidence Matrix
While I was learning about these structures, an otheranother option 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, vertex)
pairs and the values are the weight of theirthe 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(m)$$O(|E|)$ space
- Add vertex: $O(1)$ time
- Add edge: $O(1)$ time
- Remove vertex: $O(n)$$O(|V|)$ time
- Remove edge: $O(1)$ time
- Query edge existence: $O(1)$ time
Since thisThis structure has strictly better time and space complexities than all three options listed, I'm confused as to . why this optionSo why isn't this implementation used in practice.?