binary-search-trees

Return the difference between the lowest and highest key - Binary Search Tree

This is a past exam paper on binary search trees I am attempting. I have no way to check if the output is correct as I am not capable of building one of these things. The question is in the title class Tree{ Tree left; Tree right; int key; public static int span(Tree tree) { if ( tree == null ){ ...

Help with AA-tree insertion - problems with skew() and split() in loop

Hello all, I am doing an STL-like AA-tree as a personal project and am running into some trouble. Chopping out the loop containing the skew and split functions gives a working and correct unbalanced binary search tree. However, once the loop is included it goes into an infinite loop. I am trying to insert the numbers 0 to 49 and the ske...

represent binary search trees in python

how do i represent binary search trees in python? ...

Is a node in a tree considered its own ancestor?

I'm wondering what the consensus is on the definition of "ancestor" in a computer science context. I only ask because in Introduction to Algorithms, Second Edition, p. 259 there is a description of the algorithm Tree-Successor(x) that seems odd. In finding the successor of node x, [...] if the right subtree of node x is empty and x ...

For a given binary tree find maximum binary search sub-tree

For a given binary tree, largest binary search sub-tree should be found. Example: Input: 10 / \ 50 150 / \ / \ 25 75 200 20 / \ / \ / \ / \ 15 35 65 30 120 135 155 250 Output: 50...

Help with AA-Tree deletion

I am writing a non-recursive AA-Tree that is similar to std::multiset. I was wondering if anybody could notice any problems in my code to rebalance the tree for a deletion. The while loop in erase_rebalance() is going into an infinite loop when erase(iterator first, iterator last) is called. This is leading me to believe that the code to...

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...

Why Binary Search Trees?

I was reading binary search tree and was thinking that why do we need BST at all? All the things as far as I know can also be achieve using simple sorted arrays. For e.g. - In order to build a BST having n elements, we requires n*O(log n) time i.e. O(nlog n) and lookup time is O(log n). But this thing can also be achieve using array. We ...

What are the advantages of binary search trees with all elements stored in the leaf nodes ?

I'm reading Advanced Data Structures by Peter Brass, and in the begining of the chapter on search trees, he stated that there is two models of search trees; one where nodes contain the actual object (the value if the tree is used as a dictionnary), and an other where all objects are stored in leaves and internal nodes are only for compar...

Can a binary search tree be both full and complete?

In preparation for the data structures midterm, the professor gave us last year's test, one question which deals with re-arranging an example tree into a complete binary search tree. I've tried several different versions of writing out the tree, but this complete binary tree example from Wolfram Mathematica didn't help at all, since it ...