## sai25590

BAN USER- 0of 0 votes

AnswersReverse a vector or array...

- sai25590 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm - 0of 0 votes

AnswersReverse the left and right sub-tree of a binary tree:

- sai25590 in United States

for example,

I/P:

0 - root

1 - left child of root

2- right child of root

3- left child of node 2

O/P:

0- root

1 - right child of root

2- left child of root

3- right child of node 2| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Algorithm

u can modify when calling recursively:

int isBSTUtil(struct node* node, int min, int max) { if (node==NULL) return(false);

if (node->data<min || node->data>max) return(false);

if(node->left)

isBSTUtil(node->left, min, node->data);

if(node->right)

return isBSTUtil(node->right, node->data+1, max);

}

Clasrufy if i made a mistake!

1) If both trees are empty return false

2) else if both trees are non-empty

a. check data of root nodes

b. check left sub tree recursively

c. check right sub tree recursively

3 Else return false

int sametree(struct node *t1, struct node *t2)

{

if(t1->data == NULL) && (t2->data==NULL))

return 0;

else if(t1->data!=NULL && t2->data!=NULL)

{

return (t1->data == t2->data) &&

sametree( t1->left,t2->left) &&

sametree(t1->right,t2->right);

}

else

return 0;

}

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

- sai25590 October 22, 2017