Directed and undirected graphs

Graphs can be undirected (where edges do not have a direction) or directed (digraph), where edges have a direction, as demonstrated in the following diagram:

A graph is strongly connected if there is a path in both directions between every pair of vertices. For example, C and D are strongly connected, while A and B are not strongly connected.

Graphs can also be unweighted (as we have noted so far) or weighted (in which the edges have weights—or values), as shown in the following diagram:

We can solve many problems ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.