Lecture from: 06.05.2025 | Video: Homelab
Recap: Long Paths and Color Coding
In the previous lecture, we introduced the Long-Path Problem:
Given an undirected graph and an integer , does contain a simple path of length at least ?
This problem is NP-complete in general. However, for small values of - especially when - the Color Coding technique offers a randomized algorithm that runs in polynomial time.
Color Coding: The High-Level Idea
To detect a long path of length , we:
- Randomly color the vertices of with colors.
- Search for a colorful path of length - that is, a path on vertices with all vertices assigned distinct colors.
- Repeat the random coloring multiple times to increase the probability of success.
Previously, we analyzed the success probability of this strategy and showed that a randomized algorithm can solve Long-Path in
time with high probability. However, we deferred the key question of how to efficiently check whether a given coloring contains a colorful path of length .
Detecting a Colorful Path Efficiently
Problem Statement
Given:
- A graph ,
- A coloring ,
Determine whether contains a simple path on vertices (length ) such that the vertices along the path have distinct colors - i.e., a colorful path using all colors.
Suppose someone hands you a graph where each vertex is already colored. Can you find a path of length where every vertex has a different color? We’ll solve this by carefully tracking all possible ways to build such a path - starting small and growing it one vertex at a time.
Dynamic Programming Approach
DP State
For each vertex and integer , define:
- The set collects all color sets of size that can appear on a colorful path of length ending at vertex .
- The color must be in each such set .
records all the sets of colors that appear on colorful paths of length ending at vertex .
Example
Suppose a vertex has color 5. If there exists a path of length 2 ending at , say , where the colors are , then .
Base Case (Path Length 0)
For each vertex :
This corresponds to a trivial path of length 0 (just the vertex ) using only its own color.
At the beginning, each vertex can only form a trivial path with its own color.
Recurrence (Path Length )
To compute for , we try to extend shorter colorful paths by one edge:
- Look at every neighbor of
- For every color set
- If , we can extend that path by adding
We add the new color set to .
Recurrence Formula:
This just says: if you can reach neighbor with a colorful path, and brings a new color, then we can grow the path by attaching to it.
Final Check: Did We Find a Colorful Path?
After filling in all up to , we scan all vertices :
- If any contains a color set of size , then we found a colorful path of length .
Formally:
If even one vertex has a complete set of colors in its , we win!
Final Algorithm
Algorithm BUNT(G, γ, k):
// Initialization
for each v in V:
P_0(v) ← { {γ(v)} }
// Iterative DP for path lengths 1 to k-1
for i from 1 to k-1:
for each v in V:
P_i(v) ← ∅
for each neighbor x of v:
for each R in P_{i-1}(x):
if γ(v) not in R:
add R ∪ {γ(v)} to P_i(v)
// Check for colorful path
for each v in V:
for each S in P_{k-1}(v):
if |S| == k:
return YES // found colorful path of length k-1
return NO
Runtime Analysis
Let’s unpack how much time the dynamic programming algorithm actually takes.
How Much Work Are We Doing?
- For each vertex , and each path length , the DP state stores subsets of of size .
- There are at most such subsets - since we’re choosing colors from .
Think of as storing all the colorful combinations of length- paths ending at . The number of such color combinations is limited by how many size- subsets of exist.
How Do We Update the DP Table?
For every edge :
- We look at each color set .
- If , we compute .
Each such operation takes time - because these sets have at most elements.
We go through each neighbor and try to extend their colorful paths by one step - checking and merging color sets.
Cost Per Iteration (Fixed )
At step , the number of operations is roughly:
Each edge might lead to sets, and each set takes time to process.
Total Runtime (All from 1 to )
Summing across all iterations:
This total bound comes from summing over all possible path lengths. The part gives , because it covers all subsets of size at least 1.
Derandomization
Our algorithm relies on random colorings - but what if we want to make it deterministic?
We can construct a special family of colorings:
- A family of colorings
- For every subset of size , some coloring in gives all elements of different colors.
These are called -perfect hash families.
- We can build such a family with size .
- Run the DP algorithm for each coloring in the family to make the method deterministic.
We will not prove the derandomization here, but it shows that the entire approach can be made deterministic with only a modest increase in runtime.
Summary
So to summarize, we built an efficient dynamic programming method that detects colorful paths in time: . When combined with a random coloring, it gives a Monte Carlo algorithm - fast and correct with high probability.
What Is a Flow Network?
We now turn to a central topic in graph theory and combinatorial optimization: Flows in Networks. This topic is not only mathematically rich but also foundational in applications such as logistics, communication systems, traffic routing, and project scheduling.
A network is a directed graph equipped with a notion of flow capacity and distinguished source and sink nodes. Formally:
Definition: A network is a tuple where:
- is a directed graph (digraph), with:
- : set of nodes (vertices)
- : set of directed edge (aka “arc”)
- is the capacity function, assigning a non-negative real number to each directed edge , representing the maximum flow allowed on that directed edge.
- is the source node, the starting point of flow.
- , with , is the sink node, the destination of flow.
What Is a Flow?
Given a network , a flow is a function that satisfies the following conditions:
-
Capacity Constraint (Feasibility): For every directed edge , the flow must respect the capacity:
-
Flow Conservation (Kirchhoff’s Law): For every interior node , the total incoming flow equals the total outgoing flow:
This ensures that no flow is lost or created at any intermediate node - it merely passes through.
Value of a Flow
The value of a flow quantifies how much flow is sent from the source to the sink.
The value of a flow , denoted , is defined as the net outflow from the source:
In most cases, especially in standard formulations, there are no incoming edge to the source, so this simplifies to:
Example Calculation:
Suppose from the source we have:
- and one directed edge with reverse flow:
Then:
Integer Flows
In many practical cases, the capacity function assigns integer values to edges. This leads to an important special case:
A flow is called integer-valued (or integral) if:
Such flows are particularly relevant when dealing with indivisible units, like packages, vehicles, or data packets.
Net Inflow at the Sink
There is a fundamental symmetry in flow networks: what leaves the source must arrive at the sink.
Lemma: Flow Conservation at the Network Level
The net inflow into the sink equals the value of the flow:
Proof
We start by summing the flow conservation equations for all interior nodes :
Summing over all such :
Now observe:
- Every flow appears once with a + sign for and once with a − sign for , unless or is or .
- So only the source and sink terms remain.
Rewriting:
Hence:
This tells us that in a stable network, the total amount of flow sent from the source equals what is received at the sink.
Looking Ahead: The Maximum Flow Problem
This sets the stage for the central algorithmic question in flow networks:
Find a flow in that maximizes .
We will also uncover deep theoretical results like the Max-Flow Min-Cut Theorem, which links the maximum amount of flow that can be pushed from source to sink with the structure of the network itself.
Imagine drawing a curve through the graph that separates and . Such “cuts” are dual to flows and will guide our understanding of the network’s capacity limitations.
We’ll look at this and other topics in the coming lectures…
Continue here: 21 Flow Networks, Cuts, Max-Flow Min-Cut, Residual Networks, Ford-Fulkerson