Graphs Traversals
Tags: #◇Computer Science #◇CCDSALG #◇Graphs Traversals #◇Conceptual #◇M6
◇Overview
This document covers basic algorithms for searching a graph: Breadth-First Search (BFS) and Depth-First Search (DFS). BFS explores edges out of a vertex systemically layer by layer and produces a breadth-first tree. DFS explores as deeply as possible along each branch before backtracking.
◇Important Formulas
Algorithmic Properties & Complexities:
- Adjacency List Representation: Time complexity is , Auxiliary space is for visited tracking and frontier queue/recursion stack.
- Adjacency Matrix Representation: Time complexity is .
- BFS Shortest Path Property: For unweighted graphs, the breadth-first tree guarantees that for every vertex , the tree path from source to corresponds to a shortest path (minimum number of edges).
- DFS Parenthesis Theorem: For any two vertices and , the intervals and are either completely disjoint or one is strictly contained within the other.
◇Theoretical Framework: BFS vs. DFS Exploration Models
DFS Spanning Forest & Edge Taxonomy
Traversal Execution Pipelines
◇Worked Examples
- BFS Traversal Trace: Starting at vertex in graph with edges .
- Init: , visited = , distances: .
- Dequeue : Enqueue unvisited neighbors . , .
- Dequeue : Enqueue unvisited neighbor . , .
- Dequeue : Enqueue unvisited neighbor . , .
- Dequeue : No unvisited neighbors. . Done.
- DFS Cycle Detection: A back edge encountered during DFS on a directed graph indicates a cycle. If neighbor is already marked
visitedand is currently on the recursion call stack (gray state in 3-color model), a directed cycle is confirmed.
◇References & Navigation
- Related Notes: ◇Graph Traversals