mardi 10 mars 2020

Check if a node exists in a n-tree

I have a tree structure like this:

struct Node {
   int Id;
   std::string Name;
   std::vector<Node*>child;
};

How can I check if an Id or a Name exists in the tree? What is the time complexity?

Also, for this type of problem, does it make sense to change the struct to this:

struct Node {
   int Id;
   std::string Name;
   struct Node *first; 
   struct Node *next; 
};

Aucun commentaire:

Enregistrer un commentaire