In Graph Theory, we know that an Vertex adjacencies can be represented using Adjacency list data structure. On contrary, adjacency set is not widely mentioned anywhere in the Graph Theory. Why is that so?
Here's the pros, i can think of.
As Set property, the graph could provide a guarantee in term of duplicated edge and many other properties of Set. Moreover all set operation from the Set Theory became available which is more intuitive to work with the analysis. Such as:
vertex_set_A | vertex_setB
is the union operation.vertex_set_A & vertex_set_B
, is the intersection operation.
*Opinion, Set is more understandable as it has correlation in the mathematical proofing. It is also provide a good abstraction of how the low level code dealing with array and stuff.
- In term of Performance, one could use HashSet implementation which would provide a constant time operation. Or TreeSet when the graph need to dynamically changed frequently on log time operation.
- List data structure also maintain the ordering property of the element which serve no purpose in most graph. In fact, list iterates in ordered fashion which should not happened in the first place. Indexed Ordered should not matter and Set could provide that. The only time when ordering mattered is when the graph is weighted, and thus the ordering based on the weight, in which TreeSet operate mostly in log time operation.
So, I am unsure why most graph algorithms only mentioning adjacency list. Is it because of the technology barrier where Set
is harder to implement, whereas List
is easier?