Is there a built in binary search tree in .NET 4.0, or do I need to build this abstract data type from scratch?

I'm not sure what exactly you mean with 'tree', but you can do binary searchs on the List class.

```
public int BinarySearch( T item );
public int BinarySearch( T item, IComparer<T> comparer );
public int BinarySearch( int index, int count, T item, IComparer<T> comparer );
```

The answer is: No.

There are implementations available though. Take a look at the following link:

Maybe these articles can help:

The C5 collections library (see http://www.itu.dk/research/c5/) includes `TreeDictionary<>`

classes with balanced red-black binary trees. Note: I have not used this library yet, as the work I do needs nothing more that the standard .NET collections.

I think the `SortedSet<T>`

class is what you're looking for.

From this CodeProject article:

It is implemented using a

self-balancing red-black treethat gives a performance complexity ofO(log n)for insert, delete, and lookup. It is used to keep the elements in sorted order, to get the subset of elements in a particular range, or to get theMinorMaxelement of the set.

Thanx to **herzmeister der welten**, I now know there are! I tried it and it really worked!

```
namespace Tree
{
public partial class Form1 : Form
{
private SortedSet<int> binTree = new SortedSet<int>();
public Form1()
{
InitializeComponent();
}
private void Insert(int no)
{
binTree.Add(no);
}
private void Print()
{
foreach (int i in binTree)
{
Console.WriteLine("\t{0}", i);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
Insert(Int32.Parse(tbxValue.Text));
tbxValue.Text = "";
}
private void btnPrint_Click(object sender, EventArgs e)
{
Print();
}
}
}
```

a C# balanced AVL binary tree can be found @ http://code.google.com/p/self-balancing-avl-tree/ .it also implements logarithmic concatenate and split operations

No, .NET does not contain a Binary Search Tree. It does contain a Red-Black Tree which is a specialized kind of Binary Search Tree in which each node is painted red or black and there are certain rules using these colours which keep the tree balanced and allows the tree to guarantee **O(logn)** search times. A standard Binary Search Tree cannot guarantee these search times.

The class is called a SortedSet and was introduced in .NET 4.0.

Similar Questions

Why the search and successor and predecessor returns -1? // BST.cpp : main project file. #include stdafx.h #include <cstdlib> #include <iostream> #define SIZE 10 using namespace std; st

Using Java, is it possible to write a recursive method to find an element in a binary search tree? I say no because of the nature of recursive re-tracing back unless I implemented incorrectly? I have

Good evening all, I've been tasked with designing a function in Python that will build a Binary Search tree. When I walk through the function myself, it seems to make perfect sense and it SHOULD work

I am working on some binary tree algorithms and need a find node with searchindex... function. The design for treenodes is basically class TreeNode { int index; // some identifier TreeNode *left; Tr

Ok, I am trying to get a binary search tree to balance, and I know why it's not working, but I don't know how to fix it. This is what I have for my balancing methods. public void balance(){ if(isEmpt

Can anybody explain the answer for binary search, A binary search tree (BST) is built by inserting tree following values in the given order: 4,25,15,12,20,70,40. The Post Order Traversal will be A. 12

I am developing a binary search tree in java. But i am facing certain difficulties in it. Here is the code class Node { Node left, right; Integer data; Node(Integer d, Node left, Node right) { this.da

I am working on a binary search tree in C++ at the moment and I have reached the stage where I have to write the remove/delete function(using recursive approach, x = change(x)). I have two options: t

I create my tree using a read function, which uses a while loop to retrieve lines from a text file, in that loop I create a node, and then use an insert method to insert the node into the correct plac

I want to search for an item in non-binary tree (any node can have n - children) and exit from recursion immediately. The node in question can be any node, not only leafs. This is my code but i don't

Are there efficient methods for finding the number of all elements less than an element in a binary search tree? I've been trying to find a procedure or implementation in C++, but I haven't been able

I am really confused about finding an element in binary tree. Question : When we say, search an element in binary tree, maximum in this case, do we assume that the tree is sorted??? If not, take a loo

I know that SortedDictionary is a binary search tree (and it can almost do what I need to do!) but I can't figure out how to do everything I need in the correct complexity. So here are the constraints

I'm trying to build a binary search tree given an ArrayList of sorted values. In trying to create the most efficient tree possible I take the middle value, and add it to the tree. Then recursively tak

What does it mean to build a binary search tree by inserting values from left to right starting from an empty tree? The left to right part confuses me..I know how to build one by normally inserting

Studying for a final here soon and I was wondering if creating an optimal binary search tree as asked in the question below is the same as creating a huffman tree given the symbols and frequencies. C

Binary search tree algorithms usually uses recursion and i m having hard time with recursion. This is a code which converts the tree into its mirror image . void mirror_image(struct tree* node1) { if

want to insert element in binary tree. what is wrong in this code. I have a structure with data, left and right as self referencing structure and root as a global variable of type structure initialize

I'm currently trying to implement an immutable BST in clojure. This is my make-tree function: (defn make-tree [v] {:v v :l nil :r nil}) and insertion: (defn insert [tree v] (if (nil? tree) (make-tree

While I was learning Binary search tree(Balanced and unbalanced), I come up with questions which I need to resolve: If I construct a Binary search tree(Not necessary to be balanced) , using n element

I am creating a simple binary search tree.When I am calling the add method using head pointer,changes made in the method are not reflected to this head pointer.It still points null. struct node *add(s

I am working on a school project where we have to implement a polymorphic binary search tree that instead of using null references to empty parts of the tree, uses two classes (NonEmptyTree and Empt

I have to implement a sparse matrix (a matrix that has predominantly zeroes, so you only record values different than 0), but I have to implement it using a binary search tree. EDIT: So now I'm thinki

I've been trying to implement a binary search tree in C for a few hours now, and I narrowed down my main problem to the insertion function, which you see below. What appears to be the problem is that

This is a code that given a root of the binary search tree, is to create its mirror. def mirror(root): if root is None: pass else: mirror(root.left) mirror(root.right) temp = root.left root.left = roo

I am creating a binary search tree class in c#. I am creating the class by deriving from a binary tree class because binary search tree is a kind of binary tree. So i will have most of the common meth

Im trying to build an array based, Binary Search Tree by following the algorithm at: http://highered.mcgraw-hill.com/olcweb/cgi/pluginpop.cgi?it=gif%3A:600%3A:388%3A%3A/sites/dl/free/0070131511/2532

I am writing a function that will remove an entry from a binary search tree that has a given key associated with it. So far I have this for my code: template <typename Item, typename Key = Item>

So this is my first java program, but I've done c++ for a few years. I wrote what I think should work, but in fact it does not. So I had a stipulation of having to write a method for this call: tree.i

I have a problem with insertion in Binary search tree in C. I have the following definition of a binary tree(please ignore line numbers): 40 struct WordBT 41 { 42 char *term; 43 struct WordBT *right;

I'm currently writing a binary search tree to hold a list of songs that I want to be arranged by name. I do the usual recursion, using strcmp to compare the title of the current node of the tree (song

Given a binary search tree, i need to convert it into a doubly linked list(by traversing in zig zag order) using only pointers to structures in C++ as follows, Given Tree: 1 | +-------+---------+ | |

Say I have a binary tree with the following definition for a node. struct node { int key1 ; int key2 ; } The binary search tree is created on the basis of key1. Now is it possible to rearrange the

I am trying to run my Binary Search Tree, I am creating objects of type Employee in my main program which does not seem to give me problems, but when I choose to search for an item in my BST, the prog

For a given binary tree, find the largest subtree which is also binary search tree? Example: Input: 10 / \ 50 150 / \ / \ 25 75 200 20 / \ / \ / \ / \ 15 35 65 30 120 135 155 250 Output: 50 / \ 25

So I have spent many sleepless nights the last two weeks trying to work on what I thought would be a simple program: I am trying to create a Binary Tree from a list of integers in a specific file. The

I tried to search for this but without luck; please let me know if the question has been answered! Assuming I have a binary tree with key-value pairs of the form: t/0: the empty tree t/4: a tree node

for my coursework(binary search tree and hashtables) I would like to make a java program that scans a text file and orders words based on the most frequent words. Something like most popular tags. Exa

Show that every n-node binary search tree is not equally likely (assuming items are inserted in random order), and that balanced trees are more probable than straight-line trees. How is it prove mathe

wanting to write a destructor for binary search tree (its supposed to delete all the nodes in a tree) here is what i got so far virtual ~BST() { BSTNode<Data>* node = root; if (node == NULL){ re

I am trying to write a delete for a binary tree and this is the function I wrote along with my data structure: class node{ public: int value; node* left; node* right; ~node(); }; class tree{ public:

How can I implement a function to delete an element in a binary search tree? This is my tree: data Tree a = Leaf | Node a (Tree a) (Tree a) I know that in case my tree is a Leaf delete :: (Ord a) =&g

I was going through a lecture and it showed some code that prints out a binary search tree recursively like this void printTree(node *t){ if(t!=NULL){ printTree(t->left); cout<<t->key<&

I'm being asked to display a binary search tree in sorted order. The nodes of the tree contain strings. I'm not exactly sure what the best way is to attack this problem. Should I be traversing the tre

So I am working with Binary Search Trees and one method I am having trouble with is a method called stickCt, which basically it will count the number of sticks in a tree and return the number. For it

I have a binary tree with the only condition that there is a single node in the deepest level. The nodes in the tree have the parent property (as well as left, right, data) Is it possible to determine

I need the pseudocode for a C++ that will search through a tree to find the node with the value of “z”. the function is given the root node to the tree to begin with. The tree has the property where e

Introduction I'm building an HTML5 web application that creates a visual representation of a binary search tree from a given list of numbers. Currently, I have an algorithm which calculates the visual

I need to add objects to the Binary search tree and want to write my own compareTo method. How should i go about this. Actually i am trying to implement a custom TreeSet. I am confused where to implem

I wanted to make a dictionary using BST but I did not have any Idea how to store them in the tree struct node { char word[50]; char meaning[256]; struct node *left, *right; }; I started like that but