學海無涯,思境無維;數乃六藝,理之始也。
或有一得足矣 愚千慮

Tree

Cycle : A cycle is a circuit whose edge list contains no duplicates. It is customary to use

Cn to denote a cycle with
n
edges.

A Tree contains no cycle or self-loops.

A forest is an undirected graph whose components are all trees.

Conditions for a graph to be a tree

{V:Vertices,|V|=nE:EdgesG=(V,E) with no self-loopsG is a tree.G is connected|E|=n1G is connected, if eE,(V,E{e}) is disconnected.G contains no cycle, by adding a new edge, yout created a new cycle.For two distinct vertices in V, exists a unique simple path between them.

Spanning Tree

G is a connected undirected graph.
A Spanning Tree is the spanning subgraph (remove unrequired edges only) of
G
that is a tree.

Minimal Spanning Tree

G=(V,E,w) is the spanning tree with weight of each edge.
Minimal Spanning Tree
eEw(e)=minimal

Prim's Algorithm

Find the minimal spanning tree of a connected, undirected, weighted graph.

Bridge

G=(V,E) is a connected undirected graph.
{L,R}
is a partition of
V
,
e
is a bridge
eE
is an edge that connect a vertex in
L
and a vertex in
R
.

G=(V,E,w) is a weighted undirected connected graph.
{L,R}
is a partition of
V
, if
e
is the least weighted bridge between
L,R
, then exists a minimal spanning tree of
G
that include
e
.

Prim's Algorithm

  • L=V{v0},R={v0},E=
  • Find the least weighted bridge(
    e=(vL,vR)
    ) between
    L,R
    ,
    E=E+{e}
  • L=L{vL},R=R+{vL}
    , if
    L
    , goto step 2.
  • E
    is the minimal spanning tree of
    G
    .

Minimum Diameter Spanning Tree (MDST)

Given a connected undirected graph

G=(V,E), find a spanning tree
T=(V,E)
of
G
such that the longest path in
T
is as short as possible.

Rooted Trees







%0


A (Root)

A (Root)



B

B



A (Root)--B




C

C



A (Root)--C




D

D



A (Root)--D




E

E



B--E




F

F



B--F




G

G



B--G




H

H



C--H




I

I



C--I




J

J



C--J




K

K



D--K




L

L



K--L




M

M



K--M




  • Basis: A tree with no vertices is a rooted tree (the empty tree).
  • A single vertex with no children is a rooted tree.
  • Recursion: Let
    T1,T2,...,Tr,r1
    , be disjoint rooted trees with roots
    v1,v2,,vr
    respectively, and let
    v0
    be a vertex that does not belong to any of these trees. Then a rooted tree, rooted at
    v0
    , is obtained by making
    v0
    the parent of the vertices
    v1,v2,,vr
    . We call
    T1,T2,,Tr
    subtrees of the larger tree.

Kruskal’s Algorithm

Alternative waty to find the minimal spanning tree (MST)

G=(V,E,w),|V|=m,|E|=n

  • sort edge list by weight. lighter first.
  • pick the the edge in the edge list in order and that won't cause the cycle into the set
    S
    . (this approach makes sure lighter edge get picked first)
  • until
    |S|=m1
    or the end of the edge list(
    G
    is not connected).

Binary Trees

An ordered rooted tree is a rooted tree whose subtrees are put into a definite order and are, themselves, ordered rooted trees. An empty tree and a single vertex with no descendants (no subtrees) are ordered rooted trees.

Two Different Ordered Rooted Trees







%0


1

1



2

2



1--2




3

3



1--3




4

4



1--4










%0


1

1



2

2



1--2




4

4



1--4




3

3



1--3




Binary Tree
(1) A tree consisting of no vertices (the empty tree) is a binary tree
(2) A vertex together with two subtrees that are both binary trees is a binary tree. The subtrees are called the left and right subtrees of the binary tree.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

A vertex of a binary tree with two empty subtrees is called a leaf.
All other vertices are called internal vertices.

A full binary tree is a tree for which each vertex has either zero or two empty subtrees.

Traversals of Binary Trees

  • Preorder Traversal
  • Inorder Traversal
  • Postorder Traversal

Binary Sort Tree Creation

Binary Sort Tree + Inorder Traversal would create a sorted ascending list.

Binary Sort Tree for 25, 17, 9, 20, 33, 13, and 30.







%0


25

25



17

17



25--17




33

33



25--33




9

9



17--9




20

20



17--20




  

  



33--  




30

30



33--30




 

 



9-- 




13

13



9--13




Expression Trees

x=abc/d+e
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Expression Tree removed the parenthese.

  • Prefix form: +ab (Preorder Traversal of the Expression Tree = + -*ab/cde)
  • Infix form: a+b (Inorder Traversal = a*b-c/d+e)
  • Postfix form: ab+ (Postorder Traversal of the Expression Tree = ab*cd/-e+ )

Counting Binary Trees

Let

B(n) be the number of different binary trees of size
n
(
n
vertices),
n0
.
B(0)=1

B(n+1)
=
left subtree with
0
vertex * right subtree with
n
vertices +
left subtree with
1
vertex * right subtree with
n1
vertices +

left subtree with
n
vertices * right subtree with
0
vertex.
B(n+1)=B(0)B(n)+B(1)B(n1)++B(n)B(0)=k=0nB(k)B(nk)

tags: math