Banana-Leopard/TASTY huggingface dataset:
// C++ program to check if two Nodes in a binary tree are
// cousins
#include <bits/stdc++.h>
using namespace std;
 
// A Binary Tree Node
struct Node {
    int data;
    struct Node *left, *right;
};
 
// A utility function to create a new Binary Tree Node
struct Node* newNode(int item)
{
    struct Node* temp
        = new Node;
    temp->data = item;
    temp->left = temp->right = NULL;
    return temp;
}
 
// Recursive function to check if two Nodes are siblings
int isSibling(struct Node* root, struct Node* a,
              struct Node* b)
{
    // Base case
    if (root == NULL)
        return 0;
 
    return ((root->left == a && root->right == b)
            || (root->left == b && root->right == a)
            || isSibling(root->left, a, b)
            || isSibling(root->right, a, b));
}
 
// Recursive function to find level of Node 'ptr' in a
// binary tree
int level(struct Node* root, struct Node* ptr, int lev)
{
    // base cases
    if (root == NULL)
        return 0;
    if (root == ptr)
        return lev;
 
    // Return level if Node is present in left subtree
    int l = level(root->left, ptr, lev + 1);
    if (l != 0)
        return l;
 
    // Else search in right subtree
    return level(root->right, ptr, lev + 1);
}
 
// Returns 1 if a and b are cousins, otherwise 0
int isCousin(struct Node* root, struct Node* a, struct Node* b)
{
    // 1. The two Nodes should be on the same level in the
    // binary tree.
    // 2. The two Nodes should not be siblings (means that
    // they should
    // not have the same parent Node).
    if ((level(root, a, 1) == level(root, b, 1)) && !(isSibling(root, a, b)))
        return 1;
    else
        return 0;
}
 
// Driver Program to test above functions
int main()
{
    struct Node* root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->left = newNode(4);
    root->left->right = newNode(5);
    root->left->right->right = newNode(15);
    root->right->left = newNode(6);
    root->right->right = newNode(7);
    root->right->left->right = newNode(8);
 
    struct Node *Node1, *Node2;
    Node1 = root->left->left;
    Node2 = root->right->right;
 
    if (isCousin(root, Node1, Node2))
        printf("Yes\n");
    else
        printf("No\n");
 
    return 0;
}
 
// This code is contributed by ajaymakwana

Time complexity: linear
Space complexity: linear
// C++ program to check if all leaves
// are at same level
#include <bits/stdc++.h>
using namespace std;
 
// A binary tree node
struct Node
{
    int data;
    struct Node *left, *right;
};
 
// A utility function to allocate
// a new tree node
struct Node* newNode(int data)
{
    struct Node* node = (struct Node*) malloc(sizeof(struct Node));
    node->data = data;
    node->left = node->right = NULL;
    return node;
}
 
/* Recursive function which checks whether
all leaves are at same level */
bool checkUtil(struct Node *root,
            int level, int *leafLevel)
{
    // Base case
    if (root == NULL) return true;
 
    // If a leaf node is encountered
    if (root->left == NULL &&
        root->right == NULL)
    {
        // When a leaf node is found
        // first time
        if (*leafLevel == 0)
        {
            *leafLevel = level; // Set first found leaf's level
            return true;
        }
 
        // If this is not first leaf node, compare
        // its level with first leaf's level
        return (level == *leafLevel);
    }
 
    // If this node is not leaf, recursively
    // check left and right subtrees
    return checkUtil(root->left, level + 1, leafLevel) &&
            checkUtil(root->right, level + 1, leafLevel);
}
 
/* The main function to check
if all leafs are at same level.
It mainly uses checkUtil() */
bool check(struct Node *root)
{
    int level = 0, leafLevel = 0;
    return checkUtil(root, level, &leafLevel);
}
 
// Driver Code
int main()
{
    // Let us create tree shown in third example
    struct Node *root = newNode(12);
    root->left = newNode(5);
    root->left->left = newNode(3);
    root->left->right = newNode(9);
    root->left->left->left = newNode(1);
    root->left->right->left = newNode(1);
    if (check(root))
        cout << "Leaves are at same level\n";
    else
        cout << "Leaves are not at same level\n";
    getchar();
    return 0;
}
 
// This code is contributed
// by Akanksha Rai

Time complexity: linear
Space complexity: linear
// C++ program to check if all leaf nodes are at
// same level of binary tree
#include <bits/stdc++.h>
using namespace std;
  
// tree node
struct Node {
    int data;
    Node *left, *right;
};
  
// returns a new tree Node
Node* newNode(int data)
{
    Node* temp = new Node();
    temp->data = data;
    temp->left = temp->right = NULL;
    return temp;
}
  
// return true if all leaf nodes are
// at same level, else false
int checkLevelLeafNode(Node* root)
{
    if (!root)
        return 1;
  
    // create a queue for level order traversal
    queue<Node*> q;
    q.push(root);
  
    int result = INT_MAX;
     int level = 0;
 
    // traverse until the queue is empty
    while (!q.empty()) {
        int size = q.size();
        level += 1;
 
        // traverse for complete level
        while(size > 0){
            Node* temp = q.front();
            q.pop();
         
            // check for left child
            if (temp->left) {
                q.push(temp->left);
 
                // if its leaf node
                if(!temp->left->right && !temp->left->left){
 
                    // if it's first leaf node, then update result
                    if (result == INT_MAX)
                        result = level;
                     
                    // if it's not first leaf node, then compare
                    // the level with level of previous leaf node
                    else if (result != level)
                        return 0;                   
                }
            }
              
             // check for right child
            if (temp->right){
                q.push(temp->right);
 
                // if it's leaf node
                if (!temp->right->left && !temp->right->right)
 
                    // if it's first leaf node till now,
                    // then update the result
                    if (result == INT_MAX)
                        result = level;
                     
                    // if it is not the first leaf node,
                    // then compare the level with level
                    // of previous leaf node
                    else if(result != level)
                        return 0;
                     
               }
               size -= 1;
        }   
    }
     
    return 1;
}
  
// driver program
int main()
{
    // construct a tree
    Node* root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->right = newNode(4);
    root->right->left = newNode(5);
    root->right->right = newNode(6);
  
    int result = checkLevelLeafNode(root);
    if (result)
        cout << "All leaf nodes are at same level\n";
    else
        cout << "Leaf nodes not at same level\n";
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to check if there exist an edge whose
// removal creates two trees of same size
#include<bits/stdc++.h>
using namespace std;
 
struct Node
{
    int data;
    struct Node* left, *right;
};
 
// utility function to create a new node
struct Node* newNode(int x)
{
    struct Node* temp = new Node;
    temp->data = x;
    temp->left = temp->right = NULL;
    return temp;
};
 
// To calculate size of tree with given root
int count(Node* root)
{
    if (root==NULL)
        return 0;
    return count(root->left) + count(root->right) + 1;
}
 
// This function returns true if there is an edge
// whose removal can divide the tree in two halves
// n is size of tree
bool checkRec(Node* root, int n)
{
    // Base cases
    if (root ==NULL)
       return false;
 
    // Check for root
    if (count(root) == n-count(root))
        return true;
 
    // Check for rest of the nodes
    return checkRec(root->left, n) ||
           checkRec(root->right, n);
}
 
// This function mainly uses checkRec()
bool check(Node *root)
{
    // Count total nodes in given tree
    int n = count(root);
 
    // Now recursively check all nodes
    return checkRec(root, n);
}
 
// Driver code
int main()
{
    struct Node* root = newNode(5);
    root->left = newNode(1);
    root->right = newNode(6);
    root->left->left = newNode(3);
    root->right->left = newNode(7);
    root->right->right = newNode(4);
 
    check(root)?  printf("YES") : printf("NO");
 
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// C++ program to check if there exist an edge whose
// removal creates two trees of same size
#include<bits/stdc++.h>
using namespace std;
 
struct Node
{
    int data;
    struct Node* left, *right;
};
 
// utility function to create a new node
struct Node* newNode(int x)
{
    struct Node* temp = new Node;
    temp->data = x;
    temp->left = temp->right = NULL;
    return temp;
};
 
// To calculate size of tree with given root
int count(Node* root)
{
    if (root==NULL)
        return 0;
    return count(root->left) + count(root->right) + 1;
}
 
// This function returns size of tree rooted with given
// root. It also set "res" as true if there is an edge
// whose removal divides tree in two halves.
// n is size of tree
int checkRec(Node* root, int n, bool &res)
{
    // Base case
    if (root == NULL)
       return 0;
 
    // Compute sizes of left and right children
    int c = checkRec(root->left, n, res) + 1 +
            checkRec(root->right, n, res);
 
    // If required property is true for current node
    // set "res" as true
    if (c == n-c)
        res = true;
 
    // Return size
    return c;
}
 
// This function mainly uses checkRec()
bool check(Node *root)
{
    // Count total nodes in given tree
    int n = count(root);
 
    // Initialize result and recursively check all nodes
    bool res = false;
    checkRec(root, n,  res);
 
    return res;
}
 
// Driver code
int main()
{
    struct Node* root = newNode(5);
    root->left = newNode(1);
    root->right = newNode(6);
    root->left->left = newNode(3);
    root->right->left = newNode(7);
    root->right->right = newNode(4);
 
    check(root)?  printf("YES") : printf("NO");
 
    return 0;
}

Time complexity: linear
Space complexity: linear
/* C++ program to check if all three given
   traversals are of the same tree */
#include <bits/stdc++.h>
using namespace std;
 
// A Binary Tree Node
struct Node
{
    int data;
    struct Node *left, *right;
};
 
// Utility function to create a new tree node
Node* newNode(int data)
{
    Node *temp = new Node;
    temp->data = data;
    temp->left = temp->right = NULL;
    return temp;
}
 
/* Function to find index of value in arr[start...end]
   The function assumes that value is present in in[] */
int search(int arr[], int strt, int end, int value)
{
    for (int i = strt; i <= end; i++)
    {
        if(arr[i] == value)
            return i;
    }
}
 
/* Recursive function to construct binary tree
   of size len from Inorder traversal in[] and
   Preorder traversal pre[].  Initial values
   of inStrt and inEnd should be 0 and len -1. 
   The function doesn't do any error checking for
   cases where inorder and preorder do not form a
   tree */
Node* buildTree(int in[], int pre[], int inStrt,
                                      int inEnd)
{
    static int preIndex = 0;
  
    if(inStrt > inEnd)
        return NULL;
  
    /* Pick current node from Preorder traversal
       using preIndex and increment preIndex */
    Node *tNode = newNode(pre[preIndex++]);
  
    /* If this node has no children then return */
    if (inStrt == inEnd)
        return tNode;
  
    /* Else find the index of this node in
       Inorder traversal */
    int inIndex = search(in, inStrt, inEnd, tNode->data);
  
    /* Using index in Inorder traversal,
       construct left and right subtress */
    tNode->left = buildTree(in, pre, inStrt, inIndex-1);
    tNode->right = buildTree(in, pre, inIndex+1, inEnd);
  
    return tNode;
}
 
/* function to compare Postorder traversal
   on constructed tree and given Postorder */
int checkPostorder(Node* node, int postOrder[], int index)
{
    if (node == NULL)
        return index;
  
    /* first recur on left child */
    index = checkPostorder(node->left,postOrder,index);
      
    /* now recur on right child */
    index = checkPostorder(node->right,postOrder,index);   
   
    /* Compare if data at current index in
       both Postorder traversals are same */
    if (node->data == postOrder[index])
        index++;
    else
        return -1;
 
    return index;
}
 
// Driver program to test above functions
int main()
{
    int inOrder[] = {4, 2, 5, 1, 3};
    int preOrder[] = {1, 2, 4, 5, 3};
    int postOrder[] = {4, 5, 2, 3, 1};
 
    int len = sizeof(inOrder)/sizeof(inOrder[0]);
 
    // build tree from given
    // Inorder and Preorder traversals
    Node *root = buildTree(inOrder, preOrder, 0, len - 1);
 
    // compare postorder traversal on constructed
    // tree with given Postorder traversal
    int index = checkPostorder(root,postOrder,0);
 
    // If both postorder traversals are same
    if (index == len)
        cout << "Yes";
    else
        cout << "No";
 
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// C++ code to check if leaf traversals
// of two Binary Trees are same or not.
#include <bits/stdc++.h>
using namespace std;
 
// Binary Tree Node
struct Node {
    int data;
    Node* left;
    Node* right;
};
 
// Returns new Node with data as
// input to below function.
Node* newNode(int d)
{
    Node* temp = new Node;
    temp->data = d;
    temp->left = NULL;
    temp->right = NULL;
 
    return temp;
}
 
// checks if a given node is leaf or not.
bool isLeaf(Node* root)
{
    if (root == NULL)
        return false;
    if (!root->left && !root->right)
        return true;
    return false;
}
 
// iterative function.
// returns true if leaf traversals
// are same, else false.
bool isSame(Node* root1, Node* root2)
{
    stack<Node*> s1;
    stack<Node*> s2;
 
    // push root1 to empty stack s1.
    s1.push(root1);
 
    // push root2 to empty stack s2.
    s2.push(root2);
 
    // loop until either of stacks are non-empty.
    while (!s1.empty() || !s2.empty())
    {
        // this means one of the stacks has
        // extra leaves, hence return false.
        if (s1.empty() || s2.empty())
            return false;
 
        Node* temp1 = s1.top();
        s1.pop();
        while (temp1 != NULL && !isLeaf(temp1))
        {
            // Push right child if exists
            if (temp1->right)
                s1.push(temp1->right);
 
            // Push left child if exists
            if (temp1->left)
                s1.push(temp1->left);
 
            // Note that right child(if exists)
            // is pushed before left child(if exists).
            temp1 = s1.top();
            s1.pop();
        }
 
        Node* temp2 = s2.top();
        s2.pop();
        while (temp2 != NULL && !isLeaf(temp2))
        {
            // Push right child if exists
            if (temp2->right)
                s2.push(temp2->right);
 
            // Push left child if exists
            if (temp2->left)
                s2.push(temp2->left);
            temp2 = s2.top();
            s2.pop();
        }
 
        if (!temp1 && temp2 || temp1 && !temp2)
            return false;
        if (temp1 && temp2 && temp1->data!=temp2->data) {
            return false;
        }
    }
 
    // all leaves are matched
    return true;
}
 
// Driver Code
int main()
{
    Node* root1 = newNode(1);
    root1->left = newNode(2);
    root1->right = newNode(3);
    root1->left->left = newNode(4);
    root1->right->left = newNode(6);
    root1->right->right = newNode(7);
 
    Node* root2 = newNode(0);
    root2->left = newNode(1);
    root2->right = newNode(5);
    root2->left->right = newNode(4);
    root2->right->left = newNode(6);
    root2->right->right = newNode(7);
 
    if (isSame(root1, root2))
        cout << "Same";
    else
        cout << "Not Same";
    return 0;
}
 
// This code is contributed
// by AASTHA VARMA

Time complexity: linear
Space complexity: nlogn
// C++ program to check whether a given Binary Tree is full or not
#include <bits/stdc++.h>
 
using namespace std;
  
/*  Tree node structure */
struct Node
{
    int key;
    struct Node *left, *right;
};
  
/* Helper function that allocates a new node with the
   given key and NULL left and right pointer. */
struct Node *newNode(char k)
{
    struct Node *node = new  Node;
    node->key = k;
    node->right = node->left = NULL;
    return node;
}
  
/* This function tests if a binary tree is a full binary tree. */
bool isFullTree (struct Node* root)
{
    // If empty tree
    if (root == NULL)
        return true;
  
    // If leaf node
    if (root->left == NULL && root->right == NULL)
        return true;
  
    // If both left and right are not NULL, and left & right subtrees
    // are full
    if ((root->left) && (root->right))
        return (isFullTree(root->left) && isFullTree(root->right));
  
    // We reach here when none of the above if conditions work
    return false;
}
  
// Driver Program
int main()
{
    struct Node* root = NULL;
    root = newNode(10);
    root->left = newNode(20);
    root->right = newNode(30);
  
    root->left->right = newNode(40);
    root->left->left = newNode(50);
    root->right->left = newNode(60);
    root->right->right = newNode(70);
  
    root->left->left->left = newNode(80);
    root->left->left->right = newNode(90);
    root->left->right->left = newNode(80);
    root->left->right->right = newNode(90);
    root->right->left->left = newNode(80);
    root->right->left->right = newNode(90);
    root->right->right->left = newNode(80);
    root->right->right->right = newNode(90);
  
    if (isFullTree(root))
        cout << "The Binary Tree is full\n";
    else
        cout << "The Binary Tree is not full\n";
  
    return(0);
}
 
// This code is contributed by shubhamsingh10

Time complexity: linear
Space complexity: linear
// c++ program to check whether a given BT is full or not
#include <bits/stdc++.h>
using namespace std;
 
// Tree node structure
struct Node {
    int val;
    Node *left, *right;
};
 
// fun that creates and returns a new node
Node* newNode(int data)
{
    Node* node = new Node();
    node->val = data;
    node->left = node->right = NULL;
    return node;
}
 
// helper fun to check leafnode
bool isleafnode(Node* root)
{
    return !root->left && !root->right;
}
 
// fun checks whether the given BT is a full BT or not
bool isFullTree(Node* root)
{
    // if tree is empty
    if (!root)
        return true;
 
    queue<Node*> q;
    q.push(root);
 
    while (!q.empty()) {
 
        root = q.front();
        q.pop();
 
        // null indicates - not a full BT
        if (root == NULL)
            return false;
 
        // if its not a leafnode then the current node
        // should contain both left and right pointers.
        if (!isleafnode(root)) {
            q.push(root->left);
            q.push(root->right);
        }
    }
 
    return true;
}
 
int main()
{
    Node* root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->left = newNode(4);
    root->left->right = newNode(5);
 
    if (isFullTree(root))
        cout << "The Binary Tree is full\n";
    else
        cout << "The Binary Tree is not full\n";
 
    return 0;
}
// This code is contributed by Modem Upendra.

Time complexity: linear
Space complexity: linear
// C++ implementation to check whether a binary
// tree is a full binary tree or not
#include <bits/stdc++.h>
using namespace std;
 
// structure of a node of binary tree
struct Node {
    int data;
    Node *left, *right;
};
 
// function to get a new node
Node* getNode(int data)
{
    // allocate space
    Node* newNode = (Node*)malloc(sizeof(Node));
 
    // put in the data
    newNode->data = data;
    newNode->left = newNode->right = NULL;
    return newNode;
}
 
// function to check whether a binary tree
// is a full binary tree or not
bool isFullBinaryTree(Node* root)
{
    // if tree is empty
    if (!root)
        return true;
 
    // queue used for level order traversal
    queue<Node*> q;
 
    // push 'root' to 'q'
    q.push(root);
 
    // traverse all the nodes of the binary tree
    // level by level until queue is empty
    while (!q.empty()) {
        // get the pointer to 'node' at front
        // of queue
        Node* node = q.front();
        q.pop();
 
        // if it is a leaf node then continue
        if (node->left == NULL && node->right == NULL)
            continue;
 
        // if either of the child is not null and the
        // other one is null, then binary tree is not
        // a full binary tee
        if (node->left == NULL || node->right == NULL)
            return false;
 
        // push left and right childs of 'node'
        // on to the queue 'q'
        q.push(node->left);
        q.push(node->right);
    }
 
    // binary tree is a full binary tee
    return true;
}
 
// Driver program to test above
int main()
{
    Node* root = getNode(1);
    root->left = getNode(2);
    root->right = getNode(3);
    root->left->left = getNode(4);
    root->left->right = getNode(5);
 
    if (isFullBinaryTree(root))
        cout << "Yes";
    else
        cout << "No";
 
    return 0;
}

Time complexity: linear
Space complexity: constant