CIT 5920
Sli.do Ed Discussion PrairieLearn Panopto Gradescope Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Introduction to Graph Basics

Introduction

Graph theory is a fundamental area of discrete mathematics with extensive applications in computer science. Graphs are used to model networks, relationships, and structures in various domains such as social networks, communication systems, data organization, and more. Understanding graph theory is essential for algorithm design, data structures, network analysis, and solving complex computational problems.

In this lecture, we will explore the foundational concepts of graph theory, progressing through a structured sequence to build a comprehensive understanding:

  1. Definition of a Graph
  2. Edges and Their Properties
  3. Types of Graphs
  4. Degree of a Vertex
  5. Degree Sum Formula
  6. Graph Representations
  7. Graph Data Structures in Practice
  8. Paths and Walks
  9. Result: Any Walk Contains a Path
  10. Connectedness and Connected Components
  11. Trees
  12. Properties of Trees
  13. Circuits and Cycles
  14. Graph Algorithms Applications

1. Definition of a Graph

Definition

A graph \( G \) is a mathematical structure used to model pairwise relations between objects. It consists of two finite sets:

  • A set of vertices (also called nodes), denoted by \( V \).
  • A set of edges, denoted by \( E \), which are pairs of vertices.

The graph is denoted as:

\[ G = (V, E) \]

Edge Cases

  • Can a graph have no edges?
    • Yes. Such a graph is called an edgeless graph or an empty graph. It consists solely of isolated vertices.
  • Can there be multiple edges between the same pair of vertices?
    • Yes, in a multigraph. In a simple graph, there is at most one edge between any pair of vertices.

Examples

Example 1: Simple Graph

Let \( V = {A, B, C, D} \) and \( E = {(A, B), (B, C), (C, D)} \).

  • Visualization:

    A --- B --- C --- D
    
  • Explanation: Each vertex represents an object, and each edge represents a relationship between two objects.

Example 2: Edgeless Graph

Let \( V = {1, 2, 3} \) and \( E = \emptyset \).

  • Visualization:

    1   2   3
    
  • Explanation: No edges connect the vertices; the graph consists of isolated points.

Example 3 (CS-Themed): Network Nodes

Vertices represent servers in a network \( V = {S1, S2, S3} \), and edges represent direct communication links \( E = {(S1, S2), (S2, S3)} \).

  • Visualization:

    S1 --- S2 --- S3
    
  • Explanation: Models a network where servers are connected if they can communicate directly.


2. Edges and Their Properties

Concepts Introduced

  • Endpoints of an Edge: The two vertices connected by an edge.
  • Incident Edges: Edges that are connected to a vertex.
  • Adjacency: Two vertices are adjacent if they are connected by an edge.

Edge Cases

  • Is an edge from a vertex to itself valid?
    • Yes. It’s called a loop or self-loop.
  • Can an edge exist without connecting any vertices?
    • No. By definition, an edge must connect two vertices (which may be the same in the case of a loop).

Examples

Example 1: Incident Edges

Given graph \( G = (V, E) \) with \( V = {A, B, C} \) and \( E = {(A, B), (A, C)} \).

  • Incident Edges on Vertex A: \( (A, B) \), \( (A, C) \).
  • Explanation: Vertex A has two edges connected to it.

Example 2: Adjacency

In the same graph, vertices B and C are not adjacent because there is no edge between them.

  • Adjacency List:
    • A: B, C
    • B: A
    • C: A

Example 3 (CS-Themed): User Friendships

In a social network, users are vertices \( V = {\text{Alice}, \text{Bob}, \text{Carol}} \), and friendships are edges \( E = {(\text{Alice}, \text{Bob}), (\text{Bob}, \text{Carol})} \).

  • Adjacency:
    • Alice and Bob are adjacent.
    • Bob and Carol are adjacent.
    • Alice and Carol are not adjacent.

3. Types of Graphs

Concepts Introduced

  • Directed Graphs: Edges have a direction, represented as ordered pairs \( (u, v) \).
  • Undirected Graphs: Edges have no direction, represented as unordered pairs \( {u, v} \).
  • Loops (Self-Loops): Edges that connect a vertex to itself.

Edge Cases

  • In a directed graph, is the edge \( (u, v) \) the same as \( (v, u) \)?
    • No. The edge \( (u, v) \) goes from \( u \) to \( v \); direction matters.
  • Can a graph be both directed and undirected?
    • Yes. Such graphs are called mixed graphs, containing both directed and undirected edges.

Examples

Example 1: Directed Graph

Let \( V = {1, 2, 3} \) and \( E = {(1, 2), (2, 3)} \).

  • Visualization:

    1 --> 2 --> 3
    
  • Explanation: Represents processes or dependencies where direction is significant.

Example 2: Undirected Graph with Loops

Let \( V = {A, B} \) and \( E = {(A, A), (A, B)} \).

  • Visualization:

    (Loop at A)
    A --- B
    
  • Explanation: Vertex A has a self-loop and is connected to B.

Vertices represent web pages, edges represent hyperlinks.

  • Directed Graph: If page A links to page B, there is an edge \( (A, B) \).

  • Example:

    • \( V = {\text{Home}, \text{About}, \text{Contact}} \)
    • \( E = {(\text{Home}, \text{About}), (\text{About}, \text{Contact}), (\text{Contact}, \text{Home})} \)
  • Visualization:

    Home --> About --> Contact --> Home
    

4. Degree of a Vertex

Concepts Introduced

  • Degree in Undirected Graphs: Number of edges incident to a vertex.
  • In-Degree in Directed Graphs: Number of edges coming into a vertex.
  • Out-Degree in Directed Graphs: Number of edges going out from a vertex.
  • Counting Self-Loops:
    • In undirected graphs, a loop adds 2 to the degree.
    • In directed graphs, a loop adds 1 to both in-degree and out-degree.

Edge Cases

  • How is a self-loop counted in degree?
    • Undirected Graph: Adds 2 to the degree.
    • Directed Graph: Adds 1 to both in-degree and out-degree.
  • Can a vertex have zero degree?
    • Yes. Such a vertex is called an isolated vertex.

Examples

Example 1: Degree in Undirected Graph

Graph with \( V = {A, B, C} \) and \( E = {(A, B), (A, C), (B, C)} \).

  • Degrees:
    • \( \deg(A) = 2 \)
    • \( \deg(B) = 2 \)
    • \( \deg(C) = 2 \)

Example 2: Degree with Self-Loop

Graph with \( V = {X} \) and \( E = {(X, X)} \).

  • Degree of X:
    • Undirected: \( \deg(X) = 2 \)
    • Directed:
      • In-degree: 1
      • Out-degree: 1

Example 3 (CS-Themed): Network Traffic

Vertices represent servers; directed edges represent data packets sent.

  • Graph:
    • \( V = {S1, S2, S3} \)
    • \( E = {(S1, S2), (S2, S3), (S2, S1)} \)
  • Degrees:
    • S1:
      • In-degree: 1 (from S2)
      • Out-degree: 1 (to S2)
    • S2:
      • In-degree: 1 (from S1)
      • Out-degree: 2 (to S1 and S3)
    • S3:
      • In-degree: 1 (from S2)
      • Out-degree: 0

5. Degree Sum Formula

Concepts Introduced

  • Degree Sum Formula:
    • For undirected graphs: \( \sum_{v \in V} \deg(v) = 2e \), where \( e \) is the number of edges.
    • For directed graphs:
      • Sum of in-degrees: \( \sum_{v \in V} \deg_{in}(v) = e \)
      • Sum of out-degrees: \( \sum_{v \in V} \deg_{out}(v) = e \)

Edge Cases

  • Does the formula hold for graphs with self-loops?
    • Yes. Self-loops contribute correctly when degrees and edges are counted properly.
  • How does the formula adapt to directed graphs?
    • The sum of all in-degrees equals the sum of all out-degrees, both equal to the number of edges.

Examples

Example 1: Undirected Graph

Graph with \( V = {A, B, C} \) and \( E = {(A, B), (B, C)} \).

  • Degrees:
    • \( \deg(A) = 1 \)
    • \( \deg(B) = 2 \)
    • \( \deg(C) = 1 \)
  • Degree Sum: \( 1 + 2 + 1 = 4 \)
  • Edges: \( e = 2 \)
  • Verification: \( 2e = 4 \)

Example 2: Directed Graph

Graph with \( V = {1, 2, 3} \) and \( E = {(1, 2), (2, 3), (3, 1)} \).

  • In-Degrees:
    • \( \deg_{in}(1) = 1 \)
    • \( \deg_{in}(2) = 1 \)
    • \( \deg_{in}(3) = 1 \)
  • Out-Degrees:
    • \( \deg_{out}(1) = 1 \)
    • \( \deg_{out}(2) = 1 \)
    • \( \deg_{out}(3) = 1 \)
  • Sum of In-Degrees: \( 1 + 1 + 1 = 3 \)
  • Sum of Out-Degrees: \( 1 + 1 + 1 = 3 \)
  • Edges: \( e = 3 \)
  • Verification: Sum of degrees equals number of edges.

Vertices represent web pages, edges represent hyperlinks.

  • Graph:
    • \( V = {\text{Home}, \text{Products}, \text{Contact}} \)
    • \( E = {(\text{Home}, \text{Products}), (\text{Products}, \text{Contact}), (\text{Contact}, \text{Home})} \)
  • Degrees:
    • In-Degrees:
      • Home: 1
      • Products: 1
      • Contact: 1
    • Out-Degrees:
      • Home: 1
      • Products: 1
      • Contact: 1
  • Verification: Sum of in-degrees and out-degrees both equal the number of edges (3).

6. Graph Representations

Concepts Introduced

  • Adjacency Lists: Each vertex stores a list of adjacent vertices.
    • Efficient for sparse graphs (graphs with relatively few edges).
  • Adjacency Matrices: A 2D array where entry \( [i][j] \) indicates the presence of an edge from vertex \( i \) to vertex \( j \).
    • Efficient for dense graphs (graphs with many edges).

Edge Cases

  • How are self-loops represented?
    • In adjacency matrices, self-loops are entries where row and column indices are the same.
  • What if the graph is very large?
    • Adjacency lists are preferred due to space efficiency.

Examples

Example 1: Adjacency List

Graph with \( V = {1, 2, 3} \) and \( E = {(1, 2), (2, 3)} \).

  • Adjacency List:
    • 1: 2
    • 2: 1, 3
    • 3: 2

Example 2: Adjacency Matrix

Same graph represented as an adjacency matrix:

\[ \begin{array}{c|ccc} & 1 & 2 & 3 \ \hline 1 & 0 & 1 & 0 \ 2 & 1 & 0 & 1 \ 3 & 0 & 1 & 0 \ \end{array} \]

  • Explanation: Entry at \( [i][j] \) is 1 if there is an edge between \( i \) and \( j \).

Example 3 (CS-Themed): Flight Connections

Vertices represent airports, edges represent direct flights.

  • Airports: \( V = {\text{JFK}, \text{LAX}, \text{ORD}, \text{DFW}} \)
  • Edges: Direct flights between airports.
  • Adjacency List:
    • JFK: LAX, ORD
    • LAX: JFK, DFW
    • ORD: JFK, DFW
    • DFW: LAX, ORD
  • Adjacency Matrix:

\[ \begin{array}{c|cccc} & \text{JFK} & \text{LAX} & \text{ORD} & \text{DFW} \ \hline \text{JFK} & 0 & 1 & 1 & 0 \ \text{LAX} & 1 & 0 & 0 & 1 \ \text{ORD} & 1 & 0 & 0 & 1 \ \text{DFW} & 0 & 1 & 1 & 0 \ \end{array} \]


7. Graph Data Structures in Practice

Concepts Introduced

  • Edge Lists: A list of all edges in the graph.
    • Each edge is represented as a pair (or tuple) of vertices.
  • Incidence Lists: For each vertex, a list of incident edges.
  • Trade-offs:
    • Space and time efficiency vary based on the graph representation and operations performed.

Edge Cases

  • How to represent parallel edges in edge lists?
    • Include multiple entries for the same pair of vertices.
  • Can incidence lists handle directed edges?
    • Yes. By distinguishing between incoming and outgoing edges.

Examples

Example 1: Edge List

Graph with \( V = {A, B, C} \) and \( E = {(A, B), (B, C), (A, B)} \) (multigraph with parallel edges).

  • Edge List:
    • (A, B)
    • (A, B)
    • (B, C)

Example 2: Incidence List

  • Incidence List:
    • A: Edges (A, B), (A, B)
    • B: Edges (A, B), (A, B), (B, C)
    • C: Edge (B, C)

Example 3 (CS-Themed): Road Networks

Vertices represent cities, edges represent roads.

  • Edge List:
    • (City1, City2, Distance)
    • (City2, City3, Distance)
    • (City1, City2, Distance) (Parallel road with different distance or properties)
  • Incidence List:
    • City1: Edges to City2
    • City2: Edges to City1, City3
    • City3: Edge to City2

8. Paths and Walks

Concepts Introduced

  • Path: A sequence of vertices where each adjacent pair is connected by an edge, and no vertices are repeated.
  • Walk: A sequence of vertices and edges where vertices and edges can repeat.
  • Length of a Path: Number of edges in the path.

Edge Cases

  • Can a path have length zero?
    • Yes. A path from a vertex to itself with no edges.
  • Is every path a walk?
    • Yes. But not every walk is a path.

Examples

Example 1: Simple Path

Graph with \( V = {1, 2, 3, 4} \) and edges connecting sequential vertices.

  • Path from 1 to 4: \( 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \)
  • Length: 3 edges.

Example 2: Walk with Repeats

  • Walk: \( 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 4 \)
  • Vertices Repeated: 2 and 3.
  • Not a Path: Because vertices are repeated.

Example 3 (CS-Themed): File System Navigation

  • Vertices: Directories and files.
  • Edges: Navigating from one directory to another.
  • Path: A unique sequence of directories from root to a file without revisiting directories.
  • Walk: Navigating directories where you might revisit parent directories.

9. Result: Any Walk Contains a Path

Concepts Introduced

  • Simplifying a Walk to a Path: Removing cycles to create a path.
  • Implications: Demonstrates that connectivity can be represented by paths.

Edge Cases

  • What if the walk is a closed loop?
    • Simplifying the walk will result in a cycle or a path between different vertices.
  • Does this apply to infinite graphs?
    • Generally applied to finite walks in finite graphs.

Examples

Example 1: Simplifying a Walk

Given a walk: \( A \rightarrow B \rightarrow C \rightarrow B \rightarrow D \)

  • Repeated Vertex: B
  • Simplify: Remove cycle between B and C.
  • Resulting Path: \( A \rightarrow B \rightarrow D \)

Example 2: Closed Walk

Walk: \( A \rightarrow B \rightarrow C \rightarrow A \)

  • Cycle: Starts and ends at A.
  • Simplification: Cannot create a path without removing edges.
  • Result: A cycle remains.

Example 3 (CS-Themed): Debugging Call Stack

  • Vertices: Functions in a program.
  • Edges: Function calls.
  • Walk: Sequence of function calls, possibly with recursion (repeated functions).
  • Simplify: Remove recursive cycles to understand the sequence of unique function calls (path).

10. Connectedness and Connected Components

Concepts Introduced

  • Connected Graph: A graph where there is a path between every pair of vertices.
  • Disconnected Graph: Not all vertices are connected.
  • Connected Components: Maximal connected subgraphs.
  • Isolated Vertices: Vertices with no edges.

Edge Cases

  • Can a single vertex be a connected component?
    • Yes. If it has no edges connecting it to other vertices.
  • Is an empty graph connected?
    • No. Unless it has only one vertex.

Examples

Example 1: Connected Graph

Graph with vertices \( {1, 2, 3} \) and edges \( {(1, 2), (2, 3)} \).

  • Observation: Paths exist between all pairs.
  • Conclusion: Graph is connected.

Example 2: Disconnected Graph

Graph with vertices \( {A, B, C, D} \) and edges \( {(A, B)} \).

  • Connected Components:
    • Component 1: \( {A, B} \)
    • Component 2: \( {C} \)
    • Component 3: \( {D} \)
  • Observation: No paths between components.

Example 3 (CS-Themed): Network Partitions

  • Vertices: Computers in a network.
  • Edges: Direct communication links.
  • Scenario: Network split due to a failure.
  • Connected Components: Subnetworks where computers can communicate internally but not with other subnets.
  • Implication: Understanding connected components helps in network recovery.

11. Trees

Concepts Introduced

  • Tree: A connected graph with no cycles (acyclic).
  • Properties: Minimal connectivity.

Edge Cases

  • Is a single vertex a tree?
    • Yes. It’s called a trivial tree.
  • Can a tree have cycles?
    • No. By definition, a tree is acyclic.

Examples

Example 1: Simple Tree

Graph with \( V = {A, B, C} \) and edges \( {(A, B), (B, C)} \).

  • Observation: Connected and acyclic.
  • Conclusion: It’s a tree.

Example 2: Star Tree

Graph with central vertex \( C \) connected to all other vertices.

  • Vertices: \( V = {C, V1, V2, V3} \)
  • Edges: \( {(C, V1), (C, V2), (C, V3)} \)
  • Observation: No cycles.
  • Conclusion: It’s a tree.

Example 3 (CS-Themed): File Directory Structure

  • Vertices: Folders and files.
  • Edges: Parent-child relationships.
  • Observation: Hierarchical, connected, and acyclic.
  • Conclusion: File systems are modeled as trees.

12. Properties of Trees

Concepts Introduced

  • Leaf: A vertex of degree one in a tree.
  • Edge and Vertex Relationship: In any tree, \( e = v - 1 \).

Edge Cases

  • Can a tree be disconnected?
    • No. A tree is, by definition, connected.
  • Is the center of a tree always a single vertex?
    • Not necessarily. Some trees have two central vertices.

Examples

Example 1: Leaves in a Tree

Tree with \( V = {1, 2, 3, 4} \) and edges \( {(1, 2), (2, 3), (2, 4)} \).

  • Leaves: Vertices 1, 3, 4 (degree 1).
  • Internal Vertex: Vertex 2 (degree 3).

Example 2: Edge-Vertex Relationship

  • Vertices: \( v = 5 \)
  • Edges: For a tree, \( e = v - 1 = 4 \)
  • Example: Edges connect the vertices without forming cycles.

Example 3 (CS-Themed): Organizational Chart

  • Vertices: Positions in a company.
  • Edges: Reporting lines.
  • Observation: Forms a tree structure.
  • Properties:
    • Leaves represent employees with no subordinates.
    • The root represents the CEO or top-level management.

13. Circuits and Cycles

Concepts Introduced

  • Circuit: A closed walk where the start and end vertices are the same.
  • Cycle: A circuit with no repeated vertices or edges (except the start/end vertex).

Edge Cases

  • Is a self-loop a cycle?
    • Yes, in some definitions. It can be considered a cycle of length one.
  • Can a cycle be of length two?
    • Yes, in graphs with parallel edges. In simple graphs, cycles must be of length at least three.

Examples

Example 1: Simple Cycle

Graph with \( V = {A, B, C} \) and edges \( {(A, B), (B, C), (C, A)} \).

  • Cycle: \( A \rightarrow B \rightarrow C \rightarrow A \)
  • Length: 3 edges.

Example 2: Circuit with Repeated Vertices

Walk: \( A \rightarrow B \rightarrow C \rightarrow B \rightarrow A \)

  • Circuit: Starts and ends at A.
  • Repeated Vertices: B appears twice.
  • Not a Cycle: Because vertices are repeated (other than start/end).

Example 3 (CS-Themed): Deadlock Detection

  • Vertices: Processes.
  • Edges: Resource requests or holdings.
  • Cycle Detection: A cycle in the graph indicates a potential deadlock.
  • Application: Identifying cycles helps in resolving resource allocation issues.

14. Graph Algorithms Applications

Concepts Introduced

  • Social Network Analysis: Modeling relationships using graphs.
  • Web Crawling and Search Engines: Representing the web as a graph of pages and links.
  • Routing and Navigation Systems: Using graphs to model and optimize routes.

Edge Cases

  • How to represent asymmetric relationships?
    • Use directed graphs where edges have direction.
  • What if the network changes over time?
    • Use dynamic graphs that update representations as changes occur.

Examples

Example 1: Social Network Graph

  • Vertices: Users.
  • Edges: Friendships or follows.
  • Applications:
    • Finding communities.
    • Suggesting friends.

Example 2: Web Graph

  • Vertices: Web pages.
  • Edges: Hyperlinks.
  • Applications:
    • PageRank algorithm.
    • Crawling strategies.

Example 3 (CS-Themed): GPS Navigation

  • Vertices: Intersections.
  • Edges: Roads with distances or travel times.
  • Applications:
    • Shortest path algorithms (e.g., Dijkstra’s).
    • Traffic optimization.

15. Properties and Theorems with Proofs

In this section, we present key properties and theorems in graph theory, accompanied by rigorous, step-by-step proofs using mathematical notation.

1. Degree Sum Formula (Handshake Theorem)

Statement

In any undirected graph \( G = (V, E) \), the sum of the degrees of all vertices equals twice the number of edges.

Mathematical Expression:

\[ \sum_{v \in V} \deg(v) = 2|E| \]

Proof

Objective: Prove that \(\sum_{v \in V} \deg(v) = 2|E|\).

Proof:

Consider an undirected graph \( G = (V, E) \).

  1. Definition of Degree:

    • For each vertex \( v \in V \), \(\deg(v)\) is the number of edges incident to \( v \).
    • An edge \( e = {u, v} \in E \) contributes 1 to \(\deg(u)\) and 1 to \(\deg(v)\).
  2. Counting Edge Contributions:

    • Each edge \( e \in E \) connects two vertices.
    • Therefore, each edge contributes exactly 2 to the total degree sum.
  3. Summing over All Edges:

    • The total sum of degrees is:

      \[ \sum_{v \in V} \deg(v) = \sum_{e = {u, v} \in E} [1 \text{ (for } u) + 1 \text{ (for } v)] = 2|E| \]

Conclusion:

The sum of the degrees of all vertices in an undirected graph is twice the number of edges:

\[ \sum_{v \in V} \deg(v) = 2|E| \]


2. Any Walk Contains a Path Between Its Endpoints

Statement

In any graph \( G = (V, E) \), any walk from vertex \( u \) to vertex \( v \) contains a path from \( u \) to \( v \).

Proof

Objective: Given any walk \( W \) from \( u \) to \( v \), show that there exists a path \( P \) from \( u \) to \( v \) contained within \( W \).

Proof:

  1. Definition of Walk:

    • A walk \( W \) is a sequence of vertices:

      \[ W = (w_0, w_1, w_2, \dotsc, w_k) \]

      where \( w_0 = u \), \( w_k = v \), and \( (w_i, w_{i+1}) \in E \) for all \( 0 \leq i < k \).

  2. Constructing the Path:

    • Initialize \( P \) as the sequence of vertices in \( W \).
  3. Removing Cycles:

    • While \( P \) contains repeated vertices, do the following:

      a. Find Repeated Vertex:

      • Find indices \( i \) and \( j \) such that \( i < j \) and \( w_i = w_j \).

      b. Remove the Cycle:

      • Remove the subsequence \( (w_{i+1}, w_{i+2}, \dotsc, w_j) \) from \( P \).
      • The new sequence \( P \) connects \( u \) to \( v \) and is shorter.
    • This process removes cycles (closed loops) from \( P \).

  4. Resulting Path:

    • After all cycles are removed, \( P \) is a sequence of vertices with no repetitions, i.e., a path.

Conclusion:

Any walk from \( u \) to \( v \) contains a path from \( u \) to \( v \).


3. Properties of Trees

Theorem 1: In a Tree, \( |E| = |V| - 1 \)

Statement:

In any tree \( T = (V, E) \), the number of edges is one less than the number of vertices:

\[ |E| = |V| - 1 \]

Proof

Objective: Prove that \( |E| = |V| - 1 \) for any tree.

Proof by Induction on \( |V| \):

Base Case (\( |V| = 1 \)):

  • A tree with one vertex has no edges.
  • Therefore, \( |E| = 0 = 1 - 1 = |V| - 1 \).
  • Base case holds.

Inductive Step:

Assume the theorem holds for all trees with \( n \) vertices (\( |E| = n - 1 \)).

Consider a tree \( T \) with \( n + 1 \) vertices.

  1. Existence of a Leaf:

    • In a tree, there must be at least one leaf (vertex of degree 1).
    • Let \( v \) be a leaf in \( T \).
  2. Forming a Smaller Tree:

    • Remove \( v \) and its incident edge from \( T \), resulting in a smaller tree \( T’ \) with \( n \) vertices.
  3. Applying Induction Hypothesis:

    • By induction, \( |E’| = n - 1 \), where \( |E’| \) is the number of edges in \( T’ \).
  4. Calculating \( |E| \):

    • \( |E| = |E’| + 1 = (n - 1) + 1 = n \)
  5. Verifying the Formula:

    • \( |E| = n = (n + 1) - 1 = |V| - 1 \)

Conclusion:

By induction, the theorem holds for all trees.


Theorem 2: Every Tree Has at Least Two Leaves

Statement:

Every tree \( T = (V, E) \) with \( |V| \geq 2 \) has at least two vertices of degree 1 (leaves).

Proof

Objective: Prove that any tree with \( |V| \geq 2 \) has at least two leaves.

Proof:

  1. Consider the Longest Path in \( T \):

    • Let \( P \) be the longest path in \( T \), with endpoints \( u \) and \( v \).
  2. Degrees of \( u \) and \( v \):

    • Suppose, for contradiction, that \( \deg(u) \geq 2 \).
    • Then there exists an edge \( (u, w) \) not in \( P \).
  3. Contradiction:

    • Adding \( (u, w) \) to \( P \) would create a longer path, contradicting the maximality of \( P \).
  4. Conclusion:

    • Therefore, \( \deg(u) = 1 \).
    • Similarly, \( \deg(v) = 1 \).
    • Thus, \( T \) has at least two leaves.

Conclusion:

Every tree with at least two vertices has at least two leaves.


4. Connectedness Properties

Definition

A graph \( G = (V, E) \) is connected if for every pair of vertices \( u, v \in V \), there exists a path from \( u \) to \( v \).

Properties

  1. Connected Components:

    • A connected component is a maximal set of vertices \( C \subseteq V \) such that for every \( u, v \in C \), there exists a path from \( u \) to \( v \).
  2. Isolated Vertices:

    • A vertex \( v \) with \( \deg(v) = 0 \) is called an isolated vertex.
    • Each isolated vertex forms its own connected component.

Implications:

  • In a connected graph, there is exactly one connected component.
  • Understanding connected components is crucial for analyzing graph connectivity.

5. Using Graphs to Prove Combinatorial Results

Example: Mutual Friends or Strangers in a Group of Six People

Statement:

In any group of six people, there are either three mutual friends or three mutual strangers.

Proof

Objective: Prove the statement using graph theory.

Proof:

  1. Modeling the Problem:

    • Represent each person as a vertex.
    • For every pair of people, draw an edge:
      • Color it red if they are friends.
      • Color it blue if they are strangers.
  2. Applying the Pigeonhole Principle:

    • Select any vertex \( v \).
    • \( v \) has five edges connected to other vertices.
    • By the Pigeonhole Principle, at least three edges must be the same color.
    • Without loss of generality, assume \( v \) has at least three red edges to vertices \( v_1, v_2, v_3 \).
  3. Analyzing Connections Among \( v_1, v_2, v_3 \):

    • If any pair among \( v_1, v_2, v_3 \) is connected by a red edge, say \( (v_1, v_2) \), then \( v, v_1, v_2 \) form a triangle of mutual friends.
    • If none of \( v_1, v_2, v_3 \) are connected by red edges, then all edges between them are blue, and \( v_1, v_2, v_3 \) form a triangle of mutual strangers.

Conclusion:

In any case, there exists a trio of mutual friends or mutual strangers.


6. Additional Properties of Trees

Theorem: Removing Any Edge from a Tree Disconnects It

Statement:

In a tree \( T = (V, E) \), removing any edge results in a disconnected graph.

Proof

Objective: Show that removing any edge \( e \in E \) from \( T \) disconnects \( T \).

Proof:

  1. Properties of Trees:

    • Trees are connected and acyclic.
  2. Contradiction:

    • Suppose removing edge \( e = (u, v) \) does not disconnect \( T \).
    • Then there exists another path between \( u \) and \( v \) in \( T \setminus {e} \).
  3. Cycle Formation:

    • The existence of another path implies a cycle in \( T \), consisting of edge \( e \) and the alternative path between \( u \) and \( v \).
  4. Contradiction:

    • This contradicts the acyclic property of trees.

Conclusion:

Removing any edge from a tree disconnects it.


Summary

  • Graphs are powerful tools for modeling relationships and structures.
  • Understanding the foundational concepts, properties, and representations of graphs is essential for various applications in computer science.
  • Edge cases highlight important considerations and exceptions that deepen comprehension.
  • Examples illustrate concepts in practical and computational contexts.

Practice Problems

  1. Degree Sum Verification:
    • Given an undirected graph with 5 vertices and 7 edges, verify the degree sum formula.
  2. Graph Representation Conversion:
    • Convert the given adjacency list to an adjacency matrix:
      • Adjacency List:
        • A: B, C
        • B: A, D
        • C: A, D
        • D: B, C
  3. Path and Walk Identification:
    • In the following graph, list all possible paths from vertex 1 to vertex 4:
      • Edges: (1,2), (2,3), (3,4), (1,3), (2,4)
  4. Tree Properties:
    • Prove that a tree with 10 vertices has exactly 9 edges.
  5. Cycle Detection:
    • Given a directed graph representing tasks with dependencies, determine if there is a cycle indicating a circular dependency.

Additional Clarifications

Importance of Edge Cases

  • Edge cases help identify limitations and special conditions.
  • Understanding edge cases prevents misconceptions and errors in applications.

Applications in Computer Science

  • Data Structures: Trees, graphs, and their implementations.
  • Algorithms: Graph traversal, shortest paths, network flows.
  • Networking: Modeling and analyzing communication networks.
  • Artificial Intelligence: Graph-based representations in problem-solving.