binary-trees

Perfect matching in a tree

I came across a definition of Perfect matching: a set of edges that touches each node exactly once. However, i didnt really understand the definition. Can somebody give me an example of any such edge. Or may be point me towards some reference that does. I tried to google but it didnt give me any example. ...

Is there a Binary Search Tree implementation in .NET 4?

I'm looking for a built-in Binary Search Tree implementation in .NET 4. Is there one? ...

Numbers in Binary Search Tree(BST) adding to a certain value

Given a BST, is it possible to find two numbers that add up to a given value, in O(n) time and little additional memory. By little additional memory, it is implied that you can't copy the entire BST into an array. ...

Generic datastructures in C

I'm looking into creating a generic BST. Nothing fancy no COTS, but I'm trying to decide the best way to keep track of the type of the void*. Here's the interface for the nodes: typedef struct { void *data; struct TreeNode *left; struct TreeNode *right; } TreeNode; However, when I write add/remove, I'll need to do compariso...

Why Binary Search Trees?

I was reading binary search tree and was thinking that why do we need BST at all? All the things as far as I know can also be achieve using simple sorted arrays. For e.g. - In order to build a BST having n elements, we requires n*O(log n) time i.e. O(nlog n) and lookup time is O(log n). But this thing can also be achieve using array. We ...

Efficient substring searching in Python with MySQL

I'm trying to implement a live search for my website. One that identifies words, or parts of a word, in a given string. The instant results are then underlined where they match the query. For example, a query of "Fried green tomatoes" would yield: SELECT * FROM articles WHERE (title LIKE '%fried%' OR title LIKE '%green%' OR ...

Binary tree, deleting item and reconnecting node

I'm learning data structures and found out that for binary search trees, there are two ways to reconnect node when you delete item. Are those two ways (below) correct? Link to the image to see it non-resized ...

Binary Search Tree Height

I was asked to build a binary search tree after adding about 20 values in a specific order and I finished and found the size to be 16 and the height to be 4. But part (c) of the question asks me to find the Height (after removal) I am unsure what this means and would be grateful if somebody could clarify what this means. ...

Priority Queue with a find function - Fastest Implementation

Hi, I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions will be: insert, del-min and find. I am unsure whether I should use a Heap or a Self-balancing binary search tree. It appears PQs are usually implemented wit...

C++ remove node binary search tree

...

how do I balance my binary tree

Hi, I already have a working binary tree database. Unfortunately, it needs to have the ability to balance itself. I don't want to rewrite the whole thing, I just want to include a function that will balance the tree. Any algorithms or ideas? ...

cannot access protected variable in derived class c++

I have a Binary Search Tree as a derived class from a Binary Tree, right now I am trying to access the root for my recursive functions (which is in the base class). But for some reason I keep getting the error: binSTree.h:31: error: ‘root’ was not declared in this scope Here are my class declarations: base class: template <class T>...

Binary Search Tree- breadthFirst function Call

I have the algorithm for void leveltraversal(ostream& out); but i am not sure how to call it in main () . In my Assignment we are not allowed to change the header file. Is there a way to call it without overloading it? Update: void BST::levelTraversal(ostream& out){ queue<BST::BinNode*> q; BinNode* cur = myRoot; BinNode* top = NUL...

How to create binary tree using STL Set C++

Can anyone tell me how to implement Binary tree using C++ STL set. I have implemented binary tree using structures in C and class in C++ struct binary { int node; struct binary *left; struct binary *right; }; I am not sure about how to implement it using STL set. Actually I don't know how to to represent left and right in...

Pseudo-code for search in binary tree

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 each node has at most two children nodes. Each node has 3 properties: left child, right child, and value. ...

Level-order tree traversal

Hi. I am trying to write a method that will take an IntTree as a parameter and return a Queue with the values of the IntTree in level order. To clarify: an IntTree is a tree with an integer value as its root, and has an IntTree as its left and right subtrees. A note on some methods: value(t) - returns the integer value at the root of t...

Java StackOverflowError while recursively building an array from a binary search tree.

I'm trying to balance a BST by first building an array (inorder) and then rebuild the entire tree from my array. I have: public void toArray(E[] a) { toArray(root, a, 0); } /* * Adds all elements from the tree rooted at n in inorder to the array a * starting at a[index]. * Returns the index of the last inserted element + 1 ...

Chi-Square Test algorithm

Hi all, I'm randomly selecting nodes from a Binary Tree and I have to build a black-box test that proves all nodes have the nearly the same probability of being selected. I'm adapting the Chi-Square test algorithm based on this article http://en.wikibooks.org/wiki/Algorithm_Implementation/Pseudorandom_Numbers/Chi-Square_Test but I'm a ...

Height of a tree with only one node

According to Wikipedia, The height of a tree is the length of the path from the root to the deepest node in the tree. A (rooted) tree with only one node (the root) has a height of zero (or one). I dont get it-is it zero or one (or both)? ...