Sunteți pe pagina 1din 8

Types of Binary

Search Tree
In Data Structure

Alexandrea Mae Santiago <3


Arch Dorado
Rafael Masallo

Jon Jovi Coronan

Types of Binary Search Trees

Page 1

Define the Following


Balanced tree
*In computer science, a self-balancing (or height-balanced) binary search tree is any
node-based binary search tree that automatically keeps its height (maximal number of
levels below the root) small in the face of arbitrary item insertions and deletions.
These structures provide efficient implementations for mutable ordered lists, and can be
used for other abstract data structures such as associative arrays, priority queues and
sets.
The Red-black tree, which is a type of self-balancing binary search tree, was called
Symmetric binary B-tree and was renamed but can still be confused with the generic
concept of self-balancing binary search tree because of the initials.
*The binary search tree is a very useful data structure, where searching can be
significantly faster than searching into a linked list. However in some cases searching
into a binary tree can be as slow as searching into a linked list and this mainly depends
on the input sequence. Indeed in case the input is sorted the binary tree will seem much
like a linked list and the search will be slow.
Height-balanced
*In computer science, a self-balancing (or height-balanced) binary search tree is any
node-based binary search tree that automatically keeps its height (maximal number of
levels below the root) small in the face of arbitrary item insertions and deletions.
These structures provide efficient implementations for mutable ordered lists, and can be
used for other abstract data structures such as associative arrays, priority queues and
sets.
The Red-black tree, which is a type of self-balancing binary search tree, was called
Symmetric binary B-tree and was renamed but can still be confused with the generic
concept of self-balancing binary search tree because of the initials.
*A tree where no leaf is much farther away from the root than any other leaf. Different
balancing schemes allow different definitions of much farther and different amounts of
work to keep them balanced.

Types of Binary Search Trees

Page 2

Consider a height-balancing scheme where following conditions should be checked to


determine if a binary tree is balanced.
An empty tree is height-balanced. A non-empty binary tree T is balanced if:
1) Left subtree of T is balanced
2) Right subtree of T is balanced
3) The difference between heights of left subtree and right subtree is not more than 1.
The above height-balancing scheme is used in AVL trees. The diagram below shows
two trees, one of them is height-balanced and other is not. The second tree is not
height-balanced because height of left subtree is 2 more than height of right subtree.
Give 1 Example of Perfect Balance and Height Balanced

Types of Binary Search Trees

Page 3

Unbalanced tree
An "unbalanced" tree is one which is lopsided, meaning that some of the leaf nodes
have very high depths and some leaf nodes have very low depths. The most extreme
case of an "unbalanced" tree is a linked list, with the root being one end of the linked list
and the only leaf node being the other end.
Self-balancing tree
*In computer science, a self-balancing (or height-balanced) binary search tree is any
node-based binary search tree that automatically keeps its height (maximal number of
levels below the root) small in the face of arbitrary item insertions and deletions.
These structures provide efficient implementations for mutable ordered lists, and can be
used for other abstract data structures such as associative arrays, priority queues and
sets.
The Red-black tree, which is a type of self-balancing binary search tree, was called
Symmetric binary B-tree and was renamed but can still be confused with the generic
concept of self-balancing binary search tree because of the initials.
Tree rotation
There exists an inconsistency in different descriptions as to the definition of the direction
of rotations. Some say that the direction of a rotation depends on the side which the tree
nodes are shifted upon whilst others say that it depends on which child takes the root's
place (opposite of the former). This article takes the approach of the side where the
nodes get shifted to
In discrete mathematics, tree rotation is an operation on a binary tree that changes the
structure without interfering with the order of the elements. A tree rotation moves one
node up in the tree and one node down. It is used to change the shape of the tree, and
in particular to decrease its height by moving smaller subtrees down and larger subtrees
up, resulting in improved performance of many tree operations.
There exists an inconsistency in different descriptions as to the definition of the direction
of rotations. Some say that the direction of a rotation depends on the side which the tree
nodes are shifted upon whilst others say that it depends on which child takes the root's
place (opposite of the former). This article takes the approach of the side where the
nodes get shifted to.

Types of Binary Search Trees

Page 4

AVL Tree
History of AVL Tree
*A different approach is taken by AVL trees (named after their inventors, Russians G.M.
Adelson-Velsky and E.M. Landis). An AVL tree is a binary search tree that is "almost"
balanced. Recall that the height of a tree is the number of nodes on the longest path
from the root to a leaf. We will say that an empty tree has height 0. With this convention,
the height of a non-empty tree is one greater than the maximum height of its two
subtrees. A binary search tree is an AVL tree if there is no node that has subtrees
differing in height by more than 1.
*In computer science, an AVL tree (Georgy Adelson-Velsky and Evgenii Landis' tree,
named after the inventors) is a self-balancing binary search tree. It was the first such
data structure to be invented.[2] In an AVL tree, the heights of the two child subtrees of
any node differ by at most one; if at any time they differ by more than one, rebalancing
is done to restore this property. Lookup, insertion, and deletion all take O(log n) time in
both the average and worst cases, where n is the number of nodes in the tree prior to
the operation. Insertions and deletions may require the tree to be rebalanced by one or
more tree rotations.
Insertion
To make sure that the given tree remains AVL after every insertion, we must augment
the standard BST insert operation to perform some re-balancing. Following are two
basic operations that can be performed to re-balance a BST without violating the BST
property (keys(left) < key(root) < keys(right)). 1) Left Rotation 2) Right Rotation
After inserting a node, it is necessary to check each node starting with the subject node
and advancing up to the root for consistency with the invariants of AVL trees: this is
called "retracing". This is achieved by considering the balance factor of each node,
which is defined as the difference in heights of the left and right subtrees. Thus the
balance factor of any node of an AVL tree is in the integer range [-1,+1]. This balance
factor is stored in the node, but may have to be corrected after an insertion or a
deletion, which is also done during retracing. Since with a single insertion the height of
an AVL subtree cannot increase by more than one, the temporarily recomputed balance
factor of a node after an insertion will be in the range [2,+2]. For each node checked, if
the recomputed balance factor remains in the range [1,+1] no rotations are necessary.
However, if the recomputed balance factor becomes less than 1 or greater than +1, the
subtree rooted at this node is unbalanced, and a rotation is needed.

Types of Binary Search Trees

Page 5

Deletion
To make sure that the given tree remains AVL after every deletion, we must augment
the standard BST delete operation to perform some re-balancing. Following are two
basic operations that can be performed to re-balance a BST without violating the BST
property (keys(left) < key(root) < keys(right)). 1) Left Rotation 2) Right Rotation
Search
The binary search tree T is a decision tree, where the question asked at an
internal node v is whether the search key k is less than, equal to, or greater than the key
stored at v.
Searching for a key in an AVL tree can be done the same way as that of a normal
unbalanced binary search tree.

Give 1 Example of AVL Tree and explain

The sub-trees of every node differ in height by at most one. Every sub-tree is an AVL
tree.

Types of Binary Search Trees

Page 6

Splay Trees
A splay tree is a self-adjusting binary search tree with the additional property that
recently accessed elements are quick to access again. It performs basic operations
such as insertion, look-up and removal in O(log n) amortized time.
What is Trees?
In computer science, a tree is a widely used abstract data type (ADT)--or data structure
implementing this ADT--that simulates a hierarchical tree structure, with a root value and
subtrees of children with a parent node, represented as a set of linked nodes.
Give 3 examples of Advantages and Disadvantages
The Advantages are Quick search,Quick inserts and Quick deletes but Disadvantages is
Deletion algorithm is complex

Give 1 example
o Zig Step
o Zig-Zig Step
o Zig-zag Step

Types of Binary Search Trees

Page 7

What is Heap?
In computer science, a heap is a specialized tree-based data structure that satisfies the
heap property: If A is a parent node of B then the key of node A is ordered with respect
to the key of node B with the same ordering applying across the heap.
Give the algorithm of Heap
Upheap: The upheap process is used to add a node to a heap. When you upheap a
node, you compare its value to its parent node; if its value is less than its parent node,
then you switch the two nodes and continue the process. Otherwise the condition is met
that the parent node is less than the child node, and so you can stop the process. Once
you find a parent node that is less than the node being upheaped, you know that the
heap is correct--the node being upheaped is greater than its parent, and its parent is
greater than its own parent, all the way up to the root.

Downheap: The downheap process is similar to the upheaping process. When you
downheap a node, you compare its value with its two children. If the node is less than
both of its children, it remains in place; otherwise, if it is greater than one or both of its
children, then you switch it with the child of lowest value, thereby ensuring that of the
three nodes being compared, the new parent node is lowest. Of course, you cannot be
assured that the node being downheaped is in its proper position -- it may be greater
than one or both of its new children; the downheap process must be repeated until the
node is less than both of its children.
Give 1 example of Heap

Types of Binary Search Trees

Page 8

S-ar putea să vă placă și