LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

In the adjacency list structure, why does every edge store references to its positions in the two incidence sequences?

So that removeEdge(e) can unlink e from both incidence sequences directly, in $O(1)$. Without those references the graph would first have to search v's and w's sequences for e, which costs $O(\deg(v) + \deg(w))$.

The incidence sequences are linked lists, and given a reference to its node, an element is unlinked from a doubly linked list in constant time. insertEdge(v, w, o) records these references as it goes: it appends the new edge to the edge sequence, to v's incidence sequence and to w's, and stores the three node references in the edge. In an implementation that is one line per sequence, for example e.backReferences[0] = vi.incidentList.insert(e).

Linked lists only pay off together with such references. Finding a node by its index in a Java LinkedList walks node by node from the nearer end: 500 000 steps to reach the middle of a million elements. The stored references skip that walk entirely.

The same references make removeVertex(v) cheap. It removes every incident edge with removeEdge at $O(1)$ each, then unlinks v itself through its own position reference: $O(\deg(v))$ in total, against $O(m)$ in the plain edge list.

Go deeper:

  • doc Doubly linked list โ€” why removing a node you hold a reference to takes constant time.

From Quiz: ADS / Graphs: Basics, Representations and Spanning Trees | Updated: Nov 27, 2026