educative.io

Getting clarity on `Perfect Binary Trees` Definition

The chapter says that a binary tree is said to be a perfect binary tree if it is both full and complete.

I am confused with this definition and would like someone to correct my understanding.

Consider the following tree

        1
      /   \
     2     3
    / \   
   4   5
  • A full binary tree is a binary tree in which every node has either 0 or 2 children.
  • A complete binary tree is a binary tree in which all levels, except possibly the last, are completely filled, and all nodes are as left as possible.

From the above 2 definitions, the provided tree is both full and complete. Hence, does it mean it is also a perfect tree or not?


Course: Data Structures for Coding Interviews in C++ - Learn Interactively
Lesson: https://www.educative.io/courses/data-structures-coding-interviews-cpp/what-is-a-binary-tree

Hi @Dishant_Arora, Welcome to our Discuss community.

Thank you for pointing out the definition error in the course. The original definition of a perfect binary tree is as follows:
“A perfect binary tree is a binary tree in which every internal node has exactly two children, and all leaf nodes are at the same level.”

According to this definition, your provided binary tree is not a perfect binary tree. A perfect binary tree is a binary tree in which all the levels of the tree are fully filled. We have updated the definition in the course.

Once again, thanks for pointing this out.
Happy Learning!