09 Tree
09 Tree
INTRODUCTION
the data element, a pointer to the left node, and a pointer to the right
node.
So in C++, the binary tree is built with a node type given below.
class node {
struct node *left;
int data;
struct node *right;
};
Every binary tree has a pointer ROOT, which points to the root element (topmost
element) of the tree. If ROOT = NULL, then the tree is empty.
Linked representation of binary trees
Sequential representation of binary tree
2. The root of the tree will be stored in the first location. That is, TREE[1] will store the
data of the root element.
4. The maximum size of the array TREE is given as (2 h+1–1), where h is the height of the
tree.
5. An empty tree or sub-tree is specified using NULL. If TREE[1] = NULL, then the tree
is empty.
Array Implementation of a binary tree
For any node k