- Graph Theory - Home
- Graph Theory - Introduction
- Graph Theory - History
- Graph Theory - Fundamentals
- Graph Theory - Applications
- Types of Graphs
- Graph Theory - Types of Graphs
- Graph Theory - Simple Graphs
- Graph Theory - Multi-graphs
- Graph Theory - Directed Graphs
- Graph Theory - Weighted Graphs
- Graph Theory - Bipartite Graphs
- Graph Theory - Complete Graphs
- Graph Theory - Subgraphs
- Graph Theory - Trees
- Graph Theory - Forests
- Graph Theory - Planar Graphs
- Graph Theory - Hypergraphs
- Graph Theory - Infinite Graphs
- Graph Theory - Random Graphs
- Graph Representation
- Graph Theory - Graph Representation
- Graph Theory - Adjacency Matrix
- Graph Theory - Adjacency List
- Graph Theory - Incidence Matrix
- Graph Theory - Edge List
- Graph Theory - Compact Representation
- Graph Theory - Incidence Structure
- Graph Theory - Matrix-Tree Theorem
- Graph Properties
- Graph Theory - Basic Properties
- Graph Theory - Coverings
- Graph Theory - Matchings
- Graph Theory - Independent Sets
- Graph Theory - Traversability
- Graph Theory Connectivity
- Graph Theory - Connectivity
- Graph Theory - Vertex Connectivity
- Graph Theory - Edge Connectivity
- Graph Theory - k-Connected Graphs
- Graph Theory - 2-Vertex-Connected Graphs
- Graph Theory - 2-Edge-Connected Graphs
- Graph Theory - Strongly Connected Graphs
- Graph Theory - Weakly Connected Graphs
- Graph Theory - Connectivity in Planar Graphs
- Graph Theory - Connectivity in Dynamic Graphs
- Special Graphs
- Graph Theory - Regular Graphs
- Graph Theory - Complete Bipartite Graphs
- Graph Theory - Chordal Graphs
- Graph Theory - Line Graphs
- Graph Theory - Complement Graphs
- Graph Theory - Graph Products
- Graph Theory - Petersen Graph
- Graph Theory - Cayley Graphs
- Graph Theory - De Bruijn Graphs
- Graph Algorithms
- Graph Theory - Graph Algorithms
- Graph Theory - Breadth-First Search
- Graph Theory - Depth-First Search (DFS)
- Graph Theory - Dijkstra's Algorithm
- Graph Theory - Bellman-Ford Algorithm
- Graph Theory - Floyd-Warshall Algorithm
- Graph Theory - Johnson's Algorithm
- Graph Theory - A* Search Algorithm
- Graph Theory - Kruskal's Algorithm
- Graph Theory - Prim's Algorithm
- Graph Theory - Borůvka's Algorithm
- Graph Theory - Ford-Fulkerson Algorithm
- Graph Theory - Edmonds-Karp Algorithm
- Graph Theory - Push-Relabel Algorithm
- Graph Theory - Dinic's Algorithm
- Graph Theory - Hopcroft-Karp Algorithm
- Graph Theory - Tarjan's Algorithm
- Graph Theory - Kosaraju's Algorithm
- Graph Theory - Karger's Algorithm
- Graph Coloring
- Graph Theory - Coloring
- Graph Theory - Edge Coloring
- Graph Theory - Total Coloring
- Graph Theory - Greedy Coloring
- Graph Theory - Four Color Theorem
- Graph Theory - Coloring Bipartite Graphs
- Graph Theory - List Coloring
- Advanced Topics of Graph Theory
- Graph Theory - Chromatic Number
- Graph Theory - Chromatic Polynomial
- Graph Theory - Graph Labeling
- Graph Theory - Planarity & Kuratowski's Theorem
- Graph Theory - Planarity Testing Algorithms
- Graph Theory - Graph Embedding
- Graph Theory - Graph Minors
- Graph Theory - Isomorphism
- Spectral Graph Theory
- Graph Theory - Graph Laplacians
- Graph Theory - Cheeger's Inequality
- Graph Theory - Graph Clustering
- Graph Theory - Graph Partitioning
- Graph Theory - Tree Decomposition
- Graph Theory - Treewidth
- Graph Theory - Branchwidth
- Graph Theory - Graph Drawings
- Graph Theory - Force-Directed Methods
- Graph Theory - Layered Graph Drawing
- Graph Theory - Orthogonal Graph Drawing
- Graph Theory - Examples
- Computational Complexity of Graph
- Graph Theory - Time Complexity
- Graph Theory - Space Complexity
- Graph Theory - NP-Complete Problems
- Graph Theory - Approximation Algorithms
- Graph Theory - Parallel & Distributed Algorithms
- Graph Theory - Algorithm Optimization
- Graphs in Computer Science
- Graph Theory - Data Structures for Graphs
- Graph Theory - Graph Implementations
- Graph Theory - Graph Databases
- Graph Theory - Query Languages
- Graph Algorithms in Machine Learning
- Graph Neural Networks
- Graph Theory - Link Prediction
- Graph-Based Clustering
- Graph Theory - PageRank Algorithm
- Graph Theory - HITS Algorithm
- Graph Theory - Social Network Analysis
- Graph Theory - Centrality Measures
- Graph Theory - Community Detection
- Graph Theory - Influence Maximization
- Graph Theory - Graph Compression
- Graph Theory Real-World Applications
- Graph Theory - Network Routing
- Graph Theory - Traffic Flow
- Graph Theory - Web Crawling Data Structures
- Graph Theory - Computer Vision
- Graph Theory - Recommendation Systems
- Graph Theory - Biological Networks
- Graph Theory - Social Networks
- Graph Theory - Smart Grids
- Graph Theory - Telecommunications
- Graph Theory - Knowledge Graphs
- Graph Theory - Game Theory
- Graph Theory - Urban Planning
- Graph Theory Useful Resources
- Graph Theory - Quick Guide
- Graph Theory - Useful Resources
- Graph Theory - Discussion
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.
- Undirected Path: A path in an undirected graph where edges do not have a direction.
- Hamiltonian Path: A path that visits each vertex exactly once.
- Eulerian Path: A path that visits each edge exactly once.
- 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 −
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.
- Undirected Cycle: A cycle in an undirected graph where edges do not have a direction.
- Hamiltonian Cycle: A cycle that visits each vertex exactly once.
- Eulerian Cycle: A cycle that visits each edge exactly once.
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 −
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 −
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.