given a binary tree and two nodes, how do you check if there exist a path between them from the root

0

Do a preorder traversal

if you find anyone of the node then find the other node in the subtree whose root is the first found node.

bool isPresent(node* node,int n){
if(node==NULL)
return false;
if(node->data==n)
return true;
return isPresent(node->left,n)||isPresent(node->right,n);
}
bool isBothNodesinSamePathFromRoot(node* node,int n1,int n2){
if(node==NULL)
return false;
if(node->data==n1)
return isPresent(node,n2);
if(node->data==n2)
return isPresent(node,n1);
return isBothNodesinSamePathFromRoot(node->left,n1,n2)||isBothNodesinSamePathFromRoot(node->right,n1,n2);
}

Maximum complete level of a binary tree

0

Given a binary tree, find the maximum level at which tree is completely filled.

int getMaxCompleteLevel(node* node){
if(node==NULL||!(node->left)||!(node->right))
return 0;
int l=getMaxCompleteLevel(node->left);
int r=getMaxCompleteLevel(node->right);
return 1+min(l,r);
}