Data Structures – Tree-Like Structure with Multiple Root Nodes

data structuresjavascala

I'm attempting to implement a data structure, and using a more traditional tree data structure, but I'm not using the root node as it holds no real value in the context I'm using it in.

Ideally, I want to use a structure that is a tree, but that has multiple root nodes (and that is not just a list of trees). Is there a name for a data structure like this?

Best Answer

You don't have one tree with multiple roots, you have a grab bag of separate trees, each with a unique root. In graph theory, a bunch of disconnected trees are called forest. But if the trees don't really belong together, it might be more useful to think of it just as a collection (list, map, etc.) of trees.