Professional Documents
Culture Documents
1
Content
Page
Introduction
A- Definition 04
B- Types of binary trees 04
C- Binary Tree Traversals 05
D- Glossary 06
A- Definition 07
B- Performance of balanced binary tree 08
C- Big-O notation 09
D- Glossary 10
A- Definition 11
B- Properties of weight-balanced tree 11
C- Methods of weight-balanced tree 11
D- weight-balanced tree in depth 11
E- Advantages of weight-balanced tree 12
F- Implementation of weight-balanced tree 13
A- Definitions 15
B- Theorem 16
C- Performance 16
References 17
2
INTRODUCTION
There are many books describing data structures around the world. Different
kinds of data structures are there, and some are highly specialized to specific
tasks. In Our work we have mission to report information about weight
balanced binary tree. The binary search tree (BST) data structure is
fundamental to computer science. Many variants of BSTs have been devised so
far. Weight BSTs achieve logarithmic worst-case cost by using th size of the
subtrees as balancing information [13].
3
Chapter i: Binary Trees Foundation
A- Definition
A binary tree is a finite set of elements that is either empty or is partitioned
into three disjoint subsets. [1]
- The first subset contains a single element called the root of the tree.
- The other two subsets are themselves binary trees, called the left and right
subtrees of the original tree. A left or right subtree can be empty.
A Binary tree
B c
D E
F
G H I
There is a basic operation we can do in the tree: Searching, Insertion,
Deletion, Traversal and Sort. [2]
Note that this terminology often varies in the literature, especially with respect
to the meaning "complete" and "full". [2]
4
C- Binary Tree Traversals
A binary tree can be traversed using different algorithms [3]
Let L, V, and R stand for moving left, visiting the node, and moving right.
+ Pre-Order : MPN
+ In-Order : PMN
+ Post-Order : PNM
+ Level-Order : MPN
5
C- Glossary
6
Chapter ii: Balanced Tree Foundation
A- Definition
A balanced tree is a tree which is balanced - it has roughly the same height on
each of its sub-nodes. A balanced tree will have the lowest possible overall
height [7]. A binary tree where no leaf is more than a certain amount farther
from the root than any other [8]. A balanced tree is a sorted collection of
key/value pairs optimized for searching and traversing in order.
A balanced binary tree is a tree that is explicitly kept balanced. It has a lookup
and insertion complexity of O(log(n)), and an accumulative complexity of
O(n*log(n)). All of them worst case!
It turned out to be faster than the sorted array, by about a factor of 2. For more
(maximum) efficiency, a binary search tree stand be balanced.
7
B- Performance of balanced binary tree [10]
Binary search trees provide O(lg n) performance on average for important
operations such as item insertion, deletion, and search operations. Balanced
trees provide O(lg n) even in the worst case
Cons
ider the binary tree, at each level the number of the nodes is doubled. There
are three levels, and the total number of nodes is:
1 + 2 + 22 + 23 = 24 - 1 = 15
In general, if we have a tree with M levels, the number of the nodes would be:
1 + 2 + 22 + …. 2M = 2(M+1) - 1 = 2*2M – 1
We will find now how M (the depth of the tree) depends on the number of the
nodes.
N = 2*2M – 1 --- > 2*2M = N + 1 --- >2M = (N+1)/2
M = log((N+1)/2) = O(logN)
Thus, given a balanced binary tree with N nodes, the height of the tree is
O( log(N)). Given a balanced binary tree with M levels, the number of the
nodes is O(2M)
8
9
C- Big-O notation
Formal Definition: f(n) = O(g(n)) means there are positive constants c and k,
such that 0 ≤ f(n) ≤ cg(n) for all n ≥ k. The values of c and k must be fixed for the
function f and must not depend on n. [16]
10
D- Glossary
Binary Search Tree – is binary tree and the following additional property:
Red-black trees and splay trees, both of which are instances of self-
balancing binary search trees;
Ternary search trees, in which each internal node has exactly three
children;
B trees, commonly used in databases;
B+ trees, like B trees but with all data values stored in the leaves;
van Emde Boas trees, very efficient if the data values are fixed-size
integers.
11
Chapter iii: weight Balanced Binary Tree
A- Definition
A weight-balanced binary tree is a binary tree which is balanced based on
knowledge of the probabilities of searching for each individual node. Within
each subtree, the node with the highest weight appears at the root. This can
result in more efficient searching performance [11].
Also known as BB(α) tree [18]
The weight of the tree is defined as the number of external nodes in the tree
(this equals the number of null pointer in the tree) [1]. If the ratio of the weight
of the left subtree of every node to the weight of the subtre rooed at the node
is between some fraction a and a-1, the tree is a weight balanced tree of ratio a
or is said to be in the class wb[a].
12
D- Advantages of weight-balanced tree
A weight-balanced binary tree has several advantages over the other data
structures for large aggregates:
13
The following table shows a simple BB[alpha] tree (with alpha=1/4) and the
balances of the nodes. [19]
Algorithm traversal
Algorithm delete
14
o If t is null return null
o Else if t.key < key then return t.right receive delete (t.right,key)
o Else if t.key > key then return t.left receive delete(t.left,key)
Deletion if descendant is null
o Else if t.left = null then t receive t.right
o Else if t.right = null then t receive t.left
Deletion if descendant is not null
o Else if wt(t.left)>wt(t.right) then
[t=rrot(t) ; t.right = delete(t.right,key)]
o Else [t=lrot(t) ; t.left = delete(t.left,key)]
Reconstruct weight information
o If t not null then
o t.weight receive wt(t.left)+wt(t.right)
o check(t)
Return(t) // end of program
Notes
o wt is function wich give the weight of node
o rrot and lrot is respectly right and left rotation
o check controlled if the t is weight balanced
Definitions
15
Example of BB[ Alpha ] tree Alpha <= 1/3
Theorem
a)
b)
Performance
Lemma
Let .
16
Let T' be a BB[ Alpha ] tree.
Let T be result of adding (deleting) a node from T'.
Assume that Tl and Tr are BB[ Alpha ] trees.
Assume that T is no longer a BB[ Alpha ] tree.
Then a single or double rotation will balance T
Theorem.
Let . Then there is a constant c such that the total number of
single and double rotations required in a sequence of M insertions and deletions
into an empty BB[ Alpha ] tree is <= cM
For = 3/11 the prove gives the value of c = 19.59
Theorem.
Let . Then insert, access, delete takes O(N) in a BB[ Alpha ]
tree with N leaves
It has been shown that the cost W of a weight balanced binary tree
satisfies the inequalities, H 5 W 5 H + 3, where H is the entropy of the set
of the leaves. For a class of “smooth” distributions the inequalities, H 5 W
5 H + 2, are derived. These results imply that for sets with large entropy
the search times provided by such trees cannot be substantially shortened
when binary decisions are being used.
[3] University of North Texas , CSCE 3110 Data Structures & Algorithm Analysis
[17] Jon Bentley, Programming Pearls: Algorithm Design Techniques, CACM, 27(9):868,
September 1984 for an example of a microcomputer running BASIC beating a
supercomputer running FORTRAN.
[2] http://en.wikipedia.org/wiki/Binary_tree
[4] http://www.laynetworks.com/cs04.htm
[5] http://sites.google.com/site/sumedhshende/binarytrees
[6]http://en.wikipedia.org/wiki/Binary_search_tree
[7] http://wiki.answers.com/Q/What_is_a_balanced_tree_in_data_structures
[8]: http://www.csie.ntu.edu.tw/~wcchen/algorithm/balanceTree/balanced.htm
[9] http://www.itl.nist.gov/div897/sqg/dads/HTML/balancedbitr.html
[10] http://faculty.simpson.edu/lydia.sinapova/www/cmsc250/LN250_Weiss/L07-
Trees.htm
[11] http://en.wikipedia.org/wiki/Weight-balanced_tree
[12] http://en.wikipedia.org/wiki/Search_tree
[13]
http://planetmath.org/encyclopedia/WeightBalancedBinaryTreesAreUltrametric.html
[16] http://www.itl.nist.gov/div897/sqg/dads/HTML/bigOnotation.html
[18] http://www.itl.nist.gov/div897/sqg/dads/HTML/bbalphatree.html
[19] http://www.auto.tuwien.ac.at/~blieb/woop/bbalpha.html
[20] http://www.eli.sdsu.edu/courses/fall95/cs660/notes/BB/BBtrees.html
18