binary-trees

C++ design question on traversing binary trees

I have a binary tree T which I would like to copy to another tree. Suppose I have a visit method that gets evaluated at every node: struct visit { virtual void operator() (node* n)=0; }; and I have a visitor algorithm void visitor(node* t, visit& v) { //do a preorder traversal using stack or recursion if (!t) return; v(t); v...

binary search tree recursive subtree in java

Can anyone point me to a code example (java preferably) or psuedocode that uses recursion to return a subtree that contains all nodes with keys between fromKey and toKey. So if I was to call Tree.subtree(5,10) it should return all nodes in the BST that have keys between 5 and 10 inclusive - but I can't use loops or helper methods...only...

Finding height in Binary Search Tree

Hey I was wondering if anybody could help me rework this method to find the height of a binary search tree. So far my code looks like this however the answer im getting is larger than the actual height by 1, but when I remove the +1 from my return statements its less than the actual height by 1? I'm still trying to wrap my head around re...

How to Implement a Binary Tree in Python

Which is the best data structure that can be used to implement Binary Tree in Python? ...

Effects of changing a node in a binary tree

Suppose I want to change the orange node in the following tree. So, the only other change I'll need to make is in the left pointer of the green node. The blue node will remain the same. Am I wrong somewhere? Because according to this article (that explains zippers), even the blue node needs to be changed. Similarly, in this picture...

Nth largest element in a binary search tree

How to find the Nth largest node in a BST? Do I keep a count variable while doing In Order Traversal of a BST? Return the element when the count = N??? ...

Binary Search Tree Implementation

I've searched the forum, and tried to implement the code in the threads I found. But I've been working on this real simple program since about 10am, and can't solve the seg. faults for the life of me. Any ideas on what I'm doing wrong would be greatly appreciated. BST.h (All the implementation problems should be in here, and this has ...

How to count the number of right children in a binary tree?

How to count the number of right children in a binary tree? This means that I only want the children marked as right. Ex. (Left | Right) F(Root) G | H T U | I J The right children would be U,H,and J. What would be the algorithm to find these. ...

How do I remove the leaves of a binary tree?

I'm trying to remove all of the leaves. I know that leaves have no children, this is what I have so far. public void removeLeaves(BinaryTree n){ if (n.left == null && n.right == null){ n = null; } if (n.left != null) removeLeaves(n.left); if (n.right != null) removeLeaves(n.right); } ...

What is the best algorithm to use in creating binary trees??

I've been doing a research about the best algorithm to use in creating a binary tree implementation. THe top entry in my list is nested sets. Are there any other alternative or better algorithm?? If possible can you give me a list of top algorithms so that I can research/study it and see if it will fit the system needs. ...

Java Binary Tree. Priting InOrder traversal

I am having some problems printing an inOrder traversal of my binary tree. Even after inserting many items into the tree it's only printing 3 items. public class BinaryTree { private TreeNode root; private int size; public BinaryTree(){ this.size = 0; } public boolean insert(TreeNode node){ if( ro...

How to add add node in binary tree

(5)Root (3)-------^--------(7) (2)---^----(5) ^-----(8) i want to add node with data 5 in this binray tree....Please help.....i really stuck in it ...

Paged binary trees vs. AVL trees and/or B-trees

How are paged binary trees different from AVL trees and/or B-trees? ...

Haskell Binary Tree Function (map)

How can i define a Haskell function which will apply a function to every value in a binary tree? So i know that it is similar to the map function - and that its type would be: mapT :: (a -> b) -> Tree a -> Tree b but thats about it... ...

Pseudo LRU tree algorithm.

A lot of descriptions of Pseudo LRU algorithms involve using a binary search tree, and setting flags to "point away" from the node you're searching for every time you access the tree. This leads to a reasonable approximation of LRU. However, it seems from the descriptions that all of the nodes deemed LRU would be leaf nodes. Is there a ...

Persistent (purely functional) Red-Black trees on disk performance

I'm studying the best data structures to implement a simple open-source object temporal database, and currently I'm very fond of using Persistent Red-Black trees to do it. My main reasons for using persistent data structures is first of all to minimize the use of locks, so the database can be as parallel as possible. Also it will be eas...

How to generate and encode (for use in GA), random, strict, binary rooted trees with N leaves?

First, I am an engineer, not a computer scientist, so I apologize in advance for any misuse of nomenclature and general ignorance of CS background. Here is the motivational background for my question: I am contemplating writing a genetic algorithm optimizer to aid in designing a power divider network (also called a beam forming network,...

Tree + Recursion..

Hi.. I came across an article on Binary Trees Search . It uses intensive Recursive Algorithms.. I am just so confused with these stuff.. Please guide my path so as I understand these problems at ease, or any good website to read about recursion first and then solving these problems.. Please share your experience on it.. Its very urge...

adding nodes to a binary search tree randomly deletes nodes

Hi, stack. I've got a binary tree of type TYPE (TYPE is a typedef of data*) that can add and remove elements. However for some reason certain values added will overwrite previous elements. Here's my code with examples of it inserting without overwriting elements and it not overwriting elements. the data I'm storing: struct data { int n...

Minimum and maximum height of binary search trees, 2-3-4 trees and B trees.

Hi, Can anyone please tell me how you find the min/max height of B trees, 2-3-4 trees and binary search trees? Thanks. PS: This is not homework. ...