algorithms

Algorithms Handbook

View on GitHub

Binary Tree

Overview

A Binary Tree is a special case of an ordered K-ary tree, where k is 2.

Tree data structure in which each node has at most two children.

We use the attributes p, left and right, to store pointers to the parent, left child and right child of each node in a binary tree T. If x.p == NIL, then x is the root. The root of the entire tree T is pointed to by the attribute T.root.

Set Theory

A recursive definition using just set theory notions is that a (non-empty) binary tree is a tuple (L, S, R), where L and R are binary trees or the empty set, and S is a singleton set containing the root.

Graph Theory

From a graph theory perspective, binary trees are defined here as arborescences. A binary tree may thus be also called a bifurcating arborescence.

It is also possible to interpret a binary tree as an undirected, rather than a directed graph, in which case a binary tree is an ordered, rooted tree.

Applications

  1. As a means for accessing nodes based on some value/label. They are used for efficient searching & sorting (e.g., Binary Search Trees and Binary Heaps).

  2. As a representation of data with a relevant bifurcating structure (e.g., Huffman Coding and Cladograms).

Types