Check for Full Binary Tree

Last Updated : 24 May, 2026

Given a Binary Tree, check whether it is a full binary tree or not. A full binary tree is a binary tree with either zero or two child nodes for each node.

Note: An empty tree (NULL node) is considered a full binary tree. Leaf Node is also considered a full binary tree.

Example : 

Input: root = [1, 2, 3, 4, 5]

409842944

Output: true
Explanation: Every node except leaf node has two children so it is a full tree.


Input: root = [1, 2, 3, 4]

409842981

Output: false
Explanation: Node 2 has only one child so this is not a full tree.

Try It Yourself
redirect icon

Using Recursive Approach - O(n) Time and O(n) Space

The idea is to recursively check every node in the binary tree. So, for every node check if it is a leaf node, then return true else check if both left and right children exist, recursively check both subtrees and if exactly one child exists, then return false because the tree is not full.

  • If the current node is NULL, return true.
  • If the current node is a leaf node, return true.
  • Check whether both left and right children exist. If both children exist, recursively check the left and right subtrees.
  • If only one child exists, return false.
C++
#include <iostream>
using namespace std;

// Definition of Binary Tree Node
class Node
{
  public:
    int data;
    Node *left;
    Node *right;

    // Constructor
    Node(int val)
    {
        data = val;
        left = right = nullptr;
    }
};

// Function to check whether a binary tree is a Full Binary Tree
bool isFullTree(Node *root)
{
    // Case 1: Empty tree is considered full
    if (root == nullptr)
    {
        return true;
    }

    // Case 2: Leaf node
    if (root->left == nullptr && root->right == nullptr)
    {
        return true;
    }

    // Case 3: Both children exist
    if (root->left != nullptr && root->right != nullptr)
    {
        return isFullTree(root->left) && isFullTree(root->right);
    }

    // Case 4: One child is missing
    return false;
}

int main()
{
    /*
            1
          /   \
         2     3
        / \
       4   5

       This is a Full Binary Tree
    */

    Node *root = new Node(1);

    root->left = new Node(2);
    root->right = new Node(3);

    root->left->left = new Node(4);
    root->left->right = new Node(5);

    if (isFullTree(root) == true)
    {
        cout << "True";
    }
    else
    {
        cout << "False";
    }

    return 0;
}
C
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

// Definition of Binary Tree Node
struct Node
{
    int data;
    struct Node *left;
    struct Node *right;
};

// Function to create a new node
struct Node *createNode(int val)
{
    struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));

    newNode->data = val;
    newNode->left = NULL;
    newNode->right = NULL;

    return newNode;
}

// Function to check whether a binary tree is a Full Binary Tree
bool isFullTree(struct Node *root)
{
    // Case 1: Empty tree is considered full
    if (root == NULL)
    {
        return true;
    }

    // Case 2: Leaf node
    if (root->left == NULL && root->right == NULL)
    {
        return true;
    }

    // Case 3: Both children exist
    if (root->left != NULL && root->right != NULL)
    {
        return isFullTree(root->left) && isFullTree(root->right);
    }

    // Case 4: One child is missing
    return false;
}

int main()
{
    /*
            1
          /   \
         2     3
        / \
       4   5
    */

    struct Node *root = createNode(1);

    root->left = createNode(2);
    root->right = createNode(3);

    root->left->left = createNode(4);
    root->left->right = createNode(5);

    if (isFullTree(root))
    {
        printf("True");
    }
    else
    {
        printf("False");
    }

    return 0;
}
Java
class Node {
    int data;
    Node left;
    Node right;

    // Constructor
    Node(int val)
    {
        data = val;
        left = right = null;
    }
}

public class GFG {
    // Function to check whether a binary tree is a Full
    // Binary Tree
    static boolean isFullTree(Node root)
    {
        // Case 1: Empty tree is considered full
        if (root == null) {
            return true;
        }

        // Case 2: Leaf node
        if (root.left == null && root.right == null) {
            return true;
        }

        // Case 3: Both children exist
        if (root.left != null && root.right != null) {
            return isFullTree(root.left)
                && isFullTree(root.right);
        }

        // Case 4: One child is missing
        return false;
    }

    public static void main(String[] args)
    {
        /*
                1
              /   \
             2     3
            / \
           4   5
        */

        Node root = new Node(1);

        root.left = new Node(2);
        root.right = new Node(3);

        root.left.left = new Node(4);
        root.left.right = new Node(5);

        if (isFullTree(root)) {
            System.out.println("True");
        }
        else {
            System.out.println("False");
        }
    }
}
Python
# Definition of Binary Tree Node
class Node:
    def __init__(self, val):
        self.data = val
        self.left = None
        self.right = None


# Function to check whether a binary tree is a Full Binary Tree
def isFullTree(root):

    # Case 1: Empty tree is considered full
    if root is None:
        return True

    # Case 2: Leaf node
    if root.left is None and root.right is None:
        return True

    # Case 3: Both children exist
    if root.left is not None and root.right is not None:
        return isFullTree(root.left) and isFullTree(root.right)

    # Case 4: One child is missing
    return False


# Driver Code

if __name__ == "__main__":
    '''
           1
         /   \
        2     3
       / \
      4   5
    '''

    root = Node(1)

    root.left = Node(2)
    root.right = Node(3)

    root.left.left = Node(4)
    root.left.right = Node(5)

    if isFullTree(root):
        print("True")
    else:
        print("False")
C#
using System;

// Definition of Binary Tree Node
class Node {
    public int data;
    public Node left;
    public Node right;

    // Constructor
    public Node(int val)
    {
        data = val;
        left = right = null;
    }
}

class GFG {
    // Function to check whether a binary tree is a Full
    // Binary Tree
    static bool isFullTree(Node root)
    {
        // Case 1: Empty tree is considered full
        if (root == null) {
            return true;
        }

        // Case 2: Leaf node
        if (root.left == null && root.right == null) {
            return true;
        }

        // Case 3: Both children exist
        if (root.left != null && root.right != null) {
            return isFullTree(root.left)
                && isFullTree(root.right);
        }

        // Case 4: One child is missing
        return false;
    }

    static void Main()
    {
        /*
                1
              /   \
             2     3
            / \
           4   5
        */

        Node root = new Node(1);

        root.left = new Node(2);
        root.right = new Node(3);

        root.left.left = new Node(4);
        root.left.right = new Node(5);

        if (isFullTree(root)) {
            Console.WriteLine("True");
        }
        else {
            Console.WriteLine("False");
        }
    }
}
JavaScript
// Definition of Binary Tree Node
class Node {
    constructor(val)
    {
        this.data = val;
        this.left = null;
        this.right = null;
    }
}

// Function to check whether a binary tree is a Full Binary
// Tree
function isFullTree(root)
{
    // Case 1: Empty tree is considered full
    if (root === null) {
        return true;
    }

    // Case 2: Leaf node
    if (root.left === null && root.right === null) {
        return true;
    }

    // Case 3: Both children exist
    if (root.left !== null && root.right !== null) {
        return isFullTree(root.left)
               && isFullTree(root.right);
    }

    // Case 4: One child is missing
    return false;
}

// Driver Code
/*
        1
      /   \
     2     3
    / \
   4   5
*/

let root = new Node(1);

root.left = new Node(2);
root.right = new Node(3);

root.left.left = new Node(4);
root.left.right = new Node(5);

if (isFullTree(root)) {
    console.log("True");
}
else {
    console.log("False");
}

Output
True

Using Level Order Traversal - O(n) Time and O(n) Space

The idea is to perform a level order traversal using a queue to visit every node of the binary tree. For each node, we check whether it has either 0 children or 2 children. If both children exist, we insert them into the queue for further checking. If exactly one child exists, the tree cannot be a Full Binary Tree, so we return false. If all nodes satisfy the condition, we return true.

  • If the root is NULL, return true.
  • Create a queue and insert the root node into it.
  • Traverse the tree while the queue is not empty.
  • Remove the front node from the queue.
  • If the node has both left and right children, insert them into the queue.
  • If the node has exactly one child, return false; otherwise return true after traversal ends.
C++
#include <iostream>
#include <queue>
using namespace std;

// Definition of Binary Tree Node
class Node
{
  public:
    int data;
    Node *left;
    Node *right;

    // Constructor
    Node(int val)
    {
        data = val;
        left = right = nullptr;
    }
};

// Function to check whether a binary tree is a Full Binary Tree
bool isFullTree(Node *root)
{
    // Empty tree is considered full
    if (root == nullptr)
    {
        return true;
    }

    // Queue for level order traversal
    queue<Node *> q;

    // Insert root node into queue
    q.push(root);

    // Traverse until queue becomes empty
    while (!q.empty())
    {
        // Get front node
        Node *curr = q.front();
        q.pop();

        // Leaf node
        if (curr->left == nullptr && curr->right == nullptr)
        {
            continue;
        }

        // If both children exist
        if (curr->left != nullptr && curr->right != nullptr)
        {
            q.push(curr->left);
            q.push(curr->right);
        }
        else
        {
            // One child is missing
            return false;
        }
    }

    // Tree is full
    return true;
}

int main()
{
    /*
            1
          /   \
         2     3
        / \
       4   5

       This is a Full Binary Tree
    */

    Node *root = new Node(1);

    root->left = new Node(2);
    root->right = new Node(3);

    root->left->left = new Node(4);
    root->left->right = new Node(5);

    if (isFullTree(root) == true)
    {
        cout << "True";
    }
    else
    {
        cout << "False";
    }

    return 0;
}
Java
import java.util.LinkedList;
import java.util.Queue;

// Definition of Binary Tree Node
class Node {
    int data;
    Node left;
    Node right;

    // Constructor
    Node(int val)
    {
        data = val;
        left = right = null;
    }
}

public class GFG {
    // Function to check whether a binary tree is a Full
    // Binary Tree
    static boolean isFullTree(Node root)
    {
        // Empty tree is considered full
        if (root == null) {
            return true;
        }

        // Queue for level order traversal
        Queue<Node> q = new LinkedList<>();

        // Insert root node into queue
        q.offer(root);

        // Traverse until queue becomes empty
        while (!q.isEmpty()) {
            // Get front node
            Node curr = q.poll();

            // Leaf node
            if (curr.left == null && curr.right == null) {
                continue;
            }

            // If both children exist
            if (curr.left != null && curr.right != null) {
                q.offer(curr.left);
                q.offer(curr.right);
            }
            else {
                // One child is missing
                return false;
            }
        }

        // Tree is full
        return true;
    }

    public static void main(String[] args)
    {
        /*
                1
              /   \
             2     3
            / \
           4   5

           This is a Full Binary Tree
        */

        Node root = new Node(1);

        root.left = new Node(2);
        root.right = new Node(3);

        root.left.left = new Node(4);
        root.left.right = new Node(5);

        if (isFullTree(root)) {
            System.out.println("True");
        }
        else {
            System.out.println("False");
        }
    }
}
Python
from collections import deque

# Definition of Binary Tree Node
class Node:
    def __init__(self, val):
        self.data = val
        self.left = None
        self.right = None


# Function to check whether a binary tree is a Full Binary Tree
def isFullTree(root):

    # Empty tree is considered full
    if root is None:
        return True

    # Queue for level order traversal
    q = deque()

    # Insert root node into queue
    q.append(root)

    # Traverse until queue becomes empty
    while q:

        # Get front node
        curr = q.popleft()

        # Leaf node
        if curr.left is None and curr.right is None:
            continue

        # If both children exist
        if curr.left is not None and curr.right is not None:
            q.append(curr.left)
            q.append(curr.right)

        else:
            # One child is missing
            return False

    # Tree is full
    return True


# Driver Code

if __name__ == "__main__":
    '''
           1
         /   \
        2     3
       / \
      4   5

      This is a Full Binary Tree
    '''

    root = Node(1)

    root.left = Node(2)
    root.right = Node(3)

    root.left.left = Node(4)
    root.left.right = Node(5)

    if isFullTree(root):
        print("True")
    else:
        print("False")
C#
using System;
using System.Collections.Generic;

// Definition of Binary Tree Node
class Node {
    public int data;
    public Node left;
    public Node right;

    // Constructor
    public Node(int val)
    {
        data = val;
        left = right = null;
    }
}

class GFG {
    // Function to check whether a binary tree is a Full
    // Binary Tree
    static bool isFullTree(Node root)
    {
        // Empty tree is considered full
        if (root == null) {
            return true;
        }

        // Queue for level order traversal
        Queue<Node> q = new Queue<Node>();

        // Insert root node into queue
        q.Enqueue(root);

        // Traverse until queue becomes empty
        while (q.Count > 0) {
            // Get front node
            Node curr = q.Dequeue();

            // Leaf node
            if (curr.left == null && curr.right == null) {
                continue;
            }

            // If both children exist
            if (curr.left != null && curr.right != null) {
                q.Enqueue(curr.left);
                q.Enqueue(curr.right);
            }
            else {
                // One child is missing
                return false;
            }
        }

        // Tree is full
        return true;
    }

    static void Main()
    {
        /*
                1
              /   \
             2     3
            / \
           4   5

           This is a Full Binary Tree
        */

        Node root = new Node(1);

        root.left = new Node(2);
        root.right = new Node(3);

        root.left.left = new Node(4);
        root.left.right = new Node(5);

        if (isFullTree(root)) {
            Console.WriteLine("True");
        }
        else {
            Console.WriteLine("False");
        }
    }
}
JavaScript
// Definition of Binary Tree Node
class Node {
    constructor(val)
    {
        this.data = val;
        this.left = null;
        this.right = null;
    }
}

// Function to check whether a binary tree is a Full Binary
// Tree
function isFullTree(root)
{
    // Empty tree is considered full
    if (root === null) {
        return true;
    }

    // Queue for level order traversal
    let q = [];

    // Insert root node into queue
    q.push(root);

    // Traverse until queue becomes empty
    while (q.length > 0) {
        // Get front node
        let curr = q.shift();

        // Leaf node
        if (curr.left === null && curr.right === null) {
            continue;
        }

        // If both children exist
        if (curr.left !== null && curr.right !== null) {
            q.push(curr.left);
            q.push(curr.right);
        }
        else {
            // One child is missing
            return false;
        }
    }

    // Tree is full
    return true;
}

// Driver Code
/*
        1
      /   \
     2     3
    / \
   4   5

   This is a Full Binary Tree
*/

let root = new Node(1);

root.left = new Node(2);
root.right = new Node(3);

root.left.left = new Node(4);
root.left.right = new Node(5);

if (isFullTree(root)) {
    console.log("True");
}
else {
    console.log("False");
}

Output
True
Comment