Graphs Allslides
Graphs Allslides
n(n−1)
A complete graph Kn is a simple graph with all B(n, 2) := 2
possible edges, like the matrices below for n = 2, 3, 4, 5.
Proposition
Every acyclic graph contains at least one node with zero in-degree
Proof By contradiction.
Assume din (v ) > 0 for all nodes, then each node i has a
predecessor p(i) such that (vp(i) , vi ) ∈ E.
Start from an arbitrary v0 to form a list of predecessors as below
Algorithm FindTopOrd(G)
t := 0; G0 := G;
while ∃v ∈ Gt : din (v ) = 0 do
Gt+1 := Gt /{v }; order (v ) := t + 1; t := t + 1;
end while
if t = n then G is acyclic;
else if t < n then G has a cycle; end if
end if
One must find a label numbering that makes the graphs identical
This problem is still believed to be NP hard
Isomorphism
Counting graphs
2n(n−1)/2
Ln := ≤ Tn ≤ 2n(n−1)/2
n!
Exercise Explain the lower bound
n 2 3 4 5 6 7 8
Tn 2 4 11 34 156 1044 12346
dLn e 2 2 3 9 46 417 6658
Isomorphism
Bipartite revisited
A = {v ∈ V |f (v ) = odd} B = {v ∈ V |f (v ) = even}
L = (n + m) log n
0 0 0 0 0 0 1 1 0 0
An initial class has din (c) = 0. A final class has dout (c) = 0.
The other ones are intermediate.
Connectivity
Algorithm GenericSearch(G,s)
mark(s); L := {s}
while L 6= ∅ do
choose u ∈ L;
if ∃(u, v ) such that v is unmarked then
mark(v ); L := L ∪ {v };
else
L := L\{u};
end if
end while
Connectivity
L mark
{2} 2
{2, 1} 1
{2, 1, 5} 5
{2, 1, 5, 6} 6
{1, 5, 6}
{1, 5, 6, 4} 4
{5, 6, 4}
{5, 4}
{5, 4, 3} 3
{5, 3}
{5, 3, 7} 7
{5, 3}
{3}
{3, 8} 8
{3}
{}
L mark
{2} 2
{2, 1} 1
{2, 1, 4} 4
{2, 1, 4, 3} 3
{2, 1, 4, 3, 7} 7
{2, 1, 4, 3}
{2, 1, 4, 3, 8} 8
{2, 1, 4, 3}
{2, 1, 4}
{2, 1, 4, 6} 6
{2, 1, 4, 6, 5} 5
{2, 1, 4, 6}
{2, 1, 4}
{2, 1}
{2}
{}
This algorithm builds longer paths than the generic one (depth
first).
Connectivity
We now use a FIFO list for L (First In First Out) and choose for u
the first element added to L. This is a breadth first search (BFS).
Algorithm BreadthFirstSearch(G,s)
mark(s); L := {s};
while L 6= ∅ do
u := first(L)
if ∃(u, v ) such that v is unmarked then
choose (u, v ) with v of smallest index;
mark(v ); L := L ∪ {v };
else
L := L\{u}
end if
end while
Connectivity
L mark
{2} 2
{2, 1} 1
{2, 1, 5} 5
{1, 5}
{1, 5, 4} 4
{1, 5, 4, 6} 6
{5, 4, 6}
{4, 6}
{4, 6, 3} 3
{6, 3}
{3}
{3, 7}
{3, 7, 8} 8
{7, 8}
{8}
{}
The exploration algorithm finds the set of all nodes that can be
reached by a path from a given node u ∈ V .
If the graph is undirected, each node in that set can follow a path
back to u. They thus form the connected component C(u) of u.
The exploration algorithm finds the set of all nodes that can be
reached by a path from a given node u ∈ V .
How can one find the nodes from which u can be reached ?
Pj
A cost cij = α + β k =i (f (xk ) − g(xk ))2 is associated with each
linear section. This amounts to finding the shortest path in
Shortest path
Other example : Find the best production policy for a plant with a
monthly demand di , a launching cost fi , a storage cost hi and a
unit price pi , for each period i = 1, . . . , n.
In the path below, we are e.g. producing in stages 1, 4 and 5.
A cost is associated with each section. For the path (1,4) it is e.g.
c14 = f1 + p1 (d1 + d2 + d3 ) + h1 (d2 + d3 ) + h2 (d3 ) which is the
fixed cost + the production cost in periods 1, 2 and 3 + storage
costs at the end of periods 1 and 2.
Algorithm Dijkstra(G,u)
S := {u}; d(u) := 0; d(v ) := c(u, v ) ∀v 6= u;
while S 6= V do
choose v 0 ∈
/ S : d(v 0 ) ≤ d(v ) ∀v ∈ / S;
S := S ∪ {v 0 };
for each v ∈ V + (v 0 ) do
d(v ) = min{d(v ), d(v 0 ) + c(v 0 , v )}
end for
end while
Shortest path
Idea : Update a set S for which we know all shortest paths from u
Below, the node u is blue and the explored nodes are red
Shortest path
Let v 0 ∈
/ S : d(v 0 ) = minv ∈S
/ d(v ) then the
shortest path to v 0 must lie completely in S.
If not, ∃v 00 outside S at a shorter distance.
Algorithm ShortestPathBFS(G,v)
mark(v ); S := {v }; d(v ) = 0;
while not S = ∅ do
v := first(S)
if ∃(v , v 0 ) such that v 0 is unmarked then
choose (v , v 0 ) with v 0 of smallest index;
mark(v 0 ); S := S ∪ {v 0 }; d(v 0 ) = d(v ) + 1;
else
S := S\{v }
end if
end while
Shortest path
For an acyclic graph, one can just compute the topological order in
O(m) time (see earlier).
To solve the shortest path problem one then uses the algorithm
Algorithm ShortestPathAcyclic(G,v)
d(1) = 0; d(i) := ∞ for i = 2, . . . , n;
for i = 1 : n − 1 do
for j ∈ V + (i) do
d(j) := minj {d(j), d(i) + c(i, j)};
end for
end for
One can also see the shortest path problem as a flow problem or
as a linear programming problem.
This leads to other algorithms like the Bellman-Ford Algorithm.
Trees
Trees and forests
Proofs ?
Trees
For the external face result, notice that by rotating the sphere, one
can move any point (and hence sector) to the north pole
Planar graphs
Characterisation
Name k l e n f
Tetrahedron 3 3 6 4 4
Cube 3 4 12 8 6
Dodecahedron 3 5 30 20 12
Octahedron 4 3 12 6 8
Icosahedron 5 3 30 12 20
Planar graphs
Test for planar graphs
Two graphs are said to be homeomorphic to each other iff one can
be derived from the other via a sequence of subdivisions.
Example :
the Petersen
graph again
Planar graphs
Proposition (Robertson-Seymour)
For a graph G, determining if a given graph H is a minor of H, can
be solved in polynomial time (with respect to n(G) and m(G)).
But the flow is not maximal, while the next one is (F (N) = 9) as
we will show later. Notice that one edge is not being used (f = 0)
Flows
Cut of a network
(we will construct one and will see it is in fact equal to F (N))
Flows
Applications
Proposition
The flow is optimal if there exists no augmentation path from s to t
Proof Construct a cut (P, P) where u ∈ P if there is an
augmentation path from s to u and u ∈ P otherwise.
Show that (P, P) is a valid cut for which F (N) = κ(P, P).
Thisbecomes an LP problem
in the flows xij on the edges (i, j)
P P P P
max i:(s,i) xsi = i:(i,s) xis subject to i xij = i xji and 0 ≤ xij ≤ cij
Flows
Algorithm MaxFlowFF(N,s,t)
f (u, v ) := 0 ∀(u, v ) ∈ E;
while Nf contains a path from s to t do
choose an augmentation path Ap from s to t
∆ := min(u,v )∈Ap ∆i
Augment the flow by ∆ along Ap
Update Nf
end while
The path problem says if you can draw a graph without lifting your
pen. Apply this to the following examples.
Exercise
Propose a modification addressing the Eulerian Path Problem
The edges have a cost and we need to make the graph Eulerian
Exercise
1. Give a simple lower bound. 2. When can this bound be met ?
3. Is there another solution (or a better one) ?
Euler
Solution : find all odd degree vertices and find the shortest paths
between them
Exercise Construct a graph with d(v ) < n/2 and yet has a
Hamiltonian cycle
Proposition
If G = (V , E) has a Hamiltonian cycle, then G − V 0 has at most
|V 0 | connected components for any subset of vertices V 0 ⊂ V .
Proof Let H be a Hamiltonian subgraph of G, then H − V 0 has
less than |V 0 | connected components. But G − V 0 has the same
vertices as H − V 0 and it has additional edges.
In 1852 it was conjectured that a country map (like the USA map)
could always be colored with only four colors. There is an
underlying assumption for point borders.
This was proven in 1976 by K. Appel and W. Haken but their proof
used a computer search over 1200 so-called critical cases.
Petersen Graph
Even cycle
χ(G) = 3
χ(G) = 2
The table on the left gives the exams each student takes
The chromatic number χ(G) of the corresponding graph
gives the minimum numbers of time slots for the exams
Proposition q
1 1
Let G be connected and m = |E|, then χ(G) ≤ 2 + 2m + 4
Proof Let C = {C1 , . . . , Ck } be the partition of V according to
colors. There is at least one edge between two colors, which
implies m > B(k , 2) and hence k 2 − k − 2m ≤ 0.
Proposition
Let ∆(G) = max{d(v )|v ∈ V }, then χ(G) ≤ ∆(G) + 1 (trivial)
Proposition
χ(G) ≤ 1 + maxi {min(di , i − 1)} when ordering d1 ≥ . . . ≥ dn .
Proof Order the nodes like the di ’s and use the greedy algorithm
Coloring
Greedy algorithm
Algorithm GreedyColor(G)
L := sort(V ); c := sort(colors)
for v ∈ V do
choose smallest ci not used by colored neigbors
end for
On a bipartite graph this greedy algorithm is optimal when
numbering the nodes per part but it can be bad for other
numberings, such as {u1 , v1 , u2 , v2 , u3 , v3 , u4 , v4 }
Exercise
Does each graph have a good numbering for the greedy algorithm
Coloring
Show that e ≤ 3n − 6
Show then that for planar graphs average(d(v )) ≤ 6 − 12/n
Finally prove that there exists a v such that d(v ) ≤ 5
Now use induction to prove the proposition (remove nodes)
Coloring
Chromatic polynomial (Birkhoff-Lewis 1918)
Such sets can clearly be colored with only one color, which proves