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.
private Node[] next = new Node[26];
doesn't create any Node instance. It creates a Node[] (array of Node references) of 26 elements. All the references are initialized to null. The Node instances referenced by the array must be initialized elsewhere.
If, on the other hand, you had a member initialized as:
private Node n = new Node ();
that would cause an infinite recursion once the first instance of Node would be created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With