binary-trees

Iterating over a Binary Tree with O(1) Auxiliary Space

Is it possible to iterate over a binary tree in O(1) auxiliary space (w/o using a stack, queue, etc.), or has this been proven impossible? If it is possible, how can it be done? Edit: The responses I've gotten about this being possible if there are pointers to parent nodes are interesting and I didn't know that this could be done, but...

C How to "draw" a Binary Tree to the console

Hi all Im looking for an algorithm( not a library!) i could use to "draw" a binary tree( the tree itself is implemented in C) to the console, so for example a bst with numbers: 2 3 4 5 8 would be shown in the console as : Thanx for all your replyes.... ...

Are empty Binary Search Trees valid?

I have two questions regarding binary search trees, both about empty trees. Is an empty tree (null) valid? Is a root node without children valid? ...

How to create a binary tree

I did'nt mean binary search tree. for example, if I insert values 1,2,3,4,5 in to a binary search tree the inorder traversal will give 1,2,3,4,5 as output. but if I insert the same values in to a binary tree, the inorder traversal should give 4,2,5,1,3 as output. Binary tree can be created using dynamic arrays in which for each eleme...

Binary tree remove method

I am doing some extra work in my computer science class trying to get better at understanding the logic of data structures. Specifically, I am trying to write a remove function for a sorted binary tree: private boolean remove(Node cRoot, Object o) { if (cRoot == null) { return false; } else if (cRoot.item.equals(o)) { //e...

Big O of Hash Table vs. Binary Search Tree

Which would take longer? print all items stored in a binary search tree in sorted order or print all items stored in a hash table in sorted order. It would take longer to print the items of a hash table out in sorted order because a hash table is never sorted correct? and a BST is? ...

insert N items into an empty binary search tree

Why is the worst case big-O for inserting N items into an empty binary search tree n^2? there are no balance checks. ...

Average height of a binary search tree

How do you compute the average height of a binary search tree when adding 1000 random ints? What is the average height? ...

Binary Search Trees

Hi there! I have a question with regards to the Binary Search Tree Implemetation in C++. Here is the question below Implement a simple (non-templated) BST which stores integers. Provide the following operations: Insert, Remove, inOrder traversal, preOrder traversal, postOrder traversal. Use recursive routines for dealing with the tree....

Is this a full binary tree?

Hi, Here's the binary tree in question, poor quality image I know but hopefully it's legible. The leaves are a,b,c,d and the edges are labelled 0 or 1. EDIT: Transcripted tree . / \ a . / \ b . / \ c d It seems to me that it is a full binary tree, as every node is either a leaf or has two child ...

Tree Datastructures

I've tried to understand what sorted trees are and binary trees and avl and and and ... I'm still not sure, what makes a sorted tree sorted? And what is the complexity (Big-Oh) between searching in a sorted and searching in an unsorted tree? Hope you can help me. ...

Is there any map data structure that allows fast merging?

Are there any map data structures that have at least O(log n) insertion, deletion, access, and merging? Most self-balancing binary trees such as AVL trees and red-black trees have most of these properties, but I believe they have O(n log n) merging. Are there any data structures that have faster merging? Edit: I have looked around, and...

What data structure should I use to track dependency?

I have a bunch of tables in a relational database which, obviously, are dependent upon one another due to foreign key relationships. I want to build a dependency tree, traverse it, and output INSERT SQL statements. I need to first output SQL for foreign key tables in my dependency tree first because parent tables will depend on values fr...

Retrieving a Binary-Tree node's depth non-recursively

Can anyone point out a way of getting the depth of a Node in a Binary Tree (not a balanced one, or BST) without using recursion? Ideally in Java/C/C# The node is represented as: class Node { Node Left; Node Right; string Value; int Depth; } Using Level Order with a FIFO list was my first thought, but I was stumped at detectin...

Find whether a tree is a subtree of other

There are two binary trees T1 and T2 which store character data, duplicates allowed. How can I find whether T2 is a subtree of T1 ? . T1 has millions of nodes and T2 has hundreds of nodes. ...

How can i get the leaves in a Binary search tree ?

I want to sum all the values in the leafs in a BST, and i cant get the leafs without running all the tree...:( Thanks Guys, but its only for academic purposes... i didn't want to "pay" O(N) to get the sum of all leafs, but it seems thats the only way. ...

searching a binary tree

I'm writing an iterative function to search a binary tree for a certain value. This is localized to signed ints until I get into how to genericize classes. Assume that my class is BinarySearchTree, and it has a pointer to the root node of the tree. Also assume that nodes are inserted through an insert function, and have pointers to two...

Put into an array the deepest path of a BST (recursive)...

Hello, Im trying to put to an array the deepest path on a BST using a recursive algorithm, and im getting several difficulties... because the only thing that i get is the size of the longest path(equivalent to the height), and i cant put in the array the values regarding to the height of the BST... Can anybody help me ??? Thanks in ad...

How to fix fringe cases in BST delete function?

Assume that my delete tries to rebalance the tree inorder (left to right). I'm writing a BinarySearchTree class currently, and my delete function currently works (I believe - I hope <3) in most cases. I have a few fringe cases to contend with: Deleting the root node won't work, because it has no parent. In the final case where next ha...

Need Binary Tree Control in VB6

Hi, I just need to ask, does anyone have link to free resources where I could get the control to draw a binary tree using VB6. Note that I am not saying regarding TreeView control in VB6. I need a control to draw a binary tree like 1 /\ 2 3 /\ /\ 4 5 6 7 ...