Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Built-in AVL-Tree?

Is there a built in AVL Tree in the .NET libraries?

I searched but didn't find any.

  • If there is, then where? what namespace?
  • If not, is there any good implementation for AVL Trees in C#?
  • If also not! then is there an easy way to get it done? I know how it works and have built one in native C++ before, but now I have no time and am afraid of bad performance if I did it myself.
like image 247
Tamer Shlash Avatar asked Jan 07 '12 09:01

Tamer Shlash


2 Answers

You can use a System.Collections.Generic.SortedSet<T>. I think it is implemented using a red-black tree which is very similar to an AVL tree.

like image 126
Josef Pfleger Avatar answered Oct 17 '22 15:10

Josef Pfleger


A quick search found an implementation here. The code looks clean, but I haven't tried it.

If nothing else, you could do a quick performance test against SortedSet<T> (as suggested by @Josef) to see if there's any difference for your use case.

like image 23
Matthew Strawbridge Avatar answered Oct 17 '22 17:10

Matthew Strawbridge