What is Binary Tree and Representation of Binary Tree?


Binary Tree:

A binary tree is also a tree which is either empty or non empty . If it is non empty it should satisfy the following properties.

1. one of the element is identified as root.

2. other elements are divided in to two subgroups. One subgroup is called right sub tree.

3. In binary tree for every node we have almost two child nodes.

4. Every sub tree is given a binary tree.

binarytree


Note :A note is a binary tree does not necessary to have two children. It may have only a left child or only a right child. i.e., In a binary tree node with degree greater than 2.

Representation of binary tree :

The Binary Tree can be represented in computer in two ways :

1. Array  representation or sequential representation.

2. Linked representation.

1. Array  representation:  The binary tree can be represented in sequential memory location using one dimensional array. If ‘t’ is an array then the binary tree can be represented as root node. It must be stored at t[1]. For a node at t[i] the left children is at t[2*i] the right children is t [(2*i)+1]. Its parent is at t[i/2].

Ex : Binary tree

binary tree reprasentation


2.linked Representation : A node in a binary tree contains three parts. Data part , object reference parts( address parts) . one address is called left sub tree address and the other is called right sub tree address . This is denoted as follows:

Binary search tree node:
binary tree node


class BSTNode
{
int data:
BSTNode left;
BSTNode right;
}

This class is also called as self referential class.



Related

Data Structures 8492954107078451077

Post a Comment

emo-but-icon

item