Overview
Given an undirected graph and a non-negative integer , the Long-Path problem asks: Does there exist a path in of length exactly ?
Definitions
- A path is a sequence of vertices with no repetitions.
- A path of length contains distinct vertices.
NOTE
The Long-Path problem is NP-complete. It is closely related to the Hamiltonian Path and Hamiltonian Cycle problems. If we can solve the Long-Path problem in for graph with nodes, then we can solve the Hamiltonian Path problem in
Futhermore:
Long Path - Hamiltonian Cycle Proof
Link to original
NOTE
By brute force we can solve the Long-Path problem in Goal: under where is a constant
Randomized Approach: Color Coding
Key Idea
We randomly color the graph and search for a colorful path — a path where all vertices have distinct colors.
Let . We seek a path of length , using colors.
For and define
Goal: Compute all sets for every and every Example:
Colorful Path
Link to original
(color of ) for there is:
Therefore:
Computation of for all , given for all
- for all do
- for all do
- for all with do
- for all with do
Run Time
This algorithm checks for the existence of a colorful path of length in time
where
Probability That a Path Is Colorful
Suppose the graph contains a path of length .
Randomly color each vertex independently with a color in .
There are possible colorings of the vertices on .
Exactly of them assign distinct colors to all vertices on , i.e., make colorful.
So,
Using Stirling’s approximation:
we get
Therefore, a lower bound is
This means the chance of a particular path becoming colorful under a random coloring is at least .
Summary
Theorem
Let be a graph containing a path of length .
- A random coloring with colors produces a colorful path of length with probability
- For repeated colorings with colors, the expected number of trials until a colorful path of length is obtained is
(See Geometric distribution)
Monte Carlo Algorithm for Long-Path
Let .
Repeat the following times:
- Randomly color the vertices of using colors.
- Check whether the graph contains a colorful path of length .
- If such a path is found, return YES.
If no colorful path is found in any iteration, return NO.
Correctness
If the algorithm returns YES, the graph indeed contains a path of length (because colorful paths are simple paths by definition).
If the graph contains a path of length , then with probability at least , one random coloring will make some such path colorful.
The probability that none of the trials succeeds is:
using the inequality
So the error probability is at most .
This is a Monte Carlo algorithm:
it may return NO incorrectly with small probability, but never returns YES incorrectly.
Run Time
Thus, the total runtime becomes:
This is polynomial in when , i.e., when .