binary-trees

Iterating over binary tree w/o control of stack or dynamic allocation

Is there an efficient, practical way to iterate over a binary tree given the following constraints: You do not have control of the call stack, and thus may not use recursion. All state must live inside the iterator/range object, not on the stack. No heap allocations may be used anywhere in the algorithm. The tree may be immutable, and...

What's A QT Or Open Source C++ Template For Ordinal Sorting

Hi, I am looking for a special template class, hopefully either a QT template or a self-contained open source library. This template class is intended to act as a container for a set of objects. Each object in the set has an integer-valued weight function but the weight function itself is arbitrary. It could range uniformly from 10 to ...

Copy constructor for a binary tree C++

I have a Tree class with the following definition: class Tree { Tree(); private: TreeNode *rootPtr; } TreeNode represents a node and has data, leftPtr and rightPtr. How do I create a copy of a tree object using a copy constructor? I want to do something like: Tree obj1; //insert nodes Tree obj2(obj1); //without modifying obj1. ...

Is a Binary Tree Contained Within Another Binary Tree - C

Hello party people...So I just had an interview that I'm confident I screwed up royally. I had a bunch of questions thrown at me and didn't have enough time to answer the last one. After getting all beginning questions correct, I was asked to write a function that would determine whether a binary tree b is contained within another bina...

What’s An Algorithm or code for the obtaining ordinal position of an element in a list sorted by value in c++

Hi, This is similar to a recent question. I will be maintaining sorted a list of values. I will be inserting items of arbitrary value into the list. Each time I insert a value, I would like to determine its ordinal position in the list (is it 1st, 2nd, 1000th). What is the most efficient data structure and algorithm for accomplishing...

Binary Tree Nodes - Which Way?

For an assignment we were given in Data Structures, we had to create a test class to determine whether the code we were given correctly traversed the binary trees in our test class. These are the 3 constructors for BinaryTreeNode class that was given to us: public BinaryTreeNode(Object theElement, BinaryTreeNode theleftChild, BinaryTre...

traverse a Binary search tree

I am trying to do a preorder traverse ...

Working on a binary search tree

I have insert working, and i have preorder,inorder,and post order working. I am working on retrieveItem where i try to find using a key. Thats when i realize that in my driver file(main()) that my class instance holds no information.( data aData) So, that makes it impossible to do the retrieve. Down in main() i have data aData; Th...

Binary tree search algorithm errors

I have a binary tree that I need to search through. I'm not searching for one specific node of the tree, but rather over every node of the tree to gain information about them. I have a simple recursive search right now, but every time it runs I get a stack overflow error. It's a full binary tree of depth 7... if (curDepth < 6 && !search...

Breadth First Binary Tree Traversal in Scheme

Hello, I am trying to implement a breadth first (level) tree traversal. I'm very close, but I can't figure out how I'm getting duplicates. Any help is much appreciated. Thanks in advance. JR (define (atom? x) (not (pair? x))) ;;Functions to manipulate a binary tree (define (leaf? node) (atom? node)) (define (left node) (cadr node)...

Is there an existing solution to the multithreaded data structure problem?

I've had the need for a multi-threaded data structure that supports these claims: Allows multiple concurrent readers and writers Is sorted Is easy to reason about Fulfilling multiple readers and one writer is a lot easier, but I really would wan't to allow multiple writers. I've been doing research into this area, and I'm aware of ...

Optimizing binary tree inserts to O(1) with hash map for write heavy trees

First of all I assume I've missed something major when thinking about this, but I still wanted to post about it to see if I really didn't miss anything, on with it... I have a pretty write heavy binary tree (about 50/50 between writes and reads), and on the way home today I was thinking about ways to optimize this, especially make the w...

Homework: binary tree - level-order trasversal

hi, is there a way to visit a binary tree from the lowest level to the higher (root) ? not from the root-level to the lowest!!! (and not using the level-order traversal and a stack...!!!) <--- its opposite.. so difficult...thank you! ...

TreeMap memory usage

How can one calculate how much memory a Java TreeMap needs to handle each mapping? I am doing an experiment with 128 threads, each dumping 2^17 longs in its own array. All these 2^24 longs are then mapped to ints (TreeMap<Long,Integer>), each array reference is nulled before moving to the next. That should amount to 128+64 MB for the ...

Printing BFS (Binary Tree) in Level Order with _specific formatting_

Hello, To begin with, this question is not a dup of this one, but builds on it. Taking the tree in that question as an example, 1 / \ 2 3 / / \ 4 5 6 How would you modify your program to print it so, 1 2 3 4 5 6 rather than the general 1 2 3 4 5 6 I'm basically looking for intuitions on the most efficie...

Difficulties with Iterator and Generics in Binary Search Tree Implementation

Hey everyone! I am studying Data Structures in java and I am having difficulty with using generics in Binary Search Trees. For our assignment we are to implement a Binary Search Tree using nodes that contain a parent, left and right node as well as a data value. The data value in our case takes the form of a Pair object. This is what i...

Binary Tree Height

I need a general formula to calculate the minimum height of the binary tree and the maximum height of the binary tree. (not the binary search tree) ...

Binary Search Tree for specific intent

We all know there are plenty of self-balancing binary search trees (BST), being the most famous the Red-Black and the AVL. It might be useful to take a look at AA-trees and scapegoat trees too. I want to do deletions insertions and searches, like any other BST. However, it will be common to delete all values in a given range, or deletin...

Splay tree insertion

Going through some excercises to hone my binary tree skills, I decided to implement a splay tree, as outlined in Wikipedia: Splay tree. One thing I'm not getting is the part about insertion. It says: First, we search x in the splay tree. If x does not already exist, then we will not find it, but its parent node y. Second, we perfor...

Heaps vs. Binary Trees - How to implement?

when implementing a heap structure, we can store the data in an array such that the children of the node at position i are at position 2i and 2i+1. my question is, why dont we use an array to represent binary search trees and instead we deal with pointers etc.? thanks ...