Binary Tree

DOWNLOAD Mathematica Notebook

A binary tree is a tree-like structure that is rooted and in which each vertex has at most two children and each child of a vertex is designated as its left or right child (West 2000, p. 101). In other words, unlike a proper tree, the relative positions of the children is significant.

Dropping the requirement that left and right children are considered unique gives a true tree known as a weakly binary tree (in which, by convention, the root node is also required to be adjacent to at most one graph vertex).

BinaryTrees

The height of a binary tree is the number of levels within the tree. The numbers of binary trees of height h=1, 2, ... nodes are 1, 3, 21, 651, 457653, ... (OEIS A001699). A recurrence equation giving these counts is

 a_n=a_(n-1)^2+a_(n-1)(1+sqrt(4a_(n-1)-3))
(1)

with a_1=1.

BinaryTreesNodes

The number of binary trees with n nodes are 1, 2, 5, 14, 42, ... (OEIS A000108), which are the Catalan number C_n.

For a binary tree of height h with n nodes,

 h<=n<=2^h-1.
(2)

These extremes correspond to a balanced tree (each node except the tree leaves has a left and right child, and all tree leaves are at the same level) and a degenerate tree (each node has only one outgoing branch), respectively.

For a search of data organized into a binary tree, the number of search steps S(n) needed to find an item is bounded by

 lgn<=S(n)<=n.
(3)

Partial balancing of an arbitrary tree into a so-called AVL binary search tree can improve search speed.

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.