Selected Reading

Graph Theory - Path and Cycle



Path in Graph Theory

A path in a graph is a sequence of edges that connect a sequence of vertices without revisiting any vertex. It represents a way to travel from one vertex to another, visiting each vertex exactly once along the way.

Before diving into paths and cycles, it is important to define some basic terms −

  • Simple Path: A path in which no vertices (and thus no edges) are repeated, except possibly the first and last vertices in the case of a cycle.
  • Length of a Path: The number of edges in the path.
  • Notation: A path from vertex u to vertex v can be denoted as P(u,v).
  • Walk: A sequence of vertices where each adjacent pair is connected by an edge, allowing vertices and edges to be repeated.
  • Trail: A walk in which no edge is repeated.
  • Circuit: A closed trail, meaning it starts and ends at the same vertex.

Types of Paths

Paths can be classified based on their characteristics and the type of graph −

  • Directed Path: A path in a directed graph where all edges follow the direction of the graph.
  • Directed Path
  • Undirected Path: A path in an undirected graph where edges do not have a direction.
  • Undirected Path
  • Hamiltonian Path: A path that visits each vertex exactly once.
  • Hamiltonian Path
  • Eulerian Path: A path that visits each edge exactly once.
  • Eulerian Path
  • Shortest Path: The path between two vertices that has the smallest number of edges or the smallest total weight.

Properties of Paths

Paths have several important properties that are useful in graph analysis −

  • Connectivity: A graph is connected if there is a path between any pair of vertices.
  • Path Length: The number of edges in a path.
  • Path Weight: The sum of the weights of the edges in a path (in weighted graphs).

Example of a Path

Consider the following undirected graph −

Undirected Path

A path from "a" to "g" can be "a - d - f - g". The length of this path is 3.

Cycle in Graph Theory

A cycle in a graph is a path that starts and ends at the same vertex, with all other vertices in the path being distinct. In other words, a cycle is a closed loop.

Before diving into paths, it is important to define some basic terms −

  • Simple Cycle: A cycle in which no vertices (and thus no edges) are repeated, except for the starting and ending vertex.
  • Length of a Cycle: The number of edges in the cycle.
  • Notation: A cycle involving vertex v can be denoted as C(v).

Types of Cycles

Cycles can be classified based on their characteristics and the type of graph −

  • Directed Cycle: A cycle in a directed graph where all edges follow the direction of the graph.
  • Directed Cycle
  • Undirected Cycle: A cycle in an undirected graph where edges do not have a direction.
  • Undirected Cycle
  • Hamiltonian Cycle: A cycle that visits each vertex exactly once.
  • Hamiltonian Cycle
  • Eulerian Cycle: A cycle that visits each edge exactly once.
  • Eulerian Cycle

Properties of Cycles

Cycles have several important properties that are useful in graph analysis −

  • Cycle Length: The number of edges in a cycle.
  • Cycle Weight: The sum of the weights of the edges in a cycle (in weighted graphs).
  • Cycle Detection: The process of determining whether a graph contains any cycles.
  • Acyclic Graph: A graph with no cycles. A directed acyclic graph (DAG) is particularly important in various applications.

Example of a Cycle

Consider the following undirected graph −

Undirected Graphs

A cycle in this graph can be A - B - C - F - E - D - A. The length of this cycle is 6.

Algorithms for Finding Paths

We can use various algorithms to find paths in a graph −

  • Breadth-First Search (BFS): Used to find the shortest path in an unweighted graph.
  • Depth-First Search (DFS): Used to explore all possible paths in a graph.
  • Dijkstra's Algorithm: Used to find the shortest path in a weighted graph.
  • Bellman-Ford Algorithm: Used to find the shortest path in a graph with negative edge weights.
  • Floyd-Warshall Algorithm: Used to find shortest paths between all pairs of vertices in a graph.

Breadth-First Search (BFS)

In the following example, we use BFS to find the shortest path from vertex A to vertex F in an unweighted graph −

A - B - C
|   |   |
D - E - F

The shortest path from A to F using BFS is A - B - E - F.

Dijkstra's Algorithm

In the following example, we use Dijkstra's algorithm to find the shortest path from vertex A to vertex F in a weighted graph −

Dijkstra's Algorithm

The shortest path from A to F using Dijkstra's algorithm is A - E - F with a total weight of 2.

Algorithms for Detecting Cycles

We can use various algorithms to detect cycles in a graph −

  • Depth-First Search (DFS): Used to detect cycles in both directed and undirected graphs.
  • Union-Find Algorithm: Used to detect cycles in an undirected graph.
  • Kahn's Algorithm: Used to detect cycles in a directed graph (for topological sorting).

Cycle Detection using DFS

In the following example, we use DFS to detect cycles in an undirected graph −

A - B - C
|       |
D - E - F

Using DFS, we can detect that there is a cycle: A - B - C - F - E - D - A.

Applications of Paths and Cycles

Paths and cycles have various applications in different fields −

  • Network Routing: Finding the shortest or most efficient path between nodes in a network.
  • Social Networks: Analyzing connections between individuals.
  • Urban Planning: Designing transportation and logistics networks.
  • Biology: Studying pathways and cycles in biochemical networks.
  • Computer Science: Solving problems related to graph traversal, optimization, and scheduling.
Advertisements