Академический Документы
Профессиональный Документы
Культура Документы
Introduction
In this laboratory, we implement two types of binary trees, namely, the Binary Search Tree and
the AVL Tree. The purpose of this lab was to analyze the efficiency of searching in each tree
with respect to an element. The binary search simply organizes the elements in order by placing
the either to the left or right – left if smaller and right if bigger. A common issue with the Binary
Tree is that it is often unbalanced for a large quantity of elements. The solution to this problem is
the AVL Tree, the self-balancing Binary Search Tree. Unlike the typical Binary Search Tree, the
AVL Tree keeps track of the height of each sub-tree in order to ensure that the entire tree does
not remain unbalanced. Hence, the advantage of this is that it ensures that the binary tree has
O(log n) search time.
The entire program is structured in multiple classes that encapsulate each aspect of the lab. For
instance the AVL Tree and the Binary Search Tree are each located in their own separate file. In
addition to those files, the project also contains utility methods that help deal with wrong inputs
and exceptions.
There are two parts in this program. First part is when the user is prompted with the first “ n =”.
In this part, the program prints the tree since the user is confined between values of 0 and 100.
Second part consists of n being a greater number, such as 100000. This part of the program does
not print the elements, since it would be too many characters, but it does print out the amount of
seconds each tree took to search for a specific element.
Experimental Results
Both the Binary Search Tree and the AVL Tree were tested for large number of elements. Below
are the results of each tree in the search process:
1000
Time in milliseonds
Binary Search
100 Tree
AVL Tree
10
1
100000
200000
300000
400000
500000
600000
700000
800000
900000
1000000
1100000
1200000
1300000
Input Size
Conclusion
It is conclusive that the use of the AVL Tree is much more beneficial than the typical Binary
Search Tree. Due to its self-balancing property, the AVL Tree can always ensure that the seek
time for a specific element will be around O(log n). Because the Binary Search tree does not
have that ability, it cannot guarantee it.