An adjacency list represents a graph by giving each vertex a collection of directly connected edges. A Swift implementation stores vertices separately and keeps a two-dimensional edges array, using integer indexes to connect the two structures. section 4.1
A practical implementation separates graph operations into small pieces:
- Store vertex values in an array; use their integer indexes inside edges. section 4.1
A city graph
Create an UnweightedGraph<String> containing cities such as Seattle, Chicago, and San Francisco. Adding an edge from Seattle to Chicago produces reciprocal neighbor entries, so Seattle lists Chicago and Chicago lists Seattle.




