I have to solve the following constructor for a BinaryTree class in java:
BinaryTree(GeneralTree<T> aTree)
This method should create a BinaryTree (bt) from a General Tree (gt) as follows:
Every Vertex from gt will be represented as a leaf in bt.
If gt is a leaf, then bt will be a leaf with the same value as gt
If gt is not a leaf...
Hey!
I'm working on an algorithm for Redundant Binary Representation (RBR) where every two bits represent a digit.
I designed the comparator that takes 4 bits and gives out 2 bits. I want to make the comparison in log 2 n so If I have X and Y .. I compare every 2 bits of X with every 2 bits of Y. This is smooth if the number of bits of...
I have multiple binary trees stored as an array. In each slot is either nil (or null; pick your language) or a fixed tuple storing two numbers: the indices of the two "children". No node will have only one child -- it's either none or two.
Think of each slot as a binary node that only stores pointers to its children, and no inherent v...
it would be nice if i could print the binary search trees i am writing onto python console ? any idea how to do it?
...
I need a sorted set of objects and am currently using the TreeSet. My problem is that the compareTo of the objects will often return 0, meaning the order of those two objects is to be left unchanged. TreeMap (used by TreeSet by default) will then regard them as the same object, which is not true.
What alternative to TreeMap can I use?
...
For Binary tree: You no need to consider tree node values, I am interested about different tree topologies with 'N' nodes.
For Binary Search Tree: We obviously consider tree node values.
...
It's a pretty normal binary tree, except for the fact that one of the nodes may be empty.
I'd like to find a way to output it in a horizontal way (that is, the root node is on the left and expands to the right).
I've had some experience expanding trees vertically (root node at the top, expanding downwards), but I'm not sure where to st...
how do i represent binary search trees in python?
...
So I finished my List exercise and went ahead with Binary Trees. My code thus far:
Tree.h
#include "Node.h"
class Tree
{
private:
int mCount;
Node *root;
public:
Tree();
~Tree();
void insert(int, Node *);
};
Tree.cpp
void Tree::insert(int data, Node *node)
{
if( root == 0 )
{
Node *temp = new ...
Hi
is this possible that a node in the complete binary tree has just one child?
thanks
EDIT : this can be a complete binary tree?
23
/ \
12 15
/ \
9 11
/ \ \
10 5 13
...
I'm still working on my binary trees, and the insertion, lookup, maximum, minimum functions are all working great so far. So I want to do a deletion function next. I included a Stack which saves- ah hell, I'll just show the code:
class Tree
{
private:
int value_;
Tree *root_;
Tree *left_;
Tree *right_;
std::stack<Tr...
I have a binary tree. I need to write Java recursive method that will give longest path between two nodes.
For example longest path if following tree is 7 (7-8-5-13-15-18-16-17).
http://img294.imageshack.us/img294/130/treeb.jpg
What's the way to resolve this problem?
(The method: public static int longestPath(Node n) )
...
Hi
This is my homework and I have thought a lot about it but I could not get the answer I need your guidance ,please help me thanks
Q:
we have keys from 1 to 1000 in BST and we want to find the key = 363
which of these following searching is not correct?
<925, 202, 911, 240, 912, 245, 363>
<924, 220, 911, 244, 898, 258...
Hi
is there any clear algorithm that make a red black tree from a binary search tree?
please help me thanks
...
How can I prove that the number of interval nodes in a binary tree with n leaves (where each interval node has two children) is n-1, using induction?
...
Hello,
I've heard some terminology in regards to trees that I haven't heard before. There are some references to graft points in our code base in relation to n-ary trees. What exactly is a graft point in a tree and what could these references be referring to? Thanks!
...
I'm writing a game in which a character moves around on a randomly generated map in real time (as it's revealed.) This leads me an interesting data structures problem. The map is generated as it comes into view, in a circle around the character (probably 20-60 tiles) so where there is data, it is very dense, and all in a grid. Where ther...
Consider the problem of counting the number of structurally distinct binary search trees:
Given N, find the number of structurally distinct binary search trees containing the values 1 .. N
It's pretty easy to give an algorithm that solves this: fix every possible number in the root, then recursively solve the problem for the left a...
template<typename T>
void traverse_binary_tree(BinaryTreeNode<T>* root,int order = 0)// 0:pre, 1:in , 2:post
{
if( root == NULL ) return;
if(order == 0) cout << root->data << " ";
traverse_binary_tree(root->left,order);
if(order == 1) cout << root->data << " ";
traverse_binary_tree(root->right,order);
if(orde...
This is not a homework. Just an interesting task :)
Given a complete binary search three represensted by array. Sort the array in O(n) using constant memory.
Example:
Tree:
8
/ \
4 12
/\ / \
2 6 10 14
/\ /\ /\ /\
1 3 5 7 9 11 13 15
Array:...