I will be honest; I have great difficulty understanding how the Itai sentence makes no sense.
Here is the requirement you specified:
I want to write a method that will return a specific node, given the specified Code .
So, Code is unique, as I understand it? Then it didn't hurt to put all of your Node objects in a Dictionary<string, Node> .
In your comments on Itay's answer, you say the following:
I get that the dictionary is a flat index, I still do not understand how this index gets into my hierarchical data structure and returns the correct node.
If you mean that you donβt understand how the dictionary will know where your Node is in the data structure, this is because it is not. Does it matter? You did not indicate in your requirements that you want to know where the node is in the data structure; you specified only that you want to receive node. For this, the dictionary needs to know only where the node is, and not in some completely separate data structure.
To provide a simplified example (and I apologize if I insult your intelligence here, but carrying with me, as this can at least clear up a point for someone else), suppose you had a simple LinkedList<int> containing all unique integers numbers, then you list this list and use it to create a Dictionary<int, LinkedListNode<int>> , assuming you want to quickly find a node based on its value.
Does the dictionary need to know where the node is in the linked list? Of course, not only where he is in memory. After you find your node based on its value in O (1) using the dictionary, you can of course easily traverse the linked list forward or backward using the node itself, which is known to have a linked list containing it.
The same thing with your hierarchical structure, only a little more complicated than a linked list. But the same principle applies.