C# – Tree Data Structure

cc5data structuresnettree

I am looking for a tree implementation…
you can see the me previous question here.
but I won't like to implement it myself,

example functionalities needed:

  • I need FindElement(node)
  • I need GetParent(node) – will do the find again
  • GetSubTreeFrom(node) – will find the element and return a subtree..

I know C5 – but all the trees there are red-black (and I don't want it to be ordered)
I tried Powercollection didn't find Tree…

I am not sure but maybe Set or Hash can do the job.

any help would be appreciated.

Best Answer

Well an unordered tree isn't much good for anything, generally. Searching, then becomes an O(n) operation, defeating the whole purpose of using a tree to begin with.

Maybe what you need is a tree of trees (of trees of trees....). Each level in the directory can be its own tree. Sub-categories can be a sub-tree member of the parent category node.

I haven't thought this through very well, but with it you can use off the shelf data structures instead of writing your own.