Adjacency lists and matrices

Which neighbor lists change?

Examples

Worked example

Input
An undirected graph has edge A—B.
Expected output
A gains B and B gains A.

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The edge can be traversed in either direction, so both endpoints need the other endpoint as a neighbor.

Back to the lesson