# A Study of Balanced Search Trees Brainstorming a New Balanced

Document Sample

```					A Study of Balanced Search Trees:
Brainstorming a New Balanced Search Tree

Anthony Kim, 2005

Computer Systems Research
Abstract

This project investigates three different balanced
thus ultimately their efficiency. Run time and
memory space management are two main aspects
under the study. Statistical analysis is provided to
distinguish subtle differences if there is any. A new
balanced search tree is suggested and compared with
the four balanced search trees under study,.
Balanced search trees are implemented in C++
extensively using pointers and structs.
Introduction

● A simple binary search tree has some
disadvantages, specifically from its dependence on
the incoming data, that significantly affects its tree
structure hence its performance. (Ex. linear tree)
● An optimal search tree is one that tries to minimize

its height given some data. (Ex. Red-black tree has
2lg(n+1) height max)
● Some of balanced search trees are red-black tree,

AVL tree, weight-balanced tree, and B tree.
Background

● Simple vocabs: nodes, edges, children, parent, root
● Printing tree using recursion: pre-, in-, and post-

order traversal
● Basic binary search tree functions: insertion,

lookup, deletion (only first two apply in this project)
● Rotating functions: the key player in balancing

(Left rotation and right rotation.)
Some Balanced Search
(Red-black tree)
● Four properties
● The root of the tree is colored black.

● All paths from the root to the leaves agree on the

number of black nodes.
● No path from the root to a leaf may contatin two

consecutive nodes colored red.
● Every path from a node to a leaf (of the

descendants) has the same number of black nodes
● Has height at most 2lg(n+1)
Some Balanced Search Tree
(Weight & height balanced search tree.)

● Weight balanced tree and height balanced tree are
very similar.
● Weight balanced tree (Height balanced tree) has

one property
● At each node, the difference between

weight(height) of left subtree and weight(height)
of right subtree is less than the threshold value.
●Supposedly yield height lg(n) at most
A New Balanced Search Tree
Median-weight-mix tree
● Assumption on statistical data
● Give lower bound and upper bound of total data

input, random behavior is assumed, meaning data
points will be evenly distributed throughout the
interval
● Multiple “crests” is assumed to be present in the

interval.
● Each node will have a key (data number), an

interval (with lower and upper bounds of its
assigned interval) and weights of left subtree and
right subtree.
A New Balanced Search Tree
Median-weight-mix tree

●   Algorithm
● The weights of each subtree are calculated based

on constants R and S
● R = the importance of focusing frequency heavy

data points
● S = the importance of focusing frequency weak

data points
● Left/right rotations to balanced R to S ratio
Testing Methodology
●   14 Randomly generated test cases (test case size
ranges 20 – 10,000)
●   4 Real test scores of math competition etc.
●   Things I am looking for
–   Total Run Time
–   Average Time Retrieval
–   Height of Tree
–   Average Retrieval Depth
Test Runs (Height-balanced Tree)
Results
Total Run Time
Average retrieval time
Test Case       Redblack       Height          Weight       MWM          Test Case       Redblack       Height              Weight          MWM
1              0              0             0           0                1              0                  0               0                  0
2              0              0             0           0                2              0                  0               0                  0
3   N/A                       0             0           0                3   N/A                           0               0                  0
4   N/A                     0.01            0           0                4   N/A                           0               0                  0
5   N/A                     0.01        0.04            0                5   N/A                           0         0.000001                 0
6   N/A                     0.01            0         0.01               6   N/A                           0               0                  0
7   N/A                     0.01            0         0.02               7   N/A                     0.000002              0                  0
8   N/A                     0.01        0.02          0.02               8   N/A                     0.000002              0            0.000004
9   N/A                     0.02        0.02          0.02               9   N/A                           0               0                  0
10      N/A                     0.03        0.02          0.05            10     N/A                     0.000001        0.000002           0.000001
11      N/A                     0.03        0.04          0.05            11     N/A                     0.000002        0.000001           0.000001
12      N/A                     0.03        0.04          0.05            12     N/A                     0.000002        0.000002           0.000001
13      N/A                     0.04        0.04          0.05            13     N/A                     0.000002        0.000002           0.000001
14      N/A                     0.03        0.04          0.05            14     N/A                     0.000001        0.000002                 0
101                 0              0             0           0            101                0                  0               0                  0
102                 0              0             0           0            102                0                  0               0                  0
103      N/A                     0.08        0.41    N/A                  103     N/A                 0.0000007         0.00000086   N/A
104             0.02             0.02        0.05          0.02           104        0.000181        0.00000089                 0          0.00000093
Results
Depth
Average Retrieval Depth

Test Case         Redblack          Height        Weight        MWM        Test Case        Redblack         Height             Weight             MWM
1              3.5               2.35               2.35            2.35
1                 7             4             4          4
2            5.68                 3.9               5.08            4.42
2                12             6             9          7
3   N/A                          4.85               5.44            5.31
3   N/A                         8            10         10
4   N/A                          7.01              8.684           7.422
4   N/A                        11            16         13
5   N/A                         8.217             11.823           8.821
5   N/A                        12            24         14
6   N/A                        9.2445             13.721          9.9635
6   N/A                        13            29         17
7   N/A                       10.3778             14.674         12.0244
7   N/A                        14            31         20                8   N/A                       10.4804              14.52         11.6468
8   N/A                        14            31         19                9   N/A                       10.4662            15.1646         11.6474
9   N/A                        15            38         18               10   N/A                       11.5749            18.5899         13.2171
10   N/A                        16            38         23               11   N/A                       11.5864            15.6778         13.0158

11   N/A                        16            37         22               12   N/A                       11.6456            16.4298         13.1199

12   N/A                        16            37         22               13   N/A                       11.6748            16.5699         13.3742

13   N/A                        16            36         23               14   N/A                       11.5393            17.7741         13.1296
101            49.0291             4.87379            8.50971         5.18932
14   N/A                        16            33         24
102            18.5625                 4.4               4.55          4.7375
101               101             7            18          9
103      N/A                   0.000765942       0.00065652     N/A
102                38             6             8          7
104            2368.98             1.68751            2.70135         2.62517
103   N/A                        16            42   N/A

104              5596            13            24         12
Result
●   Total run time and average retrieval time data did
not make any sense.
●   Hard to time processes on fast computers
●   Red-black tree segmentation faulted for large test
cases >500, so it provided no experimental data
Result (Height)
Height

40
y = 5.3315Ln(x) - 12.735
35
30
25                         y = 2.9492Ln(x) - 5.1306
Height

20
15
10                          y = 1.8939Ln(x) - 1.517
5
0
0   2000    4000        6000      8000        10000   12000
Data size

Height     Weight    MWM
Result (Average retrieval depth)
Average Retrieval Depth

20
y = 2.3718Ln(x) - 4.9972
15                             y = 1.7446Ln(x) - 3.0532
Depth

10
y = 1.4998Ln(x) - 2.2646

5

0
0     2000       4000       6000      8000         10000   12000
Data size

Redblack    Height    Weight    MWM
Analysis
●   All balanced search trees show logarithmic
characteristics for height and average retrieval
depth as expected. (except red-black tree)
●   Height-balanced tree seems to perform the best
among three working balanced search trees.
●   Median-weight-mix tree’s logarithmic line lies
between height-balanced tree’s line and weight-
balanced tree’s line.
Conclusion
●   The project experimentally showed that balanced
binary search trees show logarithmic
characteristics.
●   Median-weight-mix tree’s performance is an
intermediate between height-balanced tree’s and
weight-balanced tree’s.
●   More studies should be done on other balanced
search trees or variants of search trees studied in
this project

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 0 posted: 6/19/2013 language: English pages: 17