About the complete binary tree

Is it possible that a node in a complete binary tree has only one child? thank

Could this be a complete binary tree?

        23
       /  \
      12  15
     /  \   
    9   11 
   / \    \
  10  5    13  
+3
source share
4 answers

OK, first make the difference between a perfect and a complete binary tree. In an ideal binary tree, each node has two children (if not a leaf) or no children (if a leaf). Thus, an ideal binary level tree Nhas completely 2^(N + 1) - 1nodes. But if we are talking about a complete binary tree - this means that each level, except the last, is filled, and the last level may not be complete. Also in the full binary tree, the last level nodes should be filled from left to right.

, , . , .

+6

, :

     *
    / \
   /   \
  *     x
 / \   / 
*   * *

, , , , , ,

node x .

+3

:

, , , , , .

, .

0

:

- , , , , , , .

        23
       /  \
      12  15
     /  \   
    9   11     <- not the last level, but not completely filled!
   / \    \
  10  5    13  <- last level: not completely filled, but that okay

, , .

0

Source: https://habr.com/ru/post/1751729/


All Articles