bst

Having issues with Binary Search Trees in C#

I'm having a problem with the following code snippet: using System; using System.Collections.Generic; using System.Text; namespace trees_by_firas { class Program { static void Main(string[] args) { BinarySearchTree t = new BinarySearchTree(); t.insert(ref t.root, 10); t.inser...

Real world examples of tree structures

I'm looking for some examples of tree structures that are used in commercial/free software projects, modern or old. I can see examples on wikipedia, but I am looking for more concrete examples and how they're used. For example primary keys in databases are (from what I've read) stored in BST structure or a variation of the BST (feel free...

Rails BST timezone implementation

Does anyone know how i can use BST for config.time_zone in my rails config/environment.rb file? At the moment i have left it as UTC and i'm thinking of adding BST to the list of supported timezones, and then extending the Time class to respect this (> last sunday of X month + 1hr) Where can i find the list of supported timezones? Sear...

copying a bst to a treeSet

I have to write a method that returns a set of all elements in a bag with no duplicate entries allowed. The data is held in a BST, and I'm trying to do this by using a TreeSet, but I'm having trouble working out how to traverse the tree and add each node's data to the TreeSet. I can only manage the following: Set<E> uniqueSet() { No...

dealing with duplicates in a bst

My bst has to be able to cope with duplicate entries. Does anyone have any strategies for how to go about this that doesn't require excessive amounts of code? I thought of consistently adding duplicates to the right but then that will mess up the bst order. for example what happens when the duplicate has two children who in turn have two...

Proof for depth of balanced search tree

If T is a balanced BST with n elements, L its left subtree and R its right one, how can I prove that its depth is less than or equal to 2log(n) + 1? There is a proof by induction which I have but I don't get it. (I understand that stackoverflow is mainly programming oriented but I found some questions about binary search trees and dec...

permutations of BST

Given an array of integers arr = [5,6,1]. When we construct a BST with this input in the same order, we will have "5" as root, "6" as the right child and "1" as left child. Now if our input is changed to [5,1,6], still our BST structure will be identical. So given an array of integers, how to find the number of different permutations ...

remove method in java BST

Hello everyone...I do have a hw question...I have to write a remove method for a binary search tree, so far what I have is below but I keep getting a bunch of errors associated with my remove method and I'm not sure why...would someone please be able to check my code. Thank You. I also tried to create a find method but I'm having some tr...

Im stuck with filling my Array Based BST in C++

Hello, 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/25327/tree%5Finsert.gif%3A%3ATREE-INSERT. ...using the algorithm I came up with the following code: void BST::insert( const data &aD...

Binary Search Tree C++ (Parents)

Hello. I need just a little more help on my BST. This is what my BST looks like when inserting: R, L, J, G R --Root at Index 0 / \ L @ Index1 L NULL / \ J @ Index3 J NULL / \ G @ Index7 G NULL Here is the code that makes it happ...

How does an insert sort for an array BST work?

I've tried to do it recursively..The parent integer varaible would is like i, conforming to the formula, 2*i +1 for leftChilds and 2*i +2 for the right. void BST::insert(const data &aData) { if ( items[Parent].empty ) { items[Parent].theData = aData; items[Parent].empty = false; } else if ( aData < items[Paren...

Binary Search Tree C++

Im a little confused. Im wondering if an array based Binary Search tree is implemented this way? void BST::insert(item &items, const data & aData ) {//helper function. Parent++; data *new_data = new data(aData); this->insert(*new_data); } // insert a new item into the BST void BST::insert(const data &aData ) { if ( item...

Calculate the DEPTH of a binary search tree?

Original problem: Calculate the number of nodes [SOLVED]. I have another similar problem, and both of these have been killing me for a while now. I can calculate the number of words fine now. Thank you very much for your assistance. The issue is now calculating the summation of depths [the sum of the individual depths for all childre...

Calculate the depth of a binary search tree?

I am having difficulty calculating the summation of depths [the sum of the individual depths for all children of the root] for a given BST. I have the total number of nodes for the tree, and I am trying to calculate the average depth for the tree, requiring I have this depth sum. Recursion and I don't get along very well.. I am finding ...

BST implementation

What's wrong with the following implementation of a binary search tree (BST)? I have been told that it is better to use pointer to a pointer to struct node as an argument in insert function. struct node { int key_value; struct node* left; struct node* right; }; insert(int key, struct node *leaf) { if( leaf == 0 ) { leaf...

why this java code does not work??

I have this code fragment class bst { public node root=null; bst() { root=null; } public void insert(int data) { insert(this.root,data); } private void insert(node ro,int data) { if (ro==null) { print ("root is null"); ro=new node(data); } else if (data>ro.data) insert(ro.right,data); ...

C# Binary Trees and Dictionaries

I'm struggling with the concept of when to use binary search trees and when to use dictionaries. In my application I did a little experiment which used the C5 library TreeDictionary (which I believe is a red-black binary search tree), and the C# dictionary. The dictionary was always faster at add/find operations and also always used les...

Calculate height of a tree

I am trying to calculate height of a tree. I am doint with the code written below. #include<iostream.h> struct tree { int data; struct tree * left; struct tree * right; }; typedef struct tree tree; class Tree { private: int n; int data; int l,r; public: tree * Root; Tree(int x) { n=x; ...

g_tree_insert overwrites all data

I wonder how I should use the GTree (from GLib) to store data? Every new value I insert into GTree with g_tree_insert routine is overwrite the previous one! GTree *tree; //init tree = g_tree_new( g_str_equal ); //"g_str_equal" is a GLib default compare func //... for( i = 0; i < 100; ++i ) g_tree_insert( tree, random_key(), random_v...

Binary Search Tree in C

Hi, I'm a Python guy. Learning C language and I've been trying to implement Binary Search Tree in C. I wrote down the code, and I've been trying from few hours but, not able to get the output as expected. Please help! Please correct me. #include<stdlib.h> #include<stdio.h> typedef int ElementType; typedef struct TreeNode { ElementT...