A tree is a nonlinear hierarchical data structure that consists of nodes connected by edges.
Tree Terminologies
Node
A node is an entity that contains a key or value and pointers to its child nodes.
The last nodes of each path are called leaf nodes or external nodes that do not contain a link/pointer to child nodes.
The node having at least a child node is called an internal node.
Edge
It is the link between any two nodes.
Types of Tree
Binary Tree
Binary Search Tree
AVL Tree
B-Tree
public class GFG {
static class Node {
int key;
Node left, right;
Node(int key)
{
this.key = key;
left = null;
right = null;
}
}
static Node root;
static Node temp = root;
// Driver code
public static void main(String args[])
{
root = new Node(10);
root.left = new Node(11);
root.left.left = new Node(7);
root.right = new Node(9);
root.right.left = new Node(15);
root.right.right = new Node(8);
}
}
0 Comments