Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

about complete binary tree

Tags:

binary-tree

is this possible that a node in the complete binary tree has just one child? thanks

Can this be a complete binary tree?

        23
       /  \
      12  15
     /  \   
    9   11 
   / \    \
  10  5    13  
like image 411
user355002 Avatar asked Apr 11 '26 01:04

user355002


2 Answers

OK, first to make the difference between a perfect and a complete binary tree. In a perfect binary tree every node has two children(if not a leaf) or no children(if a leaf). So a perfect binary tree of level N has totally 2^(N + 1) - 1 nodes. But if we talk about complete binary tree - this means every level, except the last is full, and the last level may not be full. Also in a complete binary tree, the last level nodes must be filled from left to right.

So if you talk about perfect binary tree, it is not possible. But if you mean the complete binary tree, it is possible to have only one child.

like image 64
Petar Minchev Avatar answered Apr 13 '26 01:04

Petar Minchev


I would say it is possible:

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

this is a

binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible

And node x has just one child.

like image 30
phimuemue Avatar answered Apr 13 '26 02:04

phimuemue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!