Tree
Tree is formed by one or many nodes.
Part of Tree:
1. Degree, Level of a particular node on a tree
2. Height, the height of a tree
3. Parent, parent of a node.
4. Children, child of a node.
5. Sibling, node that come from a same parent.
6. Ancestor, nodes in top of node that connected by edges.
7. Descendant, nodes in the bottom of node that connected by edges.
8. Root, node in the most top of a tree.
9. Edge, a line that connect a node to another.
10. Leaf, node which dont have child.
Binary Tree
Binary Tree is a tree which its each node has child and max 2 child.
There are many types of Binary Tree
1. Perfect Binary Tree
A tree which each level has the same height
2. Complete Binary Tree
An almost perfect binary tree,
3. Skewed Binary Tree
a tree which each node has maximum of 1 child
4. Balance Binary Tree
a tree which each side (left and right) has the same nodes
Representing Binary Tree with Array
1. 0 index is the root
2. the left child index is 2p+1 while the right child index is 2p+2
Representing Binary Tree with Linked List
struct node {
int data;
struct node *left;
struct node *right;
struct node *parent;
};struct node *root = NULL;
Expression Tree Concept
1. Prefix
Output is coming from the top to bottom, left to right.
2. Infix
Output is coming from bottom left to the right and going to the root.
3. Postfix
Output is coming from bottom to top, left to right.