5. • Root → The topmost node of the hierarchy is called the root of the tree.
• Child → Nodes next in the hierarchy are the children of the previous node.
• Parent → The node just previous to the current node is the parent of the current node.
• Siblings → Nodes with the same parent are called siblings.
• Ancestors → Nodes which are higher in the hierarchy are ancestors of a given node.
• Descendents → Nodes which are lower in the hierarchy are descendants of a given node.
• Internal Nodes → Nodes with at least one child are internal nodes.
• External Nodes/Leaves → Nodes which don't have any child are called leaves of a tree.
• Edge → The link between two nodes is called an edge.
• Level → The root of a tree is at level 0 and the nodes whose parent is root are at level 1
and so on.
6. BINARY TREE
Binary Tree is defined as a tree data structure where each node has at most
2 children. Since each element in a binary tree can have only 2 children, we
typically name them the left and right child.
7. TYPES OF BINARY TREES
1- FULL BINARY TREE
2-COMPLETE BINARY TREE
3-PERFECT BINARY TREE
4-BALANCED BINARY TREE
5-DEGENERATE BINARY TREE
8. FULL BINARY TREE
• When a tree has either two or zero child nodes, it’s considered a full binary
tree.
9. COMPLETE BINARY TREE
• All levels are completely filled except the last level.
• The last level has all nodes on left as possible.
10. PERFECT BINARY TREE
• Perfect binary tree has the same depth for every child node to the leaf nodes.
13. Binary Tree Traversals
The term 'tree traversal' means traversing or visiting each node
of a tree.
1- Inorder Traversal (Left->Root->Right)
2-Preorder Traversal (Root->Left->Right)
3- Postorder Traversal (Left->Right->Root)
14. Inorder Traversal
• This technique follows the 'left root right' policy. It means that
first left subtree is visited after that root node is traversed, and
finally, the right subtree is traversed.
1.Step 1 - Traverse the left subtree recursively.
2.Step 2 - Visit the root node.
3.Step 3 - Traverse the right subtree recursively.
D → B → E → A → F → C → G
15. Preorder Traversal
• This technique follows the 'root left right' policy.
1.Step 1 - Visit the root node
2.Step 2 - Traverse the left subtree recursively.
3.Step 3 - Traverse the right subtree recursively.
A → B → D → E → C → F → G
16. Postorder Traversal
• This technique follows the 'left right root' policy.
1.Step 1 - Traverse the left subtree recursively.
2.Step 2 - Traverse the right subtree recursively.
3.Step 3 - Visit the root node.
D → E → B → F → G → C → A