13. subtree
Tree Terminology
Root
Siblings
Internal node
External node
Ancestors
Descendant
Depth
Height
Degree
Subtree
A
B DC
G HE F
I J K
14. Binary Trees
Each node has at most 2 children
10
17
159
6 5 8
Root node
Left subtree
Right child
Right child
Left child
14
16. Tree Traversal
Preorder
Data Left Right
<root><left><right>
F,D,B,A,C,E,J,G,I,H,K
void preorder(node *root){
if(root!=NULL){
printf(“%c”,root->data);
if(root->left!=NULL)
preorder(root->left);
if(root->right!=NULL)
preorder(root->right);
}
}
F
JD
I
E KB G
A C
Root
H
16
18. Tree Traversal
pOSTORDER
Left Right Data
<left><right><root>
A,C,B,E,D,H,I,G,K,J,F,A,B
void postorder(node *root){
if(root!=NULL){
if(root->left!=NULL)
postorder(root->left);
if(root->right!=NULL)
postorder(root->right);
printf(“%c”,root->data);
}
}
F
JD
I
E KB G
A C
Root
H
18