c# – Is there a binary tree in .NET?

Question:

I don't know if it's hidden somewhere and I haven't seen a binary tree structure in .NET.

I looked in the documentation for the entire Collection , including the sublevels and nothing. Don't you have it? Why wouldn't I have something so important?

Answer:

Binary tree tends to have problems with locality of reference, so use is avoided. The .NET Framework and Core tries to provide only the most useful structures and let each one provide the others, especially if you consider that there are several ways to implement a binary tree, .NET could not deliver all necessary.

In fact there is even a binary tree in .NET, but this is considered a detail of the implementation of structures that guarantee a certain commitment, nothing guarantees that it will be a binary tree. It is better to give solutions than specific structures. See SortedDictionary . There is also the SortedList .

There are some ready-made implementations, perhaps the best known being PowerCollections (I hope they will migrate to GitHub, there are those who put it ) and C5 . Perhaps you will find one that is useful for your need there. Otherwise you have to look for others or do your own implementation.

Scroll to Top