I have a class called TrieNode which has a char key and arrayList of triNode. I am trying to implement a trie.
Structure :

For example the root key is '.' and the children are t,o,s, and p. for the node with key 's', the children are t and p. I want to calculate the number of nodes in the trie. i used this algorithm
public int size(TrieNode tmp, int n){
if(tmp.children.isEmpty()){
return 0;
}
for(int i=0;i<tmp.children.size();i++){
return 1 + size(tmp.children.get(i), n);
}
return 1;
}
the problem is i is not unique for each call. so the method is called on the root then s then it child t then t then o until p. when it returns to s again it doesn't call the method on p.
how to fix this?