4.1.8.4 Types of Graphs; Graph Implementation Using Python
Computational Structures
Graphs can be classified into several types based on their structure and properties. The main types of graphs are directed, undirected, and weighted. Each type has its own characteristics, which can be better understood through simple examples.
- Directed Graphs: In a directed graph, edges have a direction, which means they go from one vertex to another in a specific way as shown in Figure 4.11.
Example: Consider a graph shown in figure 4.11 . If you want to travel from city A to city B, you can only go in the direction permitted by the city's sign. If there's no one-way street going from city A to city B, you cannot travel directly from city A to B.
- Undirected Graphs: In an undirected graph, edges do not have a direction. This means that if there is a connection between two vertices, you can travel in both directions.
Example: Consider a graph that shown in Figure 4.12, if Person A is friends with Person B, then Person B is also friends with Person A. There is no restriction on the direction of the friendship, so you can move freely between friends.