Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) a) Write a method to create a mirror image of a binary tree. (need complete p

ID: 3543609 • Letter: 1

Question

1) a) Write a method to create a mirror image of a binary tree. (need complete program)

b) Apply preorder(), inorder(), and postorder() to the tree in Figure 6.64 if

visit(p) in IntBSTNode is defined as:

a. if (p.left != null && p.key - p.left.key < 2)

p.left.key += 2;

b. if (p.left == null)

p.right = null;

c. if (p.left == null)

p.left = new IntBSTNode(p.key-1);

d. { IntBSTNode tmp = p.right;

p.right = p.left;

p.left = tmp;

}

Write a method to create a mirror image of a binary tree. (need complete program) Apply preorder(), inorder(), and postorder() to the tree in Figure 6.64 if visit(p) in IntBSTNode is defined as: if (p.left != null && p.key - p.left.key

Explanation / Answer

void mirror(struct node* node)

{

if (node==NULL)

{

return;

}

else

{

struct node* temp;

mirror(node->left);

mirror(node->right);

temp = node->left;

node->left = node->right;

node->right = temp;

}

}



Inorder = 0>4>5>6>7>8>10>13>15>20>30

Preorder = 10>5>4>0>6>7>8>20>15>13>30

PostOrder= 0>4>8>7>6>5>13>15>30>20>10


Inorder

>> we go to left & his left & so on until there is no left child

>> then we read that left chid , then root , then his right chid then go to parent root and its right chid and so on


Preorder

>> In it we traverse reading root first , then its left child , his left chid and so on until there is no left child & then we read right child and vice versa


>>Postorder

In it we traverse reading left child , then right child & in last root.