What is a binary tree
A binary tree
is a hierarchical data structure. A binary tree consists of nodes, each node has:
- A left
node
- A right
node
- A
data
element, which could be of any type
Here's how a typical binary tree looks:
public class Node
{
public int Value;
public Node Left;
public Node Right;
public Node(int value)
{
Value = value;
}
}
A binary tree
can be represented graphically
Terminology used in trees:
Root
: the node at the top of the binary treeChild
: a node below a given nodeParent
: the converse definition of a child (the opposite of child)Leaf
: a node without child nodesEdge
: a connection between two nodesSubtree
: a tree representing the descendants of a nodeLevel
: the level at which a node resides, its generation
Another two definitions are:
Depth
: the number of edges from the root to the nodeHeight
: the number of edges from the node to the deepest leaf