Search code examples
data-structurestrie

What is the correct name for this kind of data structure?


I have groups which can have sub-groups. The sub-groups can have their own sub-groups, and so on. There is no limit to the depth of this tree-like structure.

I have been reading about Tries, http://en.wikipedia.org/wiki/Trie. It seems to me that the data structure I am envisaging is similar to a Trie, but with a couple of differences.

Firstly, in my case, values are associated with every node. (For example, the value may be Group Name and Group Description). Although the Trie structure allows for this, I am wondering if there is a more specific name for the variation that has values associated with every node?

Secondly, I have multiple roots. Another way to look at this is that I have a collection of related Tries. Is there a name for a data structure that is a collection of Tries?

I'm trying to implement that in PHP. If you have any tips that would be mighty impressive.

EDIT: I want to be able to 'add', 'edit', 'remove' and 'retrieve' nodes. (No need to for 'move'.) Retrieval will happen very frequently, but not the other actions. I'm not too worried about performance, since this is not the most commonly used part of the overall application.

Thanks!


Solution

  • What you described isn't really a trie. A trie is more like a state machine that associates a key to a value while navigating through parts of the key as nodes.

    You described a generic rooted tree. A simple trie is also a tree. There are trie-like structures that aren't trees. Most things that look like a tree are trees.

    And the collective of trees is called forest.