Search⌘ K
AI Features

Graphs

Explore the foundational concepts of graph theory including vertices, edges, directed and undirected graphs, connectivity, paths, cycles, and graph types such as planar, dependency, and configuration graphs. Understand how these concepts apply to algorithms and problem solving in Python, enhancing your ability to work with graph data structures and perform advanced computations.

Graph

Formally, a simple graph is a pair of sets (V,E),(V,E), where VV is an arbitrary non-empty finite set, whose elements are called vertices or nodes, and EE is a set of pairs of elements of V,V, which we call edges. In an undirected graph, the edges are unordered pairs or just sets of size two. We usually write uv{uv} instead of {u,v}\left\{ u, v \right\} to denote the undirected edge between uu and vv. In a directed graph, the edges are ordered pairs of vertices. We usually write uvu\rightarrow v instead of (u,v)(u, v) to denote the directed edge from uu to vv.

Following standard (but admittedly confusing) practice, we will also use VV to denote the number of vertices in a graph and EE to denote the number of edges. Thus, in any undirected graph, we have 0E(V2)0 ≤ E ≤ \binom{V}{2}, and in any directed graph, we have 0EV(V1)0 ≤ E ≤ V (V − 1).

The endpoints of an edge uvuv or uvu\rightarrow v are its vertices uu and vv. We distinguish the endpoints of a directed edge uvu\rightarrow v by calling uu the tail and vv the head.

The definition of a graph as a pair of sets forbids multiple undirected edges with the same endpoints or multiple directed edges with the same head and the same tail. (The same directed graph can contain both a directed edge uvu\rightarrow v and its reversal vuv\rightarrow u ...