Graphs: The Basic Building Blocks (1.1)
At the heart of graph theory lies the concept of a graph, a structure used to model relationships between objects. Formally, a graph is an ordered pair , where is a non-empty, finite set of vertices (or nodes), and is a set of edges. In our initial definition, we consider undirected graphs, where each edge connects a pair of vertices without specifying a direction. Mathematically, edges are defined as two-element subsets of the vertex set .
Each element , an edge, is thus a set representing a connection between vertices and . This formulation implies that the order of vertices in an edge does not matter, and self-loops (edges connecting a vertex to itself) are not allowed in simple graphs.
Graphs provide an intuitive way to visualize and analyze relationships. We can represent a graph by drawing vertices as points or circles and edges as lines connecting these vertices. An edge is drawn between two vertices if and only if the corresponding vertices are connected by an edge in the graph. This visual representation, as exemplified in Figure 1.1 of the provided text, greatly aids in understanding the structure and properties of graphs.
Types of Graphs and Examples
To illustrate the versatility of graphs, let’s consider some fundamental graph types. These examples help solidify the abstract definition and introduce common graph structures we will encounter.
-
Complete Graph (): A complete graph on vertices, denoted as , is a graph where every pair of distinct vertices is connected by an edge. In a complete graph, there are no missing edges; it is maximally connected.
-
Cycle Graph (): A cycle graph on vertices, denoted as , forms a closed loop. Vertices are connected in a cyclic manner, where each vertex is connected to exactly two others, forming a ring structure.
-
Path Graph (): A path graph on vertices, denoted as , is formed by a sequence of vertices where each vertex is connected to the next in a linear chain. It can be visualized as a cycle graph with one edge removed, resulting in a path with two endpoints.
-
d-dimensional Hypercube (): The d-dimensional hypercube is a more complex graph structure defined on the vertex set , which is the set of all binary sequences of length . Two vertices in are adjacent if and only if their binary sequences differ in exactly one position. The hypercube generalizes the familiar cube () and square () to higher dimensions.
Bipartite Graphs
A significant class of graphs is bipartite graphs. A graph is called bipartite if its vertex set can be partitioned into two disjoint sets, say and (denoted ), such that every edge in connects a vertex in to a vertex in . There are no edges within or within . Bipartite graphs are crucial in modeling relationships where two distinct types of entities are interconnected, but entities of the same type are not.
Hypercubes and path graphs are examples of bipartite graphs. Cycles, however, are bipartite only if they have an even number of vertices.
Multigraphs and Loops
While our initial definition of a graph excludes self-loops and multiple edges between the same pair of vertices, a more general structure, called a multigraph, allows for these features.
-
Loops: A loop is an edge that connects a vertex to itself, i.e., an edge of the form .
-
Multiple Edges: Multiple edges occur when more than one edge exists between the same pair of vertices.
Graphs that permit loops and multiple edges are termed multigraphs. While multigraphs are useful in certain contexts, in this course, unless explicitly stated otherwise, we will primarily focus on simple graphs, which are graphs without loops and multiple edges. When we do consider multigraphs, we will clearly indicate it.
Degree and Neighborhood
To further describe the properties of vertices within a graph, we introduce the concepts of neighborhood and degree.
-
Neighborhood (): The neighborhood of a vertex in a graph , denoted , is the set of all vertices adjacent to .
-
Degree (): The degree of a vertex , denoted , is the number of vertices in its neighborhood, or equivalently, the number of edges incident to .
When the graph is clear from the context, we often omit the subscript and simply write and .
A graph is called k-regular if every vertex in has the same degree . Complete graphs are -regular, cycles are 2-regular, and hypercubes are -regular.
Adjacency and Incidence
-
Adjacent Vertices: Two vertices and are said to be adjacent if there is an edge connecting them, i.e., .
-
Incident Edge and Vertex: A vertex and an edge are said to be incident if is one of the endpoints of . For an edge , vertices and are the endpoints of .
Handshaking Lemma
A fundamental result in graph theory that relates the degrees of vertices to the number of edges is the Handshaking Lemma (Satz 1.2). It states that the sum of the degrees of all vertices in a graph is equal to twice the number of edges.
Theorem 1.2 (Handshaking Lemma): For any graph , the sum of the degrees of all vertices is equal to twice the number of edges:
Proof: This result arises from a simple counting principle, often referred to as double counting. When we sum the degrees of all vertices, each edge is counted exactly twice: once when we consider the degree of and once when we consider the degree of . Therefore, the sum of degrees counts each edge twice, leading to the factor of 2 in the formula.
Corollary 1.3: An immediate consequence of the Handshaking Lemma is that in any graph, the number of vertices with an odd degree must be even.
Proof: Let be the set of vertices with even degrees, and be the set of vertices with odd degrees. Then,
The sum of even numbers is always even. For the total sum to be even (as it is equal to ), the sum of odd degrees, , must also be even. This is only possible if the number of terms in this sum, , is even.
Corollary 1.4: In any graph , the average degree of a vertex is . Consequently, there must exist at least two vertices, say and , such that and . This follows from the fact that in any set of numbers, there must be at least one number greater than or equal to the average and at least one number less than or equal to the average.
Subgraphs
A subgraph of a graph is a graph where the vertex set is a subset of , and the edge set is a subset of such that both endpoints of every edge in are in . We write to denote that is a subgraph of .
An induced subgraph is a special type of subgraph where the edge set consists of all edges from that connect vertices in . If is an induced subgraph of with vertex set , we write .
To obtain a subgraph, we can remove vertices and/or edges from the original graph. However, to obtain an induced subgraph, we can only remove vertices; the edges are then determined by the remaining vertices.
The notation denotes the induced subgraph obtained by removing vertex and all edges incident to from graph .
Connectivity and Trees (1.1.1)
Walks, Paths, and Cycles
Within a graph, we can traverse sequences of vertices and edges. These traversals are fundamental to understanding connectivity and structure.
-
Walk: A walk in a graph is a sequence of vertices such that for each , there is an edge between and . The length of a walk is the number of steps, which is in this case. Vertices and are the start and end vertices of the walk, respectively. A walk with start vertex and end vertex is called an -walk.
-
Path: A path is a walk where all vertices are distinct, except possibly the start and end vertices. An -path is a path with start vertex and end vertex .
-
Cycle: A cycle is a walk where (start and end vertices are the same), and the length is at least 3, and all vertices are distinct. A cycle is also known as a closed walk.
Connectedness
A graph is connected if for every pair of vertices , there exists a path between and . If a graph is not connected, it consists of several connected components. A connected component is a maximal connected subgraph. The vertex sets of the connected components of a graph form a partition of the vertex set.
Trees
A graph that contains no cycles is called acyclic or cycle-free. A tree is defined as a connected, acyclic graph. Trees are fundamental structures in graph theory and have many important properties.
Lemma 1.5: For a tree with vertices:
- (a) contains at least two leaves (vertices of degree 1).
- (b) If is a leaf, then is also a tree.
Proof of (a): Consider any edge . Start a walk from and along the graph, continuing as long as possible without repeating edges. Since is acyclic, we will never revisit a vertex in the current path to form a cycle. Since is finite, these walks must eventually terminate at vertices where no further edges can be traversed. These terminating vertices must be leaves, as they have degree 1 (or potentially 0 if we walked back to the starting vertex immediately, but since , this is not the case starting from an edge). Since we started from both ends of an edge, we must find at least two leaves.
Proof of (b): If is acyclic, then removing a vertex and its incident edges will not create any cycles. Thus, remains acyclic. We need to show that remains connected if is a leaf. Let . Since is connected, there is a path between and in . If this path does not contain , then it is also a path in . If does contain , since is a leaf, it has degree 1. Therefore, can only be an endpoint of the path . If is an intermediate vertex in the path, it would require degree at least 2. Since is a leaf, cannot be an intermediate vertex on any path. Thus, if a path exists between and in it will exist in . Hence, remains connected.
Theorem 1.6: For a graph with vertices, the following statements are equivalent:
- (a) is a tree.
- (b) is connected and acyclic.
- (c) is connected and .
- (d) is acyclic and .
- (e) For every pair of vertices , there is exactly one path in .
Proof: The proof demonstrates the equivalence of these properties through a series of implications, leveraging induction and contradiction to establish the relationships between connectedness, acyclicity, edge count, and path uniqueness in trees. The proof is detailed in the provided text and is an excellent exercise in understanding the fundamental properties of trees.
Lemma 1.7: A forest (a graph without cycles, but not necessarily connected) contains exactly connected components.
Proof: The proof uses induction on the number of edges . The base case is when . In this case, each vertex is a connected component, and the number of components is . For the inductive step, assume the lemma holds for a forest and consider adding an edge to form , such that is still acyclic. Edge must connect two vertices in different connected components of (otherwise, adding it would create a cycle). Adding merges these two components into one, reducing the number of components by one, while increasing the number of edges by one. Thus, the lemma still holds for .
Directed Graphs (1.1.2)
In directed graphs (or digraphs), edges have direction. Instead of two-element sets, edges are ordered pairs of vertices, denoted as arcs. An arc represents a directed edge from vertex to vertex . The set of arcs in a directed graph is a subset of the Cartesian product .
A directed edge is graphically represented as an arrow from to . While simple graphs do not allow loops or multiple edges, in directed graphs, loops (arcs from a vertex to itself) and multiple arcs between the same pair of vertices are formally allowed, although in this course we will generally consider directed graphs without loops and multiple arcs unless explicitly stated otherwise. Note that even without multiple arcs in the same direction, we may have both and in a directed graph, which are distinct arcs.
In-degree and Out-degree
For vertices in directed graphs, we distinguish between incoming and outgoing edges.
-
Out-degree (): The out-degree of a vertex is the number of arcs originating from .
-
In-degree (): The in-degree of a vertex is the number of arcs terminating at .
Theorem 1.8: In any directed graph , the sum of in-degrees is equal to the sum of out-degrees, and both are equal to the total number of arcs .
Directed Walks, Paths, and Cycles
Analogous to undirected graphs, we define directed walks, paths, and cycles in directed graphs, respecting the direction of arcs.
-
Directed Walk: A directed walk is a sequence of vertices such that for each , .
-
Directed Path: A directed path is a directed walk where all vertices are distinct.
-
Directed Cycle: A directed cycle is a directed walk where and are distinct.
Acyclic Digraphs (DAGs)
A directed graph that contains no directed cycles is called an acyclic digraph or simply a DAG (Directed Acyclic Graph). DAGs have many special properties and are used to model dependencies and hierarchies. A key property of DAGs is that their vertices can be topologically sorted.
Theorem 1.9: For any DAG , a topological sorting can be computed in time.
Strong and Weak Connectivity
Connectivity in directed graphs has two main variations:
-
Strongly Connected: A directed graph is strongly connected if for every pair of vertices , there is a directed path from to and a directed path from to .
-
Weakly Connected: A directed graph is weakly connected if the underlying undirected graph (obtained by ignoring the direction of edges) is connected.
Every strongly connected graph is also weakly connected, but the converse is not necessarily true. DAGs, for instance, can be weakly connected if their underlying undirected graph is connected, but they cannot be strongly connected (unless trivial, with one vertex and no arcs), as the presence of a directed cycle is required for strong connectivity.
Data Structures (1.1.3)
To efficiently work with graphs in algorithms, we need appropriate data structures to represent them. The two most common representations are:
-
Adjacency Matrix: An adjacency matrix for a graph with vertices (labeled ) is an matrix , where if there is an edge (or arc) between vertex and vertex , and otherwise. For undirected graphs, the adjacency matrix is symmetric. For graphs without self-loops, the diagonal elements are zero.
-
Adjacency List: An adjacency list representation stores, for each vertex , a list of its neighbors (or vertices reachable by outgoing arcs from in a directed graph). Adjacency lists are generally more space-efficient for sparse graphs (graphs with relatively few edges).
The choice between adjacency matrices and adjacency lists often depends on the specific algorithm and the density of the graph. Adjacency lists are typically preferred for algorithms like breadth-first search (BFS) and depth-first search (DFS) on sparse graphs, offering a time complexity of . Adjacency matrices, while potentially less space-efficient for sparse graphs, allow for constant-time adjacency checks and can be beneficial for dense graphs or algorithms that rely on matrix operations. Adjacency matrices also lend themselves to algebraic graph theory methods.
Theorem 1.13: If is the adjacency matrix of a graph (or digraph), then the entry represents the number of paths of length exactly from vertex to vertex .
This theorem highlights the utility of adjacency matrices in analyzing path properties of graphs, particularly when combined with matrix multiplication techniques.