A binary tree is a tree data structure with the restriction that each node can have at most 2 children nodes. We reuse the same terminology as regular trees. An important variation on regular binary trees is that of the binary search tree.
Quick links:
- LeetCode
- Binary tree
- 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