Check whether a binary tree is a full binary tree or not | C # program to check if binary tree is full or not ; Tree node structure ; This function checks if a binary tree is full or not ; if empty tree ; if leaf node ; if both left and right subtrees are not null they are full ; if none work ; Driver Code
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class GFG { public Node root ; public virtual bool isFullTree ( Node node ) { if ( node == null ) { return true ; } if ( node . left == null && node . right == null ) { return true ; } if ( ( node . left != null ) && ( node . right != null ) ) { return ( isFullTree ( node . left ) && isFullTree ( node . right ) ) ; } return false ; } public static void Main ( string [ ] args ) { GFG tree = new GFG ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 20 ) ; tree . root . right = new Node ( 30 ) ; tree . root . left . right = new Node ( 40 ) ; tree . root . left . left = new Node ( 50 ) ; tree . root . right . left = new Node ( 60 ) ; tree . root . left . left . left = new Node ( 80 ) ; tree . root . right . right = new Node ( 70 ) ; tree . root . left . left . right = new Node ( 90 ) ; tree . root . left . right . left = new Node ( 80 ) ; tree . root . left . right . right = new Node ( 90 ) ; tree . root . right . left . left = new Node ( 80 ) ; tree . root . right . left . right = new Node ( 90 ) ; tree . root . right . right . left = new Node ( 80 ) ; tree . root . right . right . right = new Node ( 90 ) ; if ( tree . isFullTree ( tree . root ) ) { Console . Write ( " The ▁ binary ▁ tree ▁ is ▁ full " ) ; } else { Console . Write ( " The ▁ binary ▁ tree ▁ is ▁ not ▁ full " ) ; } } }