Trees2 2
Trees2 2
Et
traversal
Vertical level order
view
a top
b bottomview
c Diagonalview
Root
LST RST
Level Order traversal
Recursion
ideal
3
d ident iterative
9 8
I N 4
6 2 7
Node f A front1
mm
OLN
Te data
wit'm print f
se if f left NULL
g insert f left
if f right NULL
g insert f right
Level Order traversal 2 Left Via To view
3 Expedient thee from left
lm
3
1stnode at every level
9 g g g en
1stnode
6 2 7 k Hints for every
2 level nu
y g b in pre
II to be Edge Cat
4 8 Root Mode
print at first
B NX 9 X Nx H N I
It
3 la
9 8 In
Mode f q fronts
6 2 7 In
hemovell
g
NULL
4 8 In if f
paint In
10 In NULL
g insert
I Pseudo Code
Queue 2 Mode q
insert root
q
insert NULL
q
1
while q sizeL
Mode
f q fronts
hemovell Node
is
q queue isvalid
typeof
NULL
if f because
now
Paint l
NULL
g insert
else I
data
print f
IIinsertchildren
NULL
if f left
insert g left
g Nuu
if gright f
q insert qright
y
OUT
To 04am
have
can
so we
Level Ordertraversal 3 Righttoleft
3 3 idea
T 9 while inserting child
at 8
2 6
nodes
7
I 2A g h if not Nuu
night
child
I 10 not Now
4 8 if
left child
Iya
7
Bottoming
6 11 5
3 g 1g lastnode at
9
2 100 32 u in everyone
3 11
1 Id Data structure nodes
Map Lint listof
7 11 5 12
z 7 mink 3
I142 10 2 214 All Modes
19
1 6115 btw
o g zg g minne
1 412
2 1 m
Example
Expected HI Preorder DLR
0g 1 9 1 9
82 0 82
0
sad lot 1 6 9 1 96
1 9
24 9I 1
0
9
28 0 28
1 9 6 18 9 6
Fill hashmap using level order
f y y 9 2 l
9 6
0 8 2
I y
1 6 9
2
Y
10
2 10 4 E IE
I 9
2
y
28 0 29 17 26 17 20 LI 27 22 17 294 I 7 24 4
0
2
Max
O
Minh
1 0
PseudoCode
Hashmap L int listofNodes km
Queue a Mode int f s q
itinmitiiii.io 5 70
White q sirec
C
Mode int f q front
q removeC f second
Node t f first int l
Minh min mint l mash Max mashie
t in level l
I insert node also insert data
hm l add t I you can
11Add left right
Null
if t left
insert t lift l I3
q
t right NULL
if 1 1
q insert L t right
in math it t
i min L
for nodes at ith lend
hml i listof
I him i o
topview
above list
1 print
bottomview
fun i sat
Diagonal View Output
1 9
8
o f IN 622
a 6 2 4109
I 7 2
he
2 10
3 2
f if we go to lift
2
944 Glue is same
if we
gotonight
had
Height1
sp
6 1 5112
5 2
int height Mode root L P 34
Nuu return l
if root
int l heightGroot left iii in
Egg II g
int as height rootright
Eff at the
1
return mall 9 1
ur
if
1
lengthof path y
Ig
no of edges
EY f l
a tree
Diameter of BT Length of Longtin
node
every
hllstthlestit
EI est th
tellst th
n y 2 1 2
2 I
E
t u s
1 O O
V
O
2
117
2
127 at G a
3
Ii
87470
FE 1 then y
Q
yo
2 9
3 4 length through
root node
a
hut thirsty
3 E
O
5 1 2
I H
I 3
E E 2
go
return Max l 9 1
hoot
ltrtz
9521279421
Ettore
2o
Colley
Eng
ABES
habit
HE