Related to video

how can we do a preorder kind of traversal in Trie

hello @talhashamim001

it is exaclty same as preorder on n-ary tree.

void preorder(node *root){   
            if(root==NULL){
             return;
           }
          cout<<root->value<<" ";
      
         for(auto k : root->children){
                  preorder(k.second);
          }

}

can you explain?..

node * is root node of trie
so first i m chekcing if it is null or not. if it is null then simply return .

otherwise.
print the root value.

and then call the same preorder function on its children.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.