Graph data structure

A graph is a non-linear data structure containing a set of points known as nodes (or vertices) and a set of links known as edges, as illustrated in the following diagram:

Figure 7

An edge that connects to the same node is called a cycle. As shown in the preceding diagram, nodes a and b are connected by two paths; one is through edge a-b, and the other is through edges a-d and d-b. A tree is a special type of graph, in which there are no cycles, and two nodes are connected by one path.

In Python, we can use a dictionary structure to represent a graph. A dictionary is a data structure where many keys are mapped to values. ...

Get Hands-On Artificial Intelligence for Search 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.