What is a Generic Tree?

How is generic Tree different from a normal tree and how do I build it?

1 Like
    10
         /   /    \   \
        2  34    56   100
       / \        |   / | \
      77  88      1   7  8  9

generic tree
binary tree can have 2 children only but generic tree(n-ary tree can have ā€˜n’ children)
sample input for this question is explained below
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
or you can refer this https://ide.codingblocks.com/s/65512

Thank you! @AASTHA011