i was looking into Trie data-structure and came across this piece of code
// R-way trie node
private static class Node {
private Object val;
private Node[] next = new Node[26];
}
i understood the logic, but what i don't get is, to what depth the Node will get initialized ?
you can check complete code at http://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieST.java.html
There is no recursion here.
doesn't create any
Node
instance. It creates aNode[]
(array ofNode
references) of 26 elements. All the references are initialized to null. TheNode
instances referenced by the array must be initialized elsewhere.If, on the other hand, you had a member initialized as:
that would cause an infinite recursion once the first instance of
Node
would be created.