Applications
At this point, you know some basic information about graphs, especially regarding nodes and various kinds of edges. However, why is the topic of graphs so important and why does it take up a whole chapter in this book? Could you use this data structure in your applications? The answer is obvious: yes! Graphs are commonly used while solving algorithmic problems and have numerous real-world applications.
To start, let’s think about a structure of friends available on social media. Each user has many contacts, but they also have many friends, and so on. What data structure should you choose to store such data? A graph is the simplest answer. In such a scenario, the nodes represent contacts, while the edges depict relationships between people. As an example, let’s take a look at the following diagram of an undirected and unweighted graph:
Figure 8.4 – Illustration of a graph representing a structure of friends
As you can...