Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why storing data only in the leaf nodes of a balanced binary-search tree?

I have bought a nice little book about computational geometry. While reading it here and there, I often stumbled over the use of this special kind of binary search tree. These trees are balanced and should store the data only in the leaf nodes, whereas inner nodes should only store values to guide the search down to the leaves.

The following image shows an example of this trees (where the leaves are rectangles and the inner nodes are circles).

illustration of a binary search tree

I have two questions:

  1. What is the advantage of not storing data in the inner nodes?

  2. For the purpose of learning, I would like to implement such a tree. Therefore, I thought it might be a good idea to use an AVL tree as the basis, but is it a good idea?

Any kind of helpful resource is very welcome.

like image 790
philipp Avatar asked Mar 01 '13 17:03

philipp


People also ask

In which tree is data can be only stored in leaf node?

B+ Tree is an extension of B Tree which allows efficient insertion, deletion and search operations. In B Tree, Keys and records both can be stored in the internal as well as leaf nodes. Whereas, in B+ tree, records (data) can only be stored on the leaf nodes while internal nodes can only store the key values.

Why is it important for a binary search tree to remain balanced?

Balancing the tree makes for better search times O(log(n)) as opposed to O(n). Show activity on this post. As we know that most of the operations on Binary Search Trees proportional to height of the Tree, So it is desirable to keep height small. It ensure that search time strict to O(log(n)) of complexity.

How many leaf nodes are in a balanced binary tree?

The maximum number of nodes in a full binary tree is 2h+1 -1. The number of leaf nodes is always one more than the number of internal nodes i.e. L = T + 1. The minimum height of a full binary tree is log2(n+1) – 1. The minimum number of nodes in a full binary tree is 2*h-1.

What is the advantage of storing multiple keys in a node?

It requires a bit more memory - one more pointer per data node - and also adds a small amount of complexity to inserts. This type of structure is great when you want to find a continuous range of items starting at some arbitrary value.


1 Answers

What is the advantage of not storing data in the inner nodes?

There are some tree data structures that, by design, require that no data is stored in the inner nodes, such as Huffman code trees and B+ trees. In the case of Huffman trees, the requirement is that no two leaves have the same prefix (i.e. the path to node 'A' is 101 whereas the path to node 'B' is 10). In the case of B+ trees, it comes from the fact that it is optimized for block-search (this also means that every internal node has a lot of children, and that the tree is usually only a few levels deep).

For the purpose of learning, I would like to implement such a tree. Therefore, I thought it might be a good idea to use an AVL tree as the basis, but is it a good idea?

Sure! An AVL tree is not extremely complicated, so it's a good candidate for learning.

like image 152
vlad Avatar answered Sep 17 '22 08:09

vlad