binary-trees

Binary Tree Transfer

How to transfer a binary tree (not a balanced tree) across two different systems efficiently, retaining its complete structure? ...

At what level is a given element in a Java TreeSet?

Does anybody know a fast way to detect at what level a given element is in a TreeSet? By level, I mean the depth of this element in the tree, i.e. the number of its ancestors. Background. I use Java's TreeSet class to store my elements. To compare two elements I need to compute some auxiliary information about them. I cannot store this ...

What is the "m-bridge technique" for partitioning binary trees for parallel processing?

How does it work? Please explain in enough detail in English or pseudocode so that I can implement in any language. It is mentioned and briefly described in this paper: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.4.3643&rep=rep1&type=pdf but there isn't enough detail there to implement myself. (the weights in Fig...

Binary Search Trees

This is some code found on wikipedia regarding BST : # 'node' refers to the parent-node in this case def search_binary_tree(node, key): if node is None: return None # key not found if key < node.key: return search_binary_tree(node.leftChild, key) elif key > node.key: return search_binary_t...

C++ superclass Array yet access subclass methods?

i have an accounts class from that i have 3 types of accounts savings, credit, and homeloan. i created a binary search tree to hold all the accounts as type account how do i now access the methods of the subclasses depending on the type of object? have resolved all errors with syntax and codeing but this. been racking my head for 2 d...

PHP Binary Tree for Tournament Bracket

I'm working on developing a tournament bracket for Single Elimination tournaments. However, I cannot seem to get the bracket to display properly. I need an implementation of a 'perfect binary tree' I believe. (or maybe complete since byes are a factor?) Currently, I have this: <?php $teams = 8; $num_rounds = round(log($teams, 2)...

Using Binary Trees to find Anagrams

I am currently trying to create a method that uses a binary tree that finds anagrams of a word inputted by the user. If the tree does not contain any other anagram for the word (i.e., if the key was not in the tree or the only element in the associated linked list was the word provided by the user), the message "no anagram found " gets ...

Finding border of a binary tree

We are given a binary search tree; we need to find out its border. So, if the binary tree is 10 / \ 50 150 / \ / \ 25 75 200 20 / \ / / \ 15 35 120 155 250 It should print out 50 25 15 35 120 155 250 20 150 10. If the binary tree is ...

Traversing and inserting into a weird binary tree [SOLVED]

Ok, I ran into this tree question which LOOKED simple, but started driving me nuts. The tree given is LIKE a binary search tree, but with one difference: For a Node, leftNode.value < value <= rightNode.value. However, (by their omission of any further info, and by their example below) this ONLY applies to the immediate children, no...

Python: binary tree traversal iterators without using conditionals

I am trying to create a module in python for iterating over a binary tree using the 4 standard tree traversals (inorder, preorder, postorder and levelorder) without using conditionals and only using polymorphic method dispatch or iterators. The following examples should work. for e in t.preorder(): print(e) for e in t.postorder(): ...

length of binary tree

What do we mean by length of binary tree - number of nodes, or height of tree? Thank you ...

Best way to select the ith smallest number of a delimited sequence of numbers

Hi everyone. If I am given a certain set of numbers (which I store in a balanced binary search tree for easiness), then I want to answer a query that requires me to inform what is the ith smallest number between [A,B], what would be a fast algorithm to perform that task? Technically I could traverse the tree from the root searching for...

Crazy C++ iterator error - pointer keeps changing!

I'm writing a binary search tree for school, and part of the assignment is to write a find function. Here's my code: typedef BSTIterator<Data> iterator; iterator find(const Data& item) const { BSTIterator<Data> iter = this->begin(); BSTIterator<Data> end = this->end(); while (iter != end) { if (*iter == item) { return it...

Binary tree that stores partial sums: Name and existing implementations

Consider a sequence of n positive real numbers, (ai), and its partial sum sequence, (si). Given a number x ∊ (0, sn], we have to find i such that si−1 < x ≤ si. Also we want to be able to change one of the ai’s without having to update all partial sums. Both can be done in O(log n) time by using a binary tree with the ai’s as leaf node v...

Redrawing Binary Tree Using Given Traversals

Hello, I am not understanding how to draw a Binary Tree give traversals. Could someone explain to me inorder, preorder, and postorder traversals in a more efficient way? For example: Reconstruct the exact BINARY tree given the following traversals: Inorder: 9, 2, 10, 6, 5, 8, 3, 1, 4, 7 Post order: 9, 10, 2, 6, 8, 3, 7, 4, 1, 5 Any h...

Binary Tree, C language

the code is here: http://pastebin.com/9vswg7b0 here is an possible input: Inserir Jose 30264221 15 Inserir Carlos 304 1 Inserir Maria 887745 7 Inserir Paulo -147 -8 Inserir Isabel 7845 38 Inserir Ana 4578 5 Inserir Danilo 5474 4 Inserir Jose 3641 36 Inserir Pedro 1234 1 Remover 4 Remover 1 Remover 12 Buscar 14 Buscar 5 Imprimir in F...

Binary Heap vs (new) B-Heap: Should it be implemented in the CLR/.NET, and where?

The following article discusses an alternative heap structure that takes into consideration that most servers are virtualized and therefore most memory is paged to disk. http://queue.acm.org/detail.cfm?id=1814327 Can (or should) a .NET developer implement a B-Heap data structure so that parent-child relationships are maintained within...

left-right BFS travesal on a binary tree

Hi all, This is not a home work. I was thinking of some new questions in tree traversal and this seems to be very obvious so thought of solving it. Question is very similar to level order traversal like BFS. In BFS, we normally travel left to right in each level of tree, but here if we are travelling left to right at level i then leve...

Binary Tree in C - Troubles

typedef struct node { struct node *leftChild, *rightChild; int value; } bst; void insert(bst* b, int i) { b=malloc(sizeof(b)); b->value=i; b->leftChild = NULL; b->rightChild = NULL; printf("[%i]",b->value); return; } main() { bst* b...

How to tell whether a red-black tree can have X black nodes and Y red nodes or not

Hello everyone, I have an exam next week in algorithms, and was given questions to prepare for it. One of these questions has me stumped though. "Can we draw a red-black tree with 7 black nodes and 10 red nodes? why?" It sounds like it could be answered quickly, but I can't get my mind around it. The CRLS gives us the maximum height ...