Professional Documents
Culture Documents
4
Example
Social network
5
Basic Terminology
The degree of a vertex in an undirected graph
is the number of edges incident with it, except
that a loop at a vertex contributes twice to the
degree of that vertex.
6
Handshaking Theorem
Let G = (V, E) be an undirected graph with e
edges. Then
2e deg v
vV
deg v 6 10 60
vV
2e 60
e 30
7
Basic Terminology
A subgraph of a graph G = (V, E) is a graph H
= (W, F), where W V and F E . A subgraph
H of G is a proper subgraph of G if H G.
G subgraph of G
8
Basic Terminology
The union of two simple graphs G1 = (V1, E1)
and G2 = ( V2, E2) is the simple graph with
vertex set V1 U V2 and edge set E1 U E2 .
9
Paths
A path is a sequence of edges that begins at a
vertex of a graph and travels from vertex to
vertex along edges of the graph.
Is a, d, c, f, e a path?
YES. {a , d}, {d, c} , {c, f}, and {f, e} are all edges
10
Paths
A path is a sequence of edges that begins at a
vertex of a graph and travels from vertex to
vertex along edges of the graph.
Is
. a, d, e, c, f a path?
NO. because {e, c} is not an edge
11
Königsberg Problem
Find a
walk
through
the city
that
would
cross
each
bridge
once and
only once
12
Euler Circuit and Paths
Euler circuit in a graph G is a simple circuit
containing every edge of G. An Euler path in
G is a simple path containing every edge of G .
13
Drill
Which of the undirected graphs have an Euler
circuit? Of those that do not, which have an
Euler path?
15
Euler Circuit and Paths
A connected multigraph has an Euler path but
not an Euler circuit if and only if it has exactly
two vertices of odd degree.
17
Hamilton Paths and Circuits
A simple path in a graph G that passes
through every vertex exactly once is called a
Hamilton path, and a simple circuit in a graph
G that passes through every vertex exactly
once is called a Hamilton circuit.
18
Example
Hamilton Path or Circuit?
a b
d c
19
Example
Hamilton Path or Circuit?
a b
d c
20
Drill
Which of the simple graphs have a Hamilton
circuit or, if not, a Hamilton path?
ai,j {
1 if (vi ,v j ) is an edge
0
22
Example
Use an adjacency matrix to represent the
following graph.
23
Isomorphism of Graphs
Simple graphs G1 = (V1, E1) & G2 = (V2, E2)
are isomorphic if there is a one-to-one and
onto function f from V1 to V2 with the property
that a and b are adjacent in G1 if and only if
f(a) and f(b) are adjacent in G2 , for all a and b
in V1 .
24
Visualization
Twist or bend
25
Example
The function f with f(u1) = V1, f(u2) = V4 , f(u3)
= V3 , and f(u4) = V2 is a one-to-one
correspondence between V and W.
Adjacent vertices in G are u1 and u2 , u1 and
u3, u2 and u4, and u3 and u4, and each of the
pairs f(u1) = V1 and f(u2) = V4, f(u1) = V1 and
f(u3) = V3 , f(u2) = V4 and f(u4) = V2 , and
f(u3) = V3 and f(u4) = V2 are adjacent in H.
26
Dijkstra’s Algorithm Definitions
• Find shortest paths from given source node to all other nodes,
by developing paths in order of increasing path length
N= set of nodes in the network
s= source node
T= set of nodes so far incorporated by the algorithm
• w(i, j) = link cost from node i to node j
– w(i, i) = 0
– w(i, j) = if the two nodes are not directly connected
– w(i, j) 0 if the two nodes are directly connected
• L(n) = cost of least-cost path from node s to node n currently
known
– At termination, L(n) is cost of least-cost path from s to n
Dijkstra’s Algorithm Method
• Step 1 [Initialization]
– T = {s} Set of nodes so far incorporated consists of only
source node
– L(n) = w(s, n) for n ≠ s
– Initial path costs to neighboring nodes are simply link
costs
• Step 2 [Get Next Node]
– Find neighboring node not in T with least-cost path
from s
– Incorporate node into T
– Also incorporate the edge that is incident on that node
and a node in T that contributes to the path
Dijkstra’s Algorithm Method
• Step 3 [Update Least-Cost Paths]
– L(n) = min[L(n), L(x) + w(x, n)] for all n T
– If latter term is minimum, path from s to n is path
from s to x concatenated with edge from x to n
36
Example
• Are the following graphs planar?
37
Drill
• Is the following graph planar?
38
Drill
• Is the following graph planar?
39
Drill
• Is the following graph planar?
40
Drill
• Is the following graph planar?
41
Drill
• Is the following graph planar?
42
Drill
• Is the following graph planar?
43
Drill
• Is the following graph planar?
44
Drill
• Is the following graph planar?
45
Drill
• Is the following graph planar?
YES
46
Example
• Is the following graph planar?
47
Example
• Is the following graph planar?
48
Euler's Formula
• Let G be a connected planar simple graph
with e edges and v vertices. Let r be the
number of regions in a planar
representation of G . Then
r=e-v+2
• A planar representation of a graph splits the
plane into regions, including an unbounded
region.
49
Example
• Suppose that a connected planar simple graph
has 20 vertices, each of degree 3 . Into how
many regions does a representation of this
planar graph split the plane?
r=e-v+2
2e deg v
vV r=e-v+2
2e 3 20 = 30 – 20 + 2
= 12
e 30
50
Homeomorphic Graphs
• Elementary subdivision - If a graph is planar, so
will be any graph obtained by removing an
edge { u, v} and adding a new vertex w
together with edges { u, w } and {w, v} .
• The graphs G1= ( V1, E1 ) and G2 = ( V2 , E2) are
called homeomorphic if they can be obtained
from the same graph by a sequence of
elementary subdivisions.
51
Example
• Show that the graphs G1, and G2 are
homeomorphic.
52
Kuratowski's Theorem
• A graph is nonplanar if and only if it contains a
subgraph homeomorphic to the following
graphs.
53
Example
• Determine whether graph G is planar.
54
Example
• Is the Petersen graph shown below planar?
55
Graph Coloring
56
Colored Graphs
• A coloring of a simple graph is the assignment of
a color to each vertex of the graph so that no two
adjacent vertices are assigned the same color.
• The chromatic number of a graph c(G) is the least
number of colors needed for a coloring of this
graph.
• The best algorithms known for finding the
chromatic number of a graph have exponential
worst-case time complexity
57
FOUR COLOR THEOREM
• The chromatic number of a planar graph is no
greater than four.
• Note that the Four Color Theorem applies only to planar graphs.
Nonplanar graphs can have arbitrarily large chromatic numbers.
58
Graph Coloring
59
Example
• What is the chromatic numbers of the graphs
G?
c(G) = 3
60
Example
• What is the chromatic numbers of the graphs
H?
c(G) = 4
61
Trees
• A tree is a connected undirected graph with
no simple circuits.
• It is a data structure that emulates a
hierarchical tree structure with a set of
linked nodes.
62
Why study Trees?
• used to construct efficient algorithms for
locating items in a list (binary search trees…)
• used in algorithms, such as Huffman coding,
that construct efficient codes saving costs in
data transmission and storage
• used to study games such as checkers and chess
and can help determine winning strategies for
playing these games
• used to model procedures carried out using a
sequence of decisions
• etc.
63
Example
• Which of the graphs shown below are trees?
G1 G2 G3 G4
64
Example
• Which of the graphs shown below are trees?
65
Rooted Tree
• Rooted Tree - a tree in which one vertex has
been designated as the root and every edge is
directed away from the root.
66
Example
• In the rooted tree T
(with root a) shown
below, find the parent
of c, the children of g,
the siblings of h , all
ancestors of e, all
descendants of b, all
internal vertices, and
all leaves.
• What is the subtree
rooted at g?
67
Example
• In the rooted tree T (with root a) shown below,
find the parent of c, the children of g, the
siblings of h , all ancestors of e, all descendants
of b, all internal vertices, and all leaves.
• The parent of c is b.
• The children of g are h, i, and j.
• The siblings of h are i and j.
• The ancestors of e are c, b, and a.
• The descendants o f b are c, d, and e.
• The internal vertices are a, b, c, g, h, and j.
• The leaves are d, e, f, i , k, I, and m.
68
Example
• What is the subtree rooted at g?
69
m-ary tree
• A rooted tree is called an m-ary tree if every
internal vertex has no more than m children.
The tree is called a full m-ary tree if every
internal vertex has exactly m children.
• An m –ary tree with m = 2 is called a binary
tree.
70
Ordered rooted tree
• Ordered rooted tree - a rooted tree where the
children of each internal vertex are ordered.
• Ex. What are the left and right children of d in
the binary tree T shown below (where the
order is that implied by the drawing)? What
are the left and right subtrees of c?
LEFT RIGHT
71
Applications
• Trees as models (Ex. Representing Organizations)
72
Tree Example-Linux Directory
73
\end
74