Question about Binary Search Tree? - algorithm

Today, in class my professors said there's a balance binary search tree which I never heard of it before. I would like to know is there a Balance Binary Search tree without rotation?
From my understanding, Balance Binary Search Tree is AVL tree. Besides that I don't think it's possible to build a 'Balance Binary Search Tree'.
But if in case there's a data structure like that, how could I build a 'Balance Binary Search Tree' from a series of random numbers?
Thanks,

The idea behind populating balanced binary search tree using random numbers is like you will be adding nodes to the tree, whose keys are random numbers. When you'll implement a balanced binary search tree, populate it with 100s or 1000s of nodes with random number. The height should be as small as possible - which is the key feature of balanced binary search tree.
There exists balanced binary search trees other than AVL trees (like Red-Black Tree). Search google with balanced binary search tree.

Wikipedia has a nice list of trees at the bottom of any tree related article such as http://en.wikipedia.org/wiki/Self-balancing_binary_search_tree

Related

Comparison between optimal binary search tree and AVL Trees?

I was preparing for my finals and while going through these topics, I got stuck with few queries.
I know that optimal binary Search trees give optimal structure to trees with respect to the frequency of the nodes. The idea is to keep the nodes having higher frequency (and also satisfying the bst properties) at the top for optimal solution.
Whereas Avl are BST which on rotation perform balancing and hence provide a balanced tree but frequencies don't play a role here.
So, my query is if we know that for frequencies of the respective nodes, we come to a optimal bst structure which is of the form :
Eg :
10
\
12
\
14
\
16...And so on
I.e., linked list kind of a structure but it is optimal as frequencies are, for example [15,13,10,4,2..]
But if this is solved with AVL, AVL will balance the tree and form a different structure making it not so optimal for these frequencies.
So, my question is if we know the respective frequencies for the nodes, then applying AVL on such data is not the right choice as compared to optimal binary search tree ?
Is optimal binary search tree a better choice in such situations ?
I would be thankful if anyone can clear this doubt of mine.
Thanks in advance.

Skewed Trees relation to Binary Search Tree

I know what Binary search tree is and I know how they work. But what does it take for it to become a skewed tree? What I mean is, do all nodes have to go on one side? or is there any other combination?
Having a tree in this shape (see below) is the only way to make it a skewed tree? If not, what are other possible skewed trees?
Skewed tree example:
Also, I searched but couldn't find a good solid definition of a skewed tree. Does anyone have a good definition?
Figured out a skewed Tree is the worst case of a tree.
`
The number of permutations of 1, 2, ... n = n!
The number of BST Shapes: (1/n+1)(2n!/n!n!)
The number of skewed trees of 1, 2, ....n = 2^(n-1)
`
Here is an example I was shown:
http://i61.tinypic.com/4gji9u.png
A good definition for a skew tree is a binary tree such that all the nodes except one have one and only one child. (The remaining node has no children.) Another good definition is a binary tree of n nodes such that its depth is n-1.
A binary tree, which is dominated solely by left child nodes or right child nodes, is called a skewed binary tree, more specifically left skewed binary tree, or right skewed binary tree.

Determining if a binary search tree can be constructed by a sequence of splay tree insertions

A splay tree is a type of self-adjusting binary search tree. Inserting a node into a splay tree involves inserting it as a leaf in the binary search tree, then bringing that node up to the root via a "splay" operation.
Let us say a binary search tree is "splay-constructible" if the tree can be produced by inserting its elements into an initially empty splay tree in some order.
Not all binary search trees are splay-constructible. For example, the following is a minimal non-splay-constructible binary search tree:
What is an efficient algorithm that, given a binary search tree, determines whether it is splay-constructible?
This question was inspired by a related question regarding concordance between AVL and splay trees.
More details: I have code to generate a splay tree from a given sequence, so I could perform a brute-force test in O(n! log(n)) time or so, but I suspect polynomial time performance is possible using some form of dynamic programming over the tree structure. Presumably such an algorithm would exploit the fact that every splay-constructible tree of size n can be produced by inserting the current root into some splay-constructible tree of size n-1, then do something to take advantage of overlapping/isomorphic subproblems.

what is the meaning of lookup algorithm?

I am a bit confused a term "lookup algorithm of avl trees". When I have searched this in google, I see so many website with related about b-tree not avl tree.
So, Is b-tree algorithm equal lookup algorithm of avl tree ?
If not, what is "lookup algorithm of avl tree" ? Moreover, what is the meaning of "lookup algorithm"? Please give me a link, of course if possible.
b-tree is a data structure - a generalized binary tree.
A lookup algorithm is an algorithm used to lookup values in the data structure. It is how you decide to find items in the data structure.
An avl tree is a type of b-tree (in the abstract).
The lookup algorithm is just the way that you look through the nodes in the tree to find a specific value.
An AVL tree is a self-balancing binary search tree, so the lookup algorithm of an AVL tree is the exact same as for a binary tree.
A B-tree is not the same thing as a binary tree, so it has a different lookup algorithm. The difference is that in a B-tree each node can have several values and more than two children, so the lookup algorithm follows the same basic principle as for a binary tree, but it's a bit more complex.
AVL tree is kind of balancing in the binary tree. B-tree is abbreviation for "Bayer-tree" - a kind of multinode (exceeding 2) tree. So these algorithms are different, since look-up in B-tree takes also look-up over particular page

Binary tree to Binary Search Tree (BST)

How can you convert Binary Tree to Binary Search Tree with O(1) extra space ?
Converting an unordered binary tree into an ordered binary search tree is trivial, but a bit more difficult to do fast.
Here's a naive implementation that should satisfy your criteria, I will not describe the actual steps to take, just the overall algorithm.
Grab a random leaf node from your existing tree
Unlink the leaf node from your existing tree
Make the node the root of your new binary search tree
Grab another random leaf node from your existing tree
Unlink that node from your existing tree
Find the right spot for, and link the node, into your new binary search tree
Repeat step 4-6 until the original tree is empty
You should require only a few variables, like the parent of the leaf node you're unlinking (unless the nodes has parent-links), the root node of the new tree, and a couple of temporary variables, all within your O(1) space criteria.
This will not produce an optimal binary search tree. For that you need to either sort the nodes before adding them, and adding them in the right order, or use a balancing binary search tree, like a red-black tree or a splay tree.
Convert Binary Tree to a doubly linked list- can be done inplace in O(n)
Then sort it using merge sort, nlogn
Convert the list back to a tree - O(n)
Simple nlogn solution.

Resources