Group4 Binary Search Tree
Group4 Binary Search Tree
Definition
This is a class of binary tree in which the node are arrange in a specific order,
this is also called ordered binary tree.
Binary Search Tree (BST), the value of all the node in left sub tree is less than
the node in the right sub tree is greater or equal to the value of the root the
shape of the binary search dependence entirely on the order of insertion or
the value of the nodes.
Example: Draw the binary search tree when the node are added in this order
(11, 6, 8, 19, 4, 10, 5, 17)
Solution
11
6 19
43
4 8
31 49
7 10
5
There has been a lot of research to prevent degeneration of the tree resulting
in worst case fame complexity of 0(n) of details see section types
Binary Search Tree support there main operations deletion of elements and
lookup checking weather a key is present
Searching
Searching in binary search tree for a specific key can be programmed
recursively or interactively
We begin by examine the root node. If the tree is null the key we are searching
for does not exist
In the tree otherwise if the key equal that of the not the search is successful
and we return the node. If the key is less than that of the root, we search the
left sub tree
Insertion
Insertion begin as a search would begin let see how a typical binary search
tree insertion in c++
Void insert (Node & another way to explain insertion is that in order to insert
a new code in the tree its key is first compared with that of the root if its key is
less then the roots it is then compared with the key of the root’s left could if
the key is greater it as compared with the root’s right word
Deletion
1. Deleting a node with no children simply remove the node from the tree
2. Deleting a node with no child
3. Deleting a node with two children
Traversal
Once binary search tree has been created its elements can be retrieved in-
order by recursively traversing the left sub tree of the root node, accessing the
node itself then recursively traversing the right sub tree of the node,
continuing the pattern with each node in the tree as if recursively accessed
Verification
Sometimes we already have a binary tree and we need to determine whether
it is BST this problem has a simple recursive solution
BST Properties
1. Every node on the right sub tree has to be larger than the current node
2. Every node on the left subs tree has to be smaller the current node
These are the key to figure out whether a tree is a BST or root
Example of Applications
Types of BST
1. AVL tree and red-black trees are both forms of self-balancing binary
search trees a splay tree is a binary search that automatically moves
frequently accessed demands nearer to the root. In a treap (tree heap),
each node also holds a (randomly chosen) priority and the parent node
has higher priority than its children tango trees are trees optimized for
fast searches
2. T-trees are binary search trees optimized to reduce storage space
overhead, widely used for in-memory databases
Performance Comparisons
Tree rotations are very common internal oprations in birnary trees to keep
perfect, or near to perfect, internal balance in the tree.
Basic operation of BST
1. Search
2. Insert
3. Pre-ordered transversal
4. Transversal – post order
5. In-order – transversal
Properties of BST
1. The tree has a root node date is used as the starting point for any
operation
2. Each node in the tree has one or two nodes attached to it one is to the
night of the node, and the other is to the left
3. Everything to the right of the node is larger in value compared to it
everything to the left of a node is smaller in value compared to CTL
The main valuable property of BST is that they store data in a way that
is easy for search when data is in a BST we can use the property of left
and right nodes to determine where a node we are searching for is likely
to be it takes less time to search BST compared to searching through a
list of value one by one
References