Discrete Math Graphs and Tree PDF
Discrete Math Graphs and Tree PDF
Mathematics
5. G r a p h s & Trees
What are Graphs? Not
• General m e a n i n g in e v e r y d a y
A plot or chart of numerical data using a
math:
coordinate system.
• Technical m e a n i n g in d i s c r e t e
m at hem atics:
A particular class of discrete structures (to be
defined) that is useful for representing relations and
has a convenient webby-looking graphical
representation.
• T h e g r a p h in w h i c h e a c h e d g e
c o n n e c t s t w o different vertices a n d
w h e r e n o t w o e d g e s c onn e c t t h e
s a m e pair o f vertices
• C o r r e s p o n d to s y m m e t r i c binary
relations R.
• Definition:
A multigraph G=(V, E, f ) c o n s i s t s o f a s e t V o f
vertices, a s e t E
f:E{{u,v}|u,vV o f e d g e s ( a s primitive objects),Parallel
uv}.
a n d a function edges
• Example:
n o d e s are cities a n d
e d g e s are s e g m e n t s o f major
highways.
Discrete Math ematics, Sp r in g
2009
Pseudographs
• Like a multigraph, bu t e d g e s
c onn e ct i ng a n o d e to itself are
a l l owe d.
• Definition:
A pseudograph G=(V, E, f ) w h e r e
f:E{{u,v}|u,vV}. E d g e eE is loop
a loop if f(e)={u,u}={u}.
• Example:
n o d e s are c a m p s i t e s
in a state p a r k a n d e d g e s
are hiking trails t h r o u g h t h e
woods.
Discrete Math ematics, Sp r in g
2009
Directed Graphs
• C o r r e s p o n d to arbitrary binary
relations R, w h i c h n e e d not b e
symmetric.
• Definition:
A directed graph (V, E) c o n s i s t s o f a s e t o f
vertices
V a n d a binary relation E o n V.
• Example:
V = p e o p l e , E={(x,y) | x l o v e s y}
• Example:
− The W W W is a directed multigraph.
− V=web p a g e s , E=hyperlinks.
Le t G b e an u nd ire c te d g r a p h w ith e d g e s e t
E.
Le t
eE b e (or m a p to) t h e pair {u,v}. Then
w e sa y:
• u, v are adjacent / neighbors / connected.
• E d g e e is incident with vertices u a n d v.
• E d g e e connects u a n d v.
• Vertices u a n d v are endpoints o f e d g e e.
• N o t e that t h e d e g r e e o f a n o d e is
u n c h a n g e d b y w h e t h e r w e c o n s i d e r its
e d g e s to b e d i r e c t e d or undirected.
Speci al c a s e s o f u n d i r e c t e d g r a p h
structures:
• C o m p l e t e G r a p h s Kn
• C y c l e s Cn
• W h e e l s Wn
• n- Cube s Q n
• Bipartite G r a p h s
• C o m p l e t e Bipartite G r a p h s Km,n
• Definition:
− For a n y nN, a complete graph o n n vertices,
Kn, is a s i m p l e g r a p h wi t h n n o d e s in
w h i c h e v e r y n o d e is adjacent to e v e r y
o t h e r n o d e : u,vV: uv{u,v}E.
K1 K2 K3 K4 K5 K6
n1
n(n 1)
Note that K n
has
i1
i
2
edges.
∑
Discrete Math ematics, Sp r in g
2009
Cycles
• Definition:
− For a n y n3, a cycle o n n vertices, Cn, is a
s i m p l e g r a p h w h e r e V={v1,v2,… ,v n } a n d
E={{v1 ,v2 },{v2 ,v3 },…,{vn1 ,vn },{vn ,v1 }}.
C3 C4 C8
C5 C6
C7
• Definition:
− For a n y n3, a wheel W n , is a s i m p l e g r a p h
o b t ai n ed b y taking t h e c y c l e Cn a n d a d d i n g o n e
extra vertex v h u b a n d n extra e d g e s {{v h u b ,v 1 },
{v h u b ,v 2 },…,{v h u b ,v n }}.
W3 W4 W5 W6 W7 W8
Q0 Q1 Q2 Q3 Q4
Number of vertices: 2n. Number of edges:Exercise to try!
Discrete Math ematics, Sp r in g
2009
n-Cubes (hypercubes)
• Definition:
For a n y nN, t h e h y p e r c u b e Q n can b e
d e f i n e d recu rsi v el y a s follows:
• Q 0 =({v 0 },) ( o n e n o d e a n d n o e d g e s )
• For a n y nN, if Qn=(V,E), w h e r e V={v1,…,va}
E={e
a n d 1 ,…,eb }, th e n Q {v1 ´,…,v
E{en+1
=(V 1 ´,…,e {{v1 ,v1 ´},{v ´}, 2 ´},
2 ,v
a
V1 V2
a bipartite
• Definition:
Let m, n b e p o si t i v e integers. T h e complete
bipartite graph Km,n is t h e g r a p h w h o s e
vertices can b e partitioned V = V1 ∪ V2
s u c h that
1. |V1| = m
2. |V2| = n
3. For all x ∈ V1 a n d for all y ∈ V2 , t h e r e is
an e d g e b e t w e e n x a n d y
4. N o e d g e h a s b o t h its e n d p o i n t s in V1 or
b o t h its e n d p o i n t s in V2
V1 V2
K2,3
V1
V2
K3,4
G H
a b a. b, c
Vertex
b. a, c, e, f
c d Adjacent
c.a, b, Vertices
f d
e
f e. b
f. c, b
• Simple graph
represent ation
Discrete Math ematics, Sp r in g
2009
Adjacency Matrices
• Matrix M=[m ij ], w h e r e
− mij = 1w h e n e d g e ej is incident wi t h vi,
− mij = 0o t h e r w i s e .
• A w a y of represent graphs
− can b e u s e d to r e p r e s e n t multiple
e d g e s and loops
• Definition:
S i m p l e g r a p h s G1=(V1, E 1 ) a n d G2=(V2, E 2 ) are
isomorphic iff a bijection f:V1V2 s u c h that
a,bV1, a a n d b are adjacent in G1 iff f(a) a n d f(b)
are adjacent in G2.
• Gr a ph Invariant
−a property preserved by isomorphism of
graphs
− Necessary b u t not sufficient conditions for
G1=(V1, E 1 ) to b e i s o m o r p h i c to G2=(V2, E 2 ):
• |V1|=|V2|, |E1|=|E2|.
• T h e n u m b e r o f v er tices w i t h d e g r e e n is t h e
s a m e in b o t h g r a p h s .
• For e v e r y p r o p e r s u b g r a p h g o f o n e g r a p h ,
t h e r e is a p r o p e r s u b g r a p h o f t h e o th e r
g r a p h that is i s o m o r p h i c to g.
a * Same # of vertices
b
* Same # of edges
d * Different # of verts of
degree 2! (1 vs 3)
c e
• Definition:
A path of length n f r o m u to v in G is
a s e q u e n c e o f n e d g e s e1, e2, … , en s u c h that e1 is
a s s o c i a t e d wi t h {x0 , x1 }, e2 is a s s o c i a t e d wi t h {x1 ,
x2 }, a n d s o on, wi t h en a s s o c i a t e d wi t h {xn-1 ,xn },
w h e r e x0=u a n d xn=v;
• T h e p a t h is circuit if it b e g i n s a n d e n d s at t h e
s a m e vertex, that is u=v, a n d h a s l e n g t h
great er than zero.
• A p a t h or circuit is simple if it d o e s not
contain t h e s a m eDiscrete
e dMath
g eematics,
m oSprr ineg than once.
2009
Connectedness
• Definition:
− An u n d i r e c t e d g r a p h is connected iff t h e r e is a
p a t h b e t w e e n e v e r y pair o f distinct vertices
in t h e g r a p h .
• Theorem:
− T h e r e is a simple p a t h b e t w e e n a n y pair o f
vertices in a c o n n e c t e d u n d i r e c t e d g r a p h .
d c c d e
a, e, c, d, e, b, a a, c, d, e, b, d, a, b
Euler circuit Euler path
Discrete Math ematics, Sp r in g
2009
Euler & Hamilton Paths (cont.)
• Definition:
− A Hamilton circuit is a s i m p l e circuit that
t r a v e r s e s e a c h v er tex in G ex actly o n ce.
− A Hamilton path is a s i m p l e p a t h that t r a v e r s e s
e a c h v er tex in G ex actly o n ce.
• Examples:
a b a b
e c
d c
d
a, b, c, d, e, a a, b, c, d
Hamilton circuit Hamilton path
• Theorem:
− A n u n d i r e c t e d g r a p h is a tree if a n d o n l y if t h e r e is
a
unique simple path b e t w e e n a n y t w o o f its vertices.
• In general, w e u s e t r e e s to r e p r e s e n t hierarchical
structures. Discrete Math ematics, Sp r in g
2009
Trees
Example: Ar e t h e f ol l owi ng g r a p h s
trees?
No. Yes
.
Yes No.
.
Discrete Math ematics, Sp r in g
2009
Root & Rooted
tree
• We often d e s i g n a t e a particular vertex o f
a tree a s t h e root. Since t h e r e is a u n i q u e
p a t h f r o m t h e root to e a c h vertex o f t h e
g r a p h , w e direct e a c h e d g e a w a y f r o m
t h e root.
• Definition:
A rooted tree is a tree in w h i c h o n e vertex h a s
b e e n d e s i g n a t e d a s t h e root a n d e v e r y e d g e
is d i r e c t e d a w a y f r o m t h e root
Christine Bob
bin spool ls
+ -
y z x y
• This tree r e p r e s e n t s t h e e x p r e s s i o n ( y +
z)(x - y).
Discrete Math ematics, Sp r in g
2009
m-ary tree
• Definition:
− A r o o t e d tree is called an m-ary tree if e v e r y
internal vertex h a s n o m o r e than m children.
− T h e tree is called a full m-ary tree if e v e r y
internal vertex h a s exactly m children.
− An m-ary tree wi t h m = 2 is called a binary
tree.
• Theorem:
− A tree wi t h n vertices h a s (n – 1) e d g e s .
− A full m-ary tree wi t h i internal vertices
contains n = Discrete Math ematics, Sp r in g
2009
m·i + 1 vertices.
Ordered Rooted Tree
• Definition:
− An ordered rooted tree is a r o o t e d tree
w h e r e t h e children o f e a c h internal vertex
are o r d e r e d .
d e f g
h i j Right subtree of
the Vertex b
k l
Discrete Math ematics, Sp r in g
2009
Tree Traversal
• P r o c e d u r e s for syst e m a t i c al l y visiting
e v e r y vertex o f an o r d e r e d r o o t e d
tree are called traversal algorithms.
b c d
g
• Preorder : a, b, e, j, k, n,
e
f o, p, f, c, d, g, l, m, h, I
h i
• Inorder : j, e, n, k, o, p,
k l
j m b, f, a, c, l, g, m, d, h, i
• Postorder : j, n, o, p, k, e,
n o p f, b, c, l, m, g, h, i, d, a