A binary tree is a tree-type data structure, where there’s a root (parent node) and 0-2 child nodes, which we call leaves. Leaves with no children point to NULL addresses. An important variation is the binary search tree. Each node in the tree is the root of a sub-tree, which allows us to define functions that operate recursively. In the worst case, binary trees can be unbalanced (i.e., a linked list).

Implementation

typedef struct node {
	int data;
	struct node *right, *left;
} Node; // for binary trees
 
typedef struct btree {
	Node *root;
} BTree; // for the root node of the tree