# Can a complete binary tree have at least two nodes with just one child?

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes at the last level h.[18] An alternative definition is a perfect tree whose rightmost leaves (perhaps all) have been removed. Some authors use the term complete to refer instead to a perfect binary tree as defined below, in which case they call this type of tree (with a possibly not filled last level) an almost complete binary tree or nearly complete binary tree.[19][20] A complete binary tree can be efficiently represented using an array.[18]

Does that mean

• a complete binary tree can have at most one node with exactly a child (or can a complete binary tree has at least two nodes with just one child?)

• in a complete binary tree, a node with exactly a child can only have a left child not a right child.

• in a complete binary tree, a node with exactly a child can exist only at the level next to the last one, and at that level, all the nodes left to the node must have two children, and all the nodes right to the node must be leaves?

Conversely, do the above three points characterize a complete binary tree?

Using the definition you cite:

• A complete tree can have at most one node with one child. If there were two such nodes, then the one on the right could shift its child to the left, so the nodes in the last level wouldn't be "as far left as possible".
• Yes, if a node has only one child, it has to be a left child. Again, because otherwise the child would not be "as far left as possible".
• Yes, in a complete tree, a node with one child has to be in the second-last level. Its children are partially filled, so its children must be in the last level. Yes all the nodes to its left in the same level must have two children, and all the nodes to its right in the same level are leaves.

Finally, no, these statements do not completely characterize a complete tree. A complete tree might have no nodes at all with only one child, in which case none of these statements about one-child nodes apply to it at all.

• Thanks. Do the three characterize a complete binary tree with (at least) a node with exactly one child? How do you characterize a complete binary tree without such a node?
– Tim
Commented Apr 2, 2022 at 23:21
• They do not. There are other shapes the two-child nodes could make that aren't complete trees. I think your definition has a pretty simple characterization. Another one is that the level-order traversal has no gaps. Commented Apr 2, 2022 at 23:23

No

A complete binary tree has a parent node with two children.