# The concept of graphs

Let’s start with the question *what is a graph?* Broadly speaking, **a graph is a data structure that consists of ****nodes**** (also called ****vertices****) and ****edges****. Each edge connects two nodes**. A graph data structure does not require any specific rules regarding connections between nodes, as shown in the following diagram:

Figure 8.1 – Illustration of a graph

This concept seems very simple, doesn’t it? Let’s try to analyze the preceding graph to eliminate any doubts. It contains **9 nodes** with numbers between **1** and **9** as values. Such nodes are connected by **11 edges**, such as between nodes **2** and **4**. Moreover, a graph can contain **cycles** – for example, with nodes indicated by **2**, **3**, and **4** – as well as separate groups of nodes, which are not connected.

However, what about the topic of parent and child nodes, which you know from learning about trees? As there are no specific rules about connections in a graph,...