$ '
E = V − ½ %& 'V %E
( )* 'E )* +,
= ¼ -. !/ n = ½ E = k − ½ V = k
+" +012
+DZ" 45
V = k + ½ c
$
(free tree
+DZ" 67
% &
n − ½ n !" #$ %
c
$ '
$
8.7 -9 -.:;- /9 :
:< # =5 > -? - %& > -@ A BC •
DE@F= =5 )*
•
r
r½
T½
c
r¾
rk
T¾
Tk
% &
c
%
$ '
$
a
c
b
!/*- G d
-@ e
T
*HI rk *
r½
-@ & rk *
f
g
h
j
c
i
k
l
: :
T
Tk
r½
*
>
T½
r
J"KF k
-.:;- K
T½, ..., Tk
•
•
r
0:LM# •
m
% &
c
%
$ '
'interior
$
! node
!N G
H A G
'height)
-@ - !" G
w
-.:;-
w
H -
v
v
G OP*
KF #*HI :;
/9 'root
-@
&
"6 /9 G # %K= > -. G
OP*
'leaf
H
-@ OP*
'depth
=5 G
'sibling
- level
G 'QLRC
SL?
"K %= > -. !G
G - -@ KF :; L c
% &
c
%
$ '
'ordered
$
tree
U*F 'k-ary
L&
& /F G =5 U** -. !"
'labeled
- R 'H P M UK$ G -. !"
k
k G =5 )* 8.7
'complete
tree
UK$ tree
!* k
k-ary tree
JF. !* k
G = 5 ) * - . ! " "K S? H
'binary
tree
! 'balanced
VL$ =5 W= - =5 8.7 LBC -. !1*F tree
:"F & -"& T" 7 8.7 H S?-. !"
-. :& DEL@F & -"& =5 X5 G & !F V$ =5
'completely
balanced tree
:"F T
F. L& K6 H SL? -. !"
c
% &
c
%
$ '
$
'subtree
'descendents)
[!) Y -R G 'full
ZL)* # :!F
v
Y v
v
G Y
-@ - !" :9:F !G -N.
[: Y !6 G tree
> 'ancestors
G 9
:"F T
F. JF. : G 9 G - - L @ L K F : 9: F G - N .
'forest
J]9
[: 9 I9 LBC #
^ )*
'proper
descendents
!) Y
!F \K7 - !) Y G : A- G Y WR*
'proper
"LK !) 9
c
% &
c
ancestors
!) 9
: A -
9 WR*
%
$ '
$
+J7
n −
H )*
B•
G J. )*
n•
"#$%
H ) * % & k
P M G = 5 ) * - . G n − B = (n − ½)/k
`>
! " _*$
½ = (n − B) ∗ k )= •
B = n − (n − ½)/k
n
•
B = [(k − ½)n + ½]/k
& a>bE
c
k
(k − ½)n + ½ !) •
% &
c
%
$ '
$
&'
a
c
b
d
T½...Tk
e
k
r
-@ T
+4L5
+'preorder
U**b> [
f
g
h
j
i
k
l
P re(T ) = r, P re(T½), P re(T¾), . . . , P re(Tk )
m
+'inorder
U**# [
Inorder(T ) = Inorder(T½), r, Inorder(T¾), . . . , Inorder(Tk )
preorder(A): a, b, c, f, g, h, j, k, d, e, i, l, m
+'postorder
U**`> [
P ost(T ) = P ost(T½), P ost(T¾), . . . , P ost(Tk ), r
c
% &
c
%
$ '
$
a
a
c
b
f
d
g
e
h
j
i
k
l
c
b
f
d
g
h
j
m
e
i
k
preorder(A): a, b, c, f, g, h, j, k, d, e, i, l, m
preorder(A): a, b, c, f, g, h, j, k, d, e, i, l, m
norder(A): b, a, f, c, g, j, h, k, d, l, i, m, e
inorder(A): b, a, f, c, g, j, h, k, d, l, i, m, e
l
m
postorder(A): b, f, g, j, k, h, c, d, l, m, i, e, a
c
% &
c
%
$ '
$
(% (')!
' !/*
root[T ]
.!F c T
!/* +MakeEmpty(T )
•
a
+!9 %d +
=!F T
-@ +Root(T )
•
c
b
d
e
G +!9 % +
=!F
T
null G
=!F
T
v
G > +Parent(T, v)
f
•
+!9 %G +
G =5 #, +Left-Most-Child(T, v)
null G
c
v
g
i
h
j
k
l
m
•
+!9 %G +
% &
c
%
$ '
p G T
$
bR>
=!F
T
R +Right-Sibling(T, v)
v
null G
Preorder(T, p)
2
3 Print Element(T, p)
!, -. .!F DE@F +isEmpty(T )
4 p ← Left-Most-Child (T, p)
=!F do Preorder (T,p)
n G BC UK$ +Element(T, n) •
UK$ +!9 %G +
p ← Right-Sibling (T, p)
c
% &
c
norder(T, p)
$
Postorder(T, p)
1 if p = null
1 if p = null
then return
2
then return
3 n ← Left-Most-Child (T, p)
3 n ← Left-Most-Child (T, p)
4 Inorder (T, n)
4 while n = null
5 Print Element(T, p)
5
6 n ← Right-Sibling (T, n)
6
7 while n = null
7 Print Element(T, p)
8
9
c
%
$ '
2
•
= +!9 % +
5 while p = null
7
•
SeM C +!9 % +
then return
6
+!9 %G +
:9:F MC )* +Size(T )
1 if p = null
•
do Postorder (T, n)
n ← Right-Sibling (T, n)
do Inorder (T, n)
n ← Right-Sibling (T, n)
% &
c
%
$ '
NodeHeight(T, p)
$
CountNodes(T, p)
returns the height of p in tree T
counts the number of nodes in T with root p
1 if isEmpty(T )
2
1 if isEmpty(T )
then error
2
then return 0
3 height ← 0
3 count ← 1
4 p ← Left-Most-Child (T, p)
4 p ← Left-Most-Child (T, p)
5 while p = null
5 while p = null
6
7
do height ← max{height, NodeHeight (T, p)}
6
p ← Right-Sibling (T, p)
7
8 return height + 1
c
do count ← count+ CountNodes (T, p)
p ← Right-Sibling (T, p)
8 return count
% &
c
%
$ '
$
+] JRC !* +,
PM Father
r
-@ - !" T
+#R*
p >
Find-Parent(T, r, p)
if p = r
1
then return null
2 q ← Left-Most-Child (T, r)
3 while q = null
4
do if p = q
5
then return r
6
s ← Find-Parent(T, q, p)
7
if s = null
8
then return s
9
q ← Right-Sibling (T, q)
10 return null
-P,:F +-@ -
fP7 U** _ U*F G>
c
parent G>
% &
c
%
$ '
$
. G> - $ :*!F [ # a
a
c
b
f
g
p
d
e
h
q
u
i
w
x
z
m
r
s
f
d
g
t
e
h
j
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
a b c d e f g h i p u q m r s t w x z
0 1 1 1 1 2 2 5 5 0 10 10 10 13 13 13 11 11 11
c
c
b
i
k
l
m
1 2 3 4 5 6 7 8 9 10 11 12 13
a b c d e f g h i j k l m
0 1 1 1 1 3 3 3 5 8 8 9 9
% &
c
%
$ '
$
,-! ! ,.+! + [
G G & G Wi = 5 - child[i]
-.
%label -P,:F
•
- •
Child[1..max-child]
.!F
G =5 )* 8.7
c
% &
c
max_child
F
•
%
$ '
$
(% /0 +,
a
root[T ]
G c
b
e
d
label -P,:F •
f
j
c
G& -
•
'!NM G > - R %V$R =5 #, -
•
parent
i
h
g
k
l
right-sibling %left-most-child
m
% &
c
%
$ '
$
$! ,-! ! ,.+! +,
"1% (')!
Create2(x, T1, T2)
[ -KF
creates a tree with x as the label of its root
and two subtrees T1 and T2 (T1 = null )
1 MakeEmpty (T )
2 root[T ] ← Allocate-Node (x, root[T1], null , null )
3 right-sibling[root[T1]] ← root[T2]
4 parent[root[T1]] ← root[T ]
5 parent[root[T2]] ← root[T ]
6 size[T ] ← 1 + size[T1] + size[T2]
7 return T
c
% &
c
%
$ '
$
Create3(x, T1, T2, T3)
MakeEmpty (T )
1 root[T ] ← Allocate-Node (x, root[T1], null , null )
.! F G & G V $ = 5 - - . right
G 2 right-sibling[root[T1]] ← root[T2]
parent #6RF
3 right-sibling[root[T2]] ← root[T3]
left - P ,: F & -"& 4 parent[root[T1]] ← root[T ]
5 parent[root[T2]] ← root[T ]
6 size[T ] ← 1 + size[T1] + size[T2] + size[T3]
7 return T
c
% &
c
%
$ '
$
Preorder(T, r)
, n !
It is assumed that r is the root of T
1 if r = null
2
then return
i
3 meet element(T, r)
4 Preorder(T, lef t[r])
5 Preorder(T, right[r])
i−½
⎧
⎪
⎪
⎨
T (n) = ⎪⎪⎩
T (¼) = ½
T (n) = ni=½ T (i − ½)T (n − i), n ≥ ½
'Y*. Wn C
c
% &
c
n−i
T (n) = n+½½ ¾nn !"@ -? # \:9
%
$ '
$
'postfix
=:K>
Expression Tree) 2) E → E½E¾ < β >
→ E<α>
→ < operand >
+01C -=:
'infix
with complete paranthesis
JF. I"=> =:=F
E →
→
→
<α> →
<β> →
c
% &
c
(E½ < β > E¾)
( < α > E)
< operand >
unary operators
binary operators
%
$ '
$
a+(b-c*d)^e-f^g^(h /-i* k)
'prefix
=:@>
E → < β > E½E¾
→ <α>E
→ < operand >
−
∧
+
∧
a
−
∧
f
∗
b
c
∗
g
e
/
h
d
k
¬
i
c
% &
c
%
$ '
$
=:K> 01C - 'JF. I"=> FI, -=
=:=F 01C J1*
01C
a + (b − c ∗ d) ∧ −f ∧ g ∧ (h/¬i ∗ k)
((a + ((b − (c ∗ d)) ∧ e) − (f ∧ (g ∧ ((h/(¬i)) ∗ k))))
abcd ∗ −e ∧ +f ghi¬/k ∗ ∧ ∧ −
− + a ∧ −b ∗ cde ∧ f ∧ g ∗ /h¬ik
→ ← -K:=
a +(b − c ∗ d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+ (b − c ∗ d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+ (
b − c ∗ d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+( b
−c ∗ d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+( − c ∗ d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+(− c
∗d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+(− ∗
d) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+(−∗ d
) ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+(−∗ )
∧e − f ∧ g ∧ (h/¬ i ∗ k)
+ ∧ e − f ∧ g ∧ (h/¬ i ∗ k)
+∧ e
−f ∧ g ∧ (h/¬ i ∗ k)
+∧ − f ∧ g ∧ (h/¬ i ∗ k)
!9 -"@>
a
a
a
ab
ab
abc
abc
abcd
abcd ∗ −
abcd ∗ −
abcd ∗ −e
c
% &
c
01C W5
=:=F
JF. I"=> =:=F
=:K>
=:@>
%
$ '
i
n
p
u
t
(
−
+
∗
/
∧
¬
)
(
Push
Push
Push
Push
Push
Push
Push
Pop-more
on the top of stack
−
+
×
/
Push Push Push Push
Pop Pop Pop Pop
Pop Pop Pop Pop
Push Push Pop Pop
Push Push Pop Pop
Push Push Push Push
Push Push Push Push
Pop Pop Pop Pop
Action[i,j]
c
∧
Push
Pop
Pop
Pop
Pop
Push
Push
Pop
$
!9
¬
Push
Pop
Pop
Pop
Pop
Pop
Pop
Pop
abcd ∗ −e ∧ +
abcd ∗ −e ∧ +f
abcd ∗ −e ∧ +f
abcd ∗ −e ∧ +f g
abcd ∗ −e ∧ +f g
abcd ∗ −e ∧ +f g
abcd ∗ −e ∧ +f gh
abcd ∗ −e ∧ +f gh
abcd ∗ −e ∧ +f gh
abcd ∗ −e ∧ +f ghi
abcd ∗ −e ∧ +f ghi¬ /
abcd ∗ −e ∧ +f ghi¬ /k
abcd ∗ −e ∧ +f ghi¬ /k∗
abcd ∗ −e ∧ +f ghi¬ /k ∗ ∧ ∧ −
% &
c
→
−
−
−∧
−∧
−∧∧
− ∧ ∧(
− ∧ ∧(
− ∧ ∧(/
− ∧ ∧(/¬
− ∧ ∧(/¬
− ∧ ∧(∗
− ∧ ∧(∗
−∧∧
-"@>
← -K:=
f
∧g ∧ (h/¬ i ∗ k)
∧ g ∧ (h/¬ i ∗ k)
g
∧(h/¬ i ∗ k)
∧ (h/¬ i ∗ k)
(
h/¬ i ∗ k)
h
/¬ i ∗ k)
/
¬ i ∗ k)
¬ i ∗ k)
i
∗k)
∗
k)
k
)
)
%
$ '
17
18
19
20 while not isEMPTY(S)
21
do write TOP(S) to postf ix
22
POP(S)
c
else
done ← true
write s to postf ix
POP(S)
$
Infix-to-Postfix(inf ix)
Uses stack S, and matrix action
1 intialize-actions()
2 while there is token in inf ix
3
do read token c from inf ix
4
if c is an operand
5
then write c to postf ix
6
else done ← f alse
7
while not done
8
do if isEMPTY(S)
9
then Push (c, S)
10
done ← true
11
else s ← T OP (S)
12
if c =) and s = (
13
then POP(S)
14
done ← true
15
if action[c, s] = push
16
then Push (S, c)
% &
c
$ '
12
13
14
15
c
do operator ← postf ix[i]; i ← i − 1
Postfix-to-Prefix (i, j)
pref ix[j] ← operator
j ← j−1
%
$
Postfix-to-Prefix(i, j)
converts correct postf ix[?..i] to pref ix[?..j]
at the end, i and j are either 0 or
the last index of the preceeding expressions.
postf ix and pref ix are global arrays
1 i , j are refrenced variables switch
2
case postf ix[i] is operand
3
do pref ix[j] ← postf ix[i]
4
i ← i − 1; j ← j − 1
5
case postf ix[i] is binary operator
6
do operator ← postf ix[i]; i ← i − 1
7
Postfix-to-Prefix (i, j)
8
Postfix-to-Prefix (i, j)
9
pref ix[j] ← operator
10
j ← j−1
11
case postf ix[i] is unary operator
% &
c
%
$ '
FindR(A, j)
1 switch
2
case A[j] is a binary operator
3
do count ← 2
4
case A[j] is a unary operator
5
do count ← 1
6
default
7
do count ← 1
8 r← j
9 while Count > 0
10
do r ← r − 1
11
switch
12
case A[r] is a binary operator
13
do count ← count + 1
14
case A[r] is a unary operator
15
do nothing
16
case
17
do count ← count − 1
c
$
Postfix-to-Prefix(i, j, k)
converts postf ix[i..j] to pref ix[k..?]
1 if j < i
2
then return
3 if i = j
% &
4
then pref ix[k] ← postf ix[i]
5
else
pref ix[k] ← postf ix[j]
6
r ← FindR (postf ix, j − 1)
7
Postfix-to-Prefix (i, r − 1, k + 1)
8
Postfix-to-Prefix (r, j − 1, r − i + k + 1)
c
%
$ '
$
18
Postfix-to-Tree(i, j)
return r
Creates a tree for postf ix[i..j]
1 if j < i
2
then return null
3 n ← Allocate-Node(A[j], null , null )
4 if i < j
5
then r ← FindR(postf ix, j − 1)
6
lef t[n] ← Postfix-to-Tree (i, r − 1)
7
right[n] ← Postfix-to-Tree (r, j − 1)
8 return n
c
% &
c
%
'
$
Postfix-to-Tree(j)
Makes a tree for postfix[?..j]
j is assumed to be a reference variable
1 n ← Allocate-Node(A[j], null , null )
2 switch
3
case postf ix[j] is a binary operator
do j ← j − 1
4
5
right[n] ← Postfix-to-Tree(j)
6
j ← j−1
7
lef t[n] ← Postfix-to-Tree(j)
8
case postf ix[j] is a unary operator
9
10
do j ← j − 1
right[n] ← Postfix-to-Tree(j)
11 return n
&
c
%
© Copyright 2026 Paperzz