GRAPHS
Graphs
A graph is a versatile data structure that represents relationships between pairs of objects. It is widely used to model networks, social interactions, dependencies, paths, and various other interconnected systems. Unlike trees, which are hierarchical, graphs can have complex structures that may include cycles and multiple connections between nodes.
Key Concepts of Graphs:
Vertex (Node):
A vertex (plural: vertices) is a point or a node in the graph that represents an entity (e.g., a person, a city, a web page).
Edge (Arc):
An edge (or arc) is a connection between two vertices. It represents a relationship or a link between the entities. An edge may or may not have a direction and may or may not have a weight (cost or value).
Adjacency:
Two vertices are adjacent if there is an edge between them. In an undirected graph, the adjacency relationship is mutual (i.e., if A is connected to B, then B is connected to A). In a directed graph, adjacency is one-way.
Path:
A path is a sequence of vertices in which each consecutive pair is connected by an edge. A simple path has no repeated vertices.
Cycle:
A cycle is a path that starts and ends at the same vertex, with all edges and vertices (except the start and end) being distinct.