Hello party people...So I just had an interview that I'm confident I screwed up royally. I had a bunch of questions thrown at me and didn't have enough time to answer the last one.
After getting all beginning questions correct, I was asked to write a function that would determine whether a binary tree b is contained within another binary tree a. I coded the question prior to that correctly, in which he asked me to write a function to determine whether two trees are equal:
int sameTree(struct node *a, struct node *b){
//both empty = TRUE
if(a == NULL && b == NULL)
return TRUE;
//both not empty, compare them
else if(a != NULL && b != NULL){
return(
a->data == b->data &&
sameTree(a->left, b->left) &&
sameTree(a->right, b->right)
);
}
//one empty, one not = FALSE
else
return FALSE;
}
Ugh. Just for clearing my conscience, again how would you determine whether tree b is inside tree a?
Thanks for any help guys.