Rooted Trees – CMPT 225

Graphs

Graph is a pair G=<V,E>, with:

Example in table format:

node connections
1 2,3
2 1
3 1

“G is directed”: edges are ordered pairs (often called arcs)

{{1,2,3},{(1,2),(1,3)}}{{1,2,3},{(2,1),(1,3)}} \langle\{\{1,2,3\},\{(1,2),(1,3)\}\}\rangle \neq \langle\{\{1,2,3\},\{(2,1),(1,3)\}\}\rangle

i.e. graph one:

node connections
1 2,3
2  
3  

does not equal graph two:

node connections
1 3
2 1
3  

“G is undirected” edges are sets

{{1,2,3},{(2,1),(1,3)}}={{1,2,3},{(1,2),(3,1)}} \langle\{\{1,2,3\},\{(2,1),(1,3)\}\}\rangle = \langle\{\{1,2,3\},\{(1,2),(3,1)\}\}\rangle

i.e. graph one:

node connections
1 3,2
2 1
3 1

is equal to graph two:

node connections
1 2,3
2 1
3 1

By default, by “graph” we will mean “undirected graph”.

Path

Path of G of length n is a sequence V0,V1,V2,Vn\langle V_{0},V_{1},V_{2},\dots V_{n}\rangle of vertacies s-t. (V0,V1),(V1,V2),(V2,V3)(V_{0},V_{1}),(V_{1},V_{2}),(V_{2},V_{3})\dots are edges of G.

s-t Path in G: path s,,t\langle s,\dots,t\rangle in G.

Example of a s-t path of length 6 for G: s,d,c,e,f,h,t\langle s,d,c,e,f,h,t\rangle

node connections
a b,s
b a,c
c b,d,e,s
d c,s
e c,f,g
f e,h
g e,h,t
h f,g,t
s a,c,d
t g,h

Vertex t is reachable from s in G if ther is an s-t path in G. G is connected if for every pair u,vVu,v\in V, u is reachable from v.

Transcriber’s note: this is much easier to show with graphics and in fact very hard to show easily without graphics. I did my best, but it should be noted that this is very obvious with a visual graph. It becomes two seperate graphs, in essense. So for convenience, I will be splitting this up into two tables, even though technically it’s one “graph” with two sets of connected nodes.

Connected:

node connections
a b,s
b a,c
c b,d,e,s
d c,s
e c,f,g
f e,h
g e,h,t
h f,g,t
s a,c,d
t g,h

Not connected:

node connections
a b,s
b a,c
c b,d,e,s
d c,s
e c
s a,c,d
node connections
f h
g h,t
h f,g,t
t g,h

Cycles & Trees

Cycle in G: path V0,Vn1,Vn\langle V_{0},\dots V_{n-1},V_{n}\rangle in G where V0=VnV_{0}=V_{n}

Simple path: all vertecies are distinct. Simple Cycle: cycle V0,Vn1,Vn\langle V_{0},\dots V_{n-1},V_{n}\rangle where V0,,Vn1\langle V_{0},\dots,V_{n-1} is a simple path.

Simple cylcle of length 5: (see “connected” graph for confirmation): s,d,c,b,a,s\langle s,d,c,b,a,s\rangle

Cycle of length 7 + repeats: s,d,c,b,f,e,c,s\langle s,d,c,b,f,e,c,s\rangle

node connections
a b,s
b a,c,f
c b,d,e,f,s
d c,s
e c,f,g
f c,e,h,b
g e,h,t
h f,g,t
s a,c,d
t g,h

Tree

Tree: a connected, acyclic graph:

Example 1 (not a tree, due to cycle: s,c,d,s\langle s,c,d,s\rangle):

node connections
a b
b a,c
c b,d,e,s
d c,s
e c,g
f h
g e,h,t
h f,g,t
s c,d
t g,h

Example 2 (a tree, no cycle, all connected):

Now using ARIA trees:

Example 3 (not a tree) (transcriber’s note: written as two trees for simplicity’s sake)

Fact: every tree with nn verticies has n1n-1 edges.

Rooted-tree:

Rooted tree: tree with a distringuished vertex called the root.

Unrooted tree:

Tree T with root:

An alternate drawing of T, with no semantic change.

Notice: in a tree there is a unique path between any two verticies. So: a unique path from any vertex to the root. Thus: the root indicates a direction on the edges e.g. towards the root.

A graph of the same tree, T, with arrows pointing towards the root. There is no reason for having any semantic markup for this.

(sometimes “away from the root”).

Rooted Tree Terminology

Depth & Height

A rooted tree is:

E.g. A ordered trenary tree:

Notice: when we draw a tree, or represent it in a data structure, we order it.

In an ordered binary tree, every child of a node v is either the “left child of v” or the “right child of v”.

Transcriber’s note: nodes’ children are transcribes from left to right. So for a binary tree, the first child is the “left child” and the second child is the “right child”.

Subtree rooted at v

Subtree rooted at v: tree with root v and containing all decendants of v.

In a binary tree:

End