A Perfect BST |
Balanced Tree |
*A perfect tree is always a complete tree but a complete tree is not always a perfect tree
BST can be simply described as an inverted tree because the data or node at the top is called the root and the node at the bottom is called the leafs. We could also use the term grandparent, ancestors, parents, siblings, child and so on.
ex:
- 50 is the ancestor of 67.
- 9 is the sibling of 23.
- The parent of 54 is 76
Properties
The number of maximum node on each level k is 2k.
The number of maximum node on a certain height h is 2h+1 - 1
The maximum height of n nodes is n-1.
The minimum height of n nodes is 2log(n).
Representation of a Binary Tree
Like I said previously, BST is like double linked list but they have multiple pointers that points towards the parent and the children.
Code:
struct node {
int data;
struct node *left;
struct node *right;
struct node *parent;
};
struct node *root = NULL;
No comments:
Post a Comment