Please read the following problem and generate a segment of pseudo-code to solve it.
As you are probably aware, a binary tree is a type of hierarchical data structure. Each node contains a value and pointers to two child nodes and a parent. Usually, each child is unique(Fig 1).
Fig. 1. Standard Tree
However, today we are using Mutant Trees, where each child DOES NOT need to be unique (Fig. 2). In other words, a child of Node X might be the same as a child of Node Y. A node can even be its own child. In addition, the Mutant Tree is unidirectional. The child node does not contain a pointer to its parent.
Fig. 2. Standard Tree
Please design a function SumTree( ) that takes in the pointer to the top (parent) node and then returns the sum of all values in the tree. For instance, if the tree looked like Fig.2, I would use the pointer to the top node as the input and the output should be 19. You cannot assume anything about the shape and components of the tree. You only know that each node has 2 children. The children can be any other node on the tree. A node CAN be the child of multiple parents or itself. Listed below is the definition of the Node class (which each element of the tree is a member of). I am not asking you to write actual code, only to sketch out how you the function would work.
class Node {
int Value;
Node* Child1;
Node* Child2;
}
The function signature is:
int SumTree(Node* Parent)