Binary trees
As we have seen before, a binary tree consists of a tree in which the maximum number of children per node is two. This property ensures us that every node has a finite number of children. Moreover, we can assign them known references, left and right children.
Types and variations
Before getting into the Swift implementation, let's define some different types of binary tree:
Full binary tree: When for every node N in the tree, N has zero or two children (but never one).
Full binary tree compared to a not full binary tree
Perfect binary tree: All interior nodes have two children. All leaves have the same depth.
Perfect binary tree
Complete binary tree: All levels are 100% filled by nodes except the last one, which can be not fully completed but in which the existent nodes are in the left side of the tree.
Complete binary tree
Balanced binary tree: It has the minimum possible height for the leaf nodes.
Balanced binary tree
Code
For a binary tree implementation, the data structure...