# 3) Design a recursive algorithm to verify that every node in a binar

Content type
User Generated
Rating
Showing Page:
1/3
3) Design a recursive algorithm to verify that every node in
a binary search tree maintains the searchability condition
(left child smaller, right child greater) for all nodes.
4) Two trees, T1 and T2, are isomorphic if T1 can be
transformed into T2 by swapping left and right children of
(some of the) nodes in T1. For instance, the two trees
below are isomorphic because they are the same if the
children of A, B, and G, but not the other nodes, are
swapped. Create a polynomial time algorithm to check if
two trees passed as input are isomorphic. What is the
overall run time of your algorithm?
Solution
int validBST(struct node* node, int minimum, int maximum)
{
// BST is empty
if (node==NULL)
return 1;
//as this node voilates the maximum and minimum exit the
function with zero
if (node->data < minimum || node->data > maximum)
return 0;

Showing Page:
2/3
checking the subtree of the parent node recursively
return
validBST(node->left, minimum, node->data-1) &&
validBST(node->right, node->data+1, maximum);
}
bool IsomorTree(node* node1, node *node2)
{
if (node1 == NULL && node2 == NULL)
return true;
if (node1 == NULL || node2 == NULL)
return false;
if (node1->data != node2->data)
return false;
return
(IsomorTree(node1->left,node2->left) &&
IsomorTree(node1->right,node2->right))||
(IsomorTree(node1->left,node2->right) &&
IsomorTree(node1->right,node2->left));
}

Showing Page:
3/3

Unformatted Attachment Preview
3) Design a recursive algorithm to verify that every node in a binary search tree maintains the searchability condition (left child smaller, right child greater) for all nodes. 4) Two trees, T1 and T2, are isomorphic if T1 can be transformed into T2 by swapping left and right children of (some of the) nodes in T1. For instance, the two trees below are isomorphic because they are the same if the children of A, B, and G, but not the other nodes, are swapped. Create a polynomial time algorithm to check if two trees passed as input are isomorphic. What is the overall run time of your algorithm? Solution Answer 3: int validBST(struct node* node, int minimum, int maximum) { // BST is empty if (node==NULL) return 1; //as this node voilates the maximum and minimum exit the function with zero if (node->data < minimum || node->data > maximum) return 0; checking the subtree of the parent node ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

### Review

Anonymous
I was struggling with this subject, and this helped me a ton!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4