Theoretische Informatik II - Lecture 01: Graphen Grundlagen
Recap of Landau Notation and Intervals
Landau Symbols (Big-O Notation): Let f, g : N_{>0} \rightarrow R_{>0}.
Upper Bound (): means grows at most as fast as . Formally: ∃c > 0 ∃n_0 ≥ 0 ∀n ≥ n_0: f(n) ≤ c ⋅ g(n).
Lower Bound (): means grows at least as fast as . Formally: .
Tight Bound (): means grows exactly as fast as . Formally: .
Interval Notation:
For two numbers , define .
Define .
Fundamentals of Undirected Graphs
Definition: An undirected graph is a pair consisting of:
A set of nodes (vertices).
A set of edges.
Conventions:
Unless specified otherwise, graphs are assumed to be undirected by default.
Size notation: Typically, and .
Edge notation: The notation is commonly used for both undirected and directed edges.
Example Setup:
.
.
Fundamentals of Directed Graphs (Digraphs)
Definition: A directed graph (digraph) is a pair consisting of:
A set of nodes (vertices).
A set of edges (sometimes called arcs).
Self-Loops: In directed graphs, loops of the form are typically allowed, unlike in simple undirected graphs.
Example Setup:
.
.
Essential Graph Terminology and Definitions
Adjacency: A node is adjacent (neighboring) to if an edge exists between them (e.g., for undirected graphs).
Neighborhood (): The set of all nodes adjacent to . Formally: .
Degree (): The size of a node's neighborhood. Formally: .
Incidence: An edge is incident to its endpoints and . This is denoted as .
Path (): A sequence of distinct, consecutive adjacent nodes. is a tuple such that:
For all .
For all .
This is called a - path.
Path Length: The number of edges in the path. A path has a length of .
Cycle: A path with an additional edge connecting the last node back to the first node. Formally: where for all and additionally .
Reachability: A node is reachable from if there exists a - path.
Distance (): The length of the shortest path between and . If no path exists, .
Connectivity: A graph is connected if every node is reachable from every other node.
Tree: A connected graph that contains no cycles.
Graph Representation: Adjacency Lists
Structure: Consists of an array of size . Each element is a (doubly) linked list.
Contents: For every node , the list contains all nodes in its neighborhood .
Storage Properties:
Nodes are typically named .
Total number of entries across all lists is for undirected graphs because each edge appears twice (once in each endpoint's list).
The order of nodes within the linked lists is arbitrary.
Graph Representation: Adjacency Matrix
Structure: Consists of a binary matrix .
Values: For all nodes :
if .
otherwise.
Storage Complexity: An adjacency matrix always requires memory space.
Comparison of Graph Representations
Efficiency Criteria:
Adjacency Lists: Superior for sparse graphs where is significantly smaller than . They are highly efficient for iterating through a node's neighbors.
Adjacency Matrix: Superior for dense graphs where approaches . They allow for checking if an edge exists between two specific nodes in constant time ().
Usage: Most algorithms discussed in this course utilize the Adjacency List representation.
Breadth-First Search (BFS)
Objective: Given a graph and a source node , identify all nodes reachable from and determine the shortest distance for every node .
Search Logic: Nodes are visited incrementally by distance from the source (distance 1, then distance 2, etc.).
Mechanism: Use an Discovery Queue ().
Visit the first node in the queue.
Add all previously undiscovered neighbors of that node to the end of the queue.
Algorithm Pseudocode:
Initialize and for all .
Set .
Initialize Queue .
while Q ist nicht leer do:first node in ( is "visited").
Remove from .
for jeden u ∈ N(v) mit d[u] = ∞ do:and .
Append to the end of .
Node States:
White: Undiscovered and unvisited.
Gray: Discovered (currently in the queue) but not yet visited.
Black: Fully visited (all neighbors processed).
Correctness and Guarantees: At the algorithm's conclusion:
For nodes with d[v] < ∞: Node is reachable, , and is the predecessor on a shortest - path.
For nodes with : Node is not reachable from .
Runtime: On an adjacency list representation, BFS has a complexity of .
Each node enters and leaves the queue at most once.
For each node, neighbors are iterated via its adjacency list; thus, each edge is processed at most twice.
Depth-First Search (DFS)
Logic: Instead of exploring the "breadth," the algorithm explores the "depth." It visits an undiscovered neighbor of the most recently visited node. If no such neighbor exists, it uses backtracking to return to the node from which the current node was discovered.
Algorithm Pseudocode:
Initialize for all .
Call
DFS-VISIT(s).function
DFS-VISIT(v):for alle u ∈ N(v) do:if π[u] = NULL ∧ u ≠ s then:.
DFS-VISIT(u).
Mechanism: Implemented via a Recursion Stack.
Runtime: On an adjacency list representation, DFS has a complexity of .
Directed Acyclic Graphs (DAGs) and Topological Sorting
Directed Graph Traversal: Both BFS and DFS work on directed graphs; when visiting a node, only outgoing edges to neighbors are explored.
Directed Acyclic Graph (DAG): A directed graph that contains no cycles.
Topological Sorting: A linear ordering of all nodes such that for every directed edge , it holds that .
Existence and Calculation: A topological ordering exists for every DAG. It can be calculated using Depth-First Search with a runtime of .
Course Roadmap and Key Learning Objectives
Current Goals:
Review basic graph terminology.
Master Breadth-First and Depth-First Search.
Understand Topological Sorting.
Lecture Plan:
Part 1: Graph Algorithms: Graphs (VL 1), Shortest Paths (VL 2), Matching (VL 3), Flows (VL 4), Linear Programming (VL 5).
Part 2: Formal Languages: Automata & Regular Expressions (VL 6), Closure Properties & Myhill-Nerode (VL 7), Pumping Lemma & Grammars (VL 8), Decision Problems & Non-regular Languages (VL 9).
Part 3: Computational Hardness: Complexity Class NP (VL 10), NP-Hardness I & II (VL 11-12), Tractability Limits (VL 13), Approximation & ILP (VL 14).