No, .NET does not contain a binary search tree . It contains a Red-Black Tree , which is a specialized binary search tree in which each node is colored red or black, and there are certain rules that use these colors to keep the tree balanced and allow the tree to guarantee O (logn) search time. The standard binary search tree cannot guarantee these search times.
The class is called SortedSet<T> and was introduced in .NET 4.0. You can see the source code here . Here is a usage example:
// Created sorted set of strings. var set = new SortedSet<string>(); // Add three elements. set.Add("net"); set.Add("net"); // Duplicate elements are ignored. set.Add("dot"); set.Add("rehan"); // Remove an element. set.Remove("rehan"); // Print elements in set. foreach (var value in set) { Console.WriteLine(value); } // Output is in alphabetical order: // dot // net
Muhammad Rehan Saeed Jan 23 '15 at 11:48 2015-01-23 11:48
source share