Trees- Find sum at level K (Input format)

PLease explain the input format of this question? What do the 0s represent?
INPUT-
1 2
2 2
3 0
4 0
5 2
6 0
7 0
2
OUTPUT-
20

The input in this question is taken as a generic tree .
It takes the data of the node and the number of children it has .

class node{ //Generic_Tree node structure
int data ;
int noofchildren;
node* childArr;
node(int d,int n)
{ data = d;
noofchildren = n;
childArr = new node[n]; //This creates an array of Node* pointers dynamically
}
};

Ask for the data and no of children in BuildTree()
If no of children = 0 ; then that node is leave node
take for loop for input data recursively for each child node
for eg. in this case
data of root node = 1 , having two children
2 node also has two children

1 Like