Week 7 Trees
Week 7 Trees
Rooted Tree
→
we can change an un rooted tree into a rooted tree by choosing
vertex as the root
any
→ Two rooted trees are isomorphic if there is a
bijection
between their vertices that
↳ Takes the root to root
to non
↳
edges
to
edges
and non
edges edges
→ if vertices u and connected
u
by an edge and u
are
↳ of u
vertices with same parent are called siblings
→ a childless vertex is called a kat
→
vertices with at least one child are called internal
e-
g level of root is 0
→ The
height of a rooted tree is the man level of its vertices
Subtrees
if every internal
vertex has no more than m children g binary tree
e.
→ a
full binary tree with n internal vertices
contains 2n + 1 vertices in total
↳ internal vertex has 2 children so 2h vertices
every ,
plus root so In + I
→ a
full m -
any
tree with n internal vertices contains
man +1 vertices in total .
Search Trees
Binary
Linearly ordered list
sequence ( list) whose
→ : A
this
↳ searching for data in
binary search tree
data
↳
revising n u n u
search for
→
A
binary tree L and L is
binary
a tree
which every vertex is labelled
in an with item
from L such that :
2)
Every path in the tree is compatible with the order
of listing
e.
9 for the list ( 5,128,3 ,
2
, 15,4 ,
20 ) and linear order
≤
5
/
3 728
2
/ I
15
-
go
How to build a
binary search tree from linearly ordered list
we list L and linear order them
given
→ are a a 4 on .
→ we
go through each member of the list left b- night
,
a
right child
Adding :
[
an
greater on
night
Tree Traversal
→
Rooted trees have traversal algorithms to access or add
data
→
Important traversal algorithms :
HiFi
f g
:
/ elk
j /
in
n Tip I
Preorder traversal
→ visit the root , then continue traversing subtrees in
preorder from left to right
g for tree above a b e , j K, N , O , P , F 9 , I m oh , i
e. : C d
, , , , ,
, ,
In order traversal
→
Begin traversing leftmost subtree in order then visit ,
to
right .
e.
9 For tree above : j ,
e
,
n
,
K ,
O
, P, b
,
f- ,
a
,
c
, 1,9 ,
m
,
d,h i
,
above j N O P K e it b C I m 9 h i d a
g for tree
e. :
, , ,, , , , , , , , , ,
,