Graphs
Graphs are one of the most versatile and widely used non-linear data structures. They are used to represent relationships between entities, where entities are represented as nodes (also called vertices) and relationships as edges. Graphs can model a wide range of real-world problems, from social networks to transportation systems and communication protocols.
Graphs come in various types, each with specific properties that make them suitable for different tasks. Here are the most common types of graphs:
- Undirected graphs: In undirected graphs, edges have no direction. The relationship between two nodes is bidirectional (see Figure 13.1). If there is an edge between node A and node B, you can traverse from A to B or from B to A without any restrictions. An example of an undirected graph is the social network of Facebook friends, where connections are mutual. This means if A is friends with B, then B is also friends with A, reflecting the bidirectional nature of the...