08 Graphs
08 Graphs
08 Graphs
BASIC CONCEPTS
Definition of graph
Undirected graph consists of a set V of vertices (or nodes) and a set E of edges (or arcs) such that each edge e E is associated with an unordered pair of vertices
Directed graph consists of a set V of vertices (or nodes) and a set E of edges (or arcs) such that each edge e E is associated with an ordered pair of vertices
BASIC CONCEPTS
Incidence
an edge e = (v, w) is incident on the vertices v and w, and v and w are incident on e; v and w are adjacent vertices
an edge that is incident on a single vertex a vertex that is not incident on any edge distinct edges that are incident on the same pair of vertices
Loop
Isolated vertex
Parallel edges
BASIC CONCEPTS
Degree of a vertex
the number of edges incident on the vertex a loop on the vertex adds 2 to the degree of v contains neither parallel edges nor loops
simple graph where there is an edge between every pair of distinct vertices denote Kn as a complete graph on n vertices
Simple graph
Complete graph
BASIC CONCEPTS
a b c f e a b c
d
g Undirected graph with a loop and parallel edges
d Directed graph
BASIC CONCEPTS
a b c b a c
d Simple graph
e Complete graph: K5
Path
a path from a vertex v0 to a vertex vn (of length n) is an alternating sequence of n + 1 vertices and n edges starting from v0 and ending with vn.
(v0, e1, v1, e2, v2, . . . , vn-1, en, vn)
has no repeated edges but may have repeated vertices path with no repeated vertices graph with numbers on the edges the length of a path in the graph is the sum of the weights of the edges in the path
Simple path
Weighted graph
Connected graph
given any pair of vertices v and w in the graph, there is a path from v to w path of nonzero length from a vertex v to v has no repeated edges but may have repeated vertices cycle with no repeated vertices (except for the initial vertex cycle that includes all edges and all vertices in a graph
Cycle (Circuit)
Simple cycle
Euler cycle
Theorem
The sum of the degrees of all the vertices in a graph with m edges = 2m. Corollary
Theorem
A graph G has an Euler cycle iff G is connected and every vertex has an even degree. A connected graph has an Euler path (but not an Euler cycle) iff it has exactly 2 vertices of odd degree
Theorem
Hamiltonian cycle
cycle that contains each vertex in the graph exactly once If a graph G is connected, simple, has n 3 vertices and v deg(v) n/2, then G has a Hamiltonian circuit. Given a weighted graph G, find a minimum length Hamiltonian cycle. Euler cycle: O(n) algorithms exist (n-edge graph) Hamiltonian cycle: worst case algorithms require factorial or exponential time
Algorithm complexity
Shortest path
path having a minimum length between two vertices in a weighted graph
Dijkstras algorithm
determines the shortest path from vertex a to z w(i, j) is the weight of edge (i, j) L(x) is the label of a vertex x at termination, L(z) is the minimum length of the path from a to z
Dijkstras algorithm
T = set of all vertices L(a) = 0 for all vertices x a L(x) = while z T choose v T with minimum L(v) T = T v for each x T adjacent to v L(x) = min( L(x), L(v) + w(v, x) )
c
2
z
2
1
d e
1
Answer: a d e z
2
4
c
3 1
e
7 6
T = { b, c, d, e, f, g, h } T = { b, c, d, e, g, h } T = { c, d, e, g, h } T = { c, e, g, h } T = { e, g, h } T = { e, g }
Answer: a b c h
GRAPH COLORING
Graph coloring
Let C = { c1, c2, . . . , cn } be a set of n colors. A coloring of the simple graph G using n colors is a function f: V C. For each vertex v, f(v) is the color of v. A coloring is proper if any two adjacent vertices have different colors. Chromatic number of a graph G
smallest number of colors needed to produce a proper coloring of G Every planar graph is 4-colorable.
Four-color Theorem
GRAPH COLORING
b 2 1 a e g
2 3
c 1
2
chromatic color : 3
graph representation of a map