liveBook · Manning

Adjacency list

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A graph representation that stores, for each vertex, the vertices or edges directly connected to it.

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.

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines the representation and demonstrates Swift storage and lookup, but stops short of detailed graph algorithms.
Examples
Uses a city graph and printed neighbor lists to show reciprocal adjacency.
What it assumes
Assumes Swift arrays, protocols, classes, and Equatable values while teaching indexed graph storage.
What you can do after
Build it from scratch as a Swift graph with indexed vertices, adjacency lists, edges, and neighbor lookup.
How it connects
Connects vertices, edges, undirected graphs, graph protocols, and integer indexing.

Also explained in

Compare how 5 books explain adjacency list →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.