## binary-trees

### Expression Evaluation and Tree Walking using polymorphism? (ala Steve Yegge)

This morning, I was reading Steve Yegge's: When Polymorphism Fails, when I came across a question that a co-worker of his used to ask potential employees when they came for their interview at Amazon. As an example of polymorphism in action, let's look at the classic "eval" interview question, which (as far as I know) was brough...

### Red-Black Trees

I've seen binary trees and binary searching mentioned in several books I've read lately, but as I'm still at the beginning of my studies in Computer Science, I've yet to take a class that's really dealt with algorithms and data structures in a serious way. I've checked around the typical sources (Wikipedia, Google) and most descriptions...

### Persistent Binary Tree / Hash table in .Net

Hi, I need a pure .Net persistent hashtable/binarytree, functionally similar to berkeley-db Java edition. Functionally it should opperate in a similar maner to a DHT such memcached and velocity etc but it doesn't have to be distributed. In essence I am looking for a persistent hashtable. Does anyone have any ideas or suggestions? A ...

### Shortest Root to Leaf Path

What is the easiest way, preferably using recursion, to find the shortest root-to-leaf path in a BST (Binary Search Tree). Java prefered, pseudocode okay. Thanks! ...

### Balancing a Binary Tree (AVL)

Ok, this is another one in the theory realm for the CS guys around. In the 90's I did fairly well in implementing BST's. The only thing I could bever get my head around was the intricacy of the algorithm to balance a Binary Tree (AVL). Can you guys help me on this? ...

### C++ Recursive Traversals with Function Pointers

template <class T> void BT<T>::inOrder(void (*inOrderPtr)(T&)) { inOrderPtr(inOrder(this->root)); } template <class T> void BT<T>::inOrder(Node<T>* root) const { if (root->left != NULL) inOrder(root->left); //something here if (root->right != NULL) inOrder(root->right); } Ok I am trying to create t...

### C++ Binary Search Tree Insert via Recursion

So my code is below. I'm not getting any errors and it places everything in the node just fine. But based on my debug statements Everytime anything is inserted it's finding the root. I'm not sure if that is right. But according to output file for the assignment, my answers are different when it comes to the height of the tree, the tr...

### How is Wikipedia's example of an unbalanced AVL tree really unbalanced?

The image above is from "Wikipedia's entry on AVL trees" which Wikipedia indicates is unbalanced. How is this tree not balanced already? Here's a quote from the article: The balance factor of a node is the height of its right subtree minus the height of its left subtree and a node with balance factor 1, 0, or -1 is considered bala...

### Skip Lists -- ever used them?

I'm wondering whether anyone here has ever used a skip list. It looks to have roughly the same advantages as a balanced binary tree, but is simpler to implement. If you have, did you write your own, or use a pre-written library (and if so, what was its name)? ...

### iterative version of recursive algorithm to make a binary tree

Given this algorithm, I would like to know if there exists an iterative version. Also, I want to know if the iterative version can be faster. This some kind of pseudo-python... the algorithm returns a reference to root of the tree make_tree(array a) if len(a) == 0 return None; node = pick a random point from the array c...

### Skip List vs. Binary Tree

I recently came across the data structure known as a Skip list. They seem to have very similar behavior to a binary search tree... my question is - why would you ever want to use a skip list over a binary search tree? ...

### What is an "internal node" in a binary search tree?

I'm scouring the internet for a definition of the term "Internal Node." I cannot find a succinct definition. Every source I'm looking at uses the term without defining it, and the usage doesn't yield a proper definition of what an internal node actually is. Here are the two places I've been mainly looking: http://planetmath.org/encyclop...

### Definition of a binary search tree

Hey guys, I'm trying to find the definition of a binary search tree and I keep finding different definitions everywhere. Some say that for any given subtree the left child key is less than or equal to the root. Some say that for any given subtree the right child key is greater than or equal to the root. And my old college data struc...

### prolog recursively find largest node

Just a simple binary tree and i want to find the the largest node. example tree: t(t(t(nil,1,nil),2,t(nil,3,nil)),4,t(t(t(nil,8,nil),5,nil),6,t(nil,7,nil))) int L(t,max) { if(t=null) return max; if(max<t.root) max = t.root; LN(t,max); RN(t,max); return max; } L(tree,tree.root); I just cant wrap my head around applying it to prolog. He...

### Java TreeMap sorting options?

I've been told that the java class TreeMap uses an implementation of a RB tree. If this is the case, how does one do an inorder, preorder and postorder tree-walk on a TreeMap? Or is this not possible? ...

### Want to save binary tree to disk for "20 questions" game

In short, I'd like to learn/develop an elegant method to save a binary tree to disk (a general tree, not necessarily a BST). Here is the description of my problem: I'm implementing a game of "20-questions". I've written a binary tree whose internal nodes are questions and leaves are answers. The left child of a node is the path you'd...

### Using a Binary Search Tree as a spell checker

Wondering the most efficent way to make a binary search tree into a spell checker by reading in say 1000 word dictionary file and then having it check another document that say has a couple paragraphs. ...

### Implementing a tree from scratch

Hello everyone, I'm trying to learn about trees by implementing one from scratch. In this case I'd like to do it in C# Java or C++. (without using built in methods) So each node will store a character and there will be a maximum of 26 nodes per node. What data structure would I use to contain the pointers to each of the nodes? Basica...

### Binary Trees vs. Linked Lists vs. Hash Tables

I'm building a symbol table for a project I'm working on. I was wondering what peoples opinions are on the advantages and disadvantages of the various methods available for storing + creating a symbol table. I've done a fair bit of searching and the most commonly recommended are binary trees or linked lists or hash tables. I was wonderi...

### BST C# Code with errors

Hi, I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to 'int' // on findmin Cannot implicitly convert type x.Program.TreeNode' to 'int' // on findmax and is my main correct or missing somethin? and how i can count the nodes,leaves and get the hight (need only hints) class Program { ...