Representation of Binary Tree
Each node in a Binary Tree has three parts:
- Data
- Pointer to the left child
- Pointer to the right child
Below is the representation of a Node of Binary Tree in different languages:
// Use any below method to implement Nodes of tree
// Method 1: Using "struct" to make
// user-define data type
struct node {
int data;
struct node* left;
struct node* right;
};
// Method 2: Using "class" to make
// user-define data type
class Node {
public:
int data;
Node* left;
Node* right;
};
// Structure of each node of the tree
struct node {
int data;
struct node* left;
struct node* right;
};
// Class containing left and right child
// of current node and key value
class Node {
int key;
Node left, right;
public Node(int item)
{
key = item;
left = right = null;
}
}
# A Python class that represents
# an individual node in a Binary Tree
class Node:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
// Class containing left and right child
// of current node and key value
class Node {
int key;
Node left, right;
public Node(int item)
{
key = item;
left = right = null;
}
}
<script>
/* Class containing left and right child of current
node and key value*/
class Node
{
constructor(item)
{
this.key = item;
this.left = this.right = null;
}
}
// This code is contributed by umadevi9616
</script>
Introduction to Binary Tree – Data Structure and Algorithm Tutorials
Binary Tree is a non-linear data structure where each node has at most two children. In this article, we will cover all the basics of Binary Tree, Operations on Binary Tree, its implementation, advantages, disadvantages which will help you solve all the problems based on Binary Tree.
Table of Content
- What is Binary Tree?
- Representation of Binary Tree
- Types of Binary Tree
- Operations On Binary Tree
- Insertion in Binary Tree
- Traversal of Binary Tree
- Deletion in Binary Tree
- Searching in Binary Tree
- Auxiliary Operations On Binary Tree
- Implementation of Binary Tree
- Complexity Analysis of Binary Tree Operations
- Advantages of Binary Tree
- Disadvantages of Binary Tree
- Applications of Binary Tree
- Frequently Asked Questions on Binary Tree