Processing & Properties of Floor and Wall Tiles.pptx
Daa unit 2
1. RED BLACK TREE
Red Black tree is self balancing binary search tree(BST),where every node follows
following rules.
•Every node has a color either Red or Black.
•Root of tree is always black.
•There are no two adjacent red nodes ( A Red node can not have a red parent or Red
child).
•If a node is Red , then both it’s children is Black.
•Every path from root to a Null node has same number of black nodes.
6/10/2017 Abhimanyu Mishra(CSE) JETGI 1
2. Example of Red Black Tree
6/10/2017 Abhimanyu Mishra(CSE) JETGI 2
8
4 17
219
N N
N N N N
3. •Perform standard BST insertion and make the colour of newly
inserted nodes as Red.
Let X be the newly inserted node.
•If X is root , change colour of X as Black.
•Do following if colour of X’s parent is not Black or X is not
root.
1. If X’s uncle is red.
Change colour of parent and uncle as Black.
Colour of grand parent as Red.
Insertion of Red Black Tree
6/10/2017 Abhimanyu Mishra(CSE) JETGI 3
5
3 8
6
8
6
5
3
6
83
5
4. 2.If X’s uncle is Black .It contains four cases for X, X’s parent and grandparent .
6/10/2017 Abhimanyu Mishra(CSE) JETGI 4
i. Left left case
g
p u
x u
gx
p
ii. Left right case
g
p u
x
g
x u
p u
gp
x
ii. Right right case
g
p
u
xg
p
x
u
5. iv. Right left case
Deletion of Red Black Tree
It is fairly complex process. To understand deletion ,notation of double
black is used . When a black node is deleted and replaced by a black child
,the child is marked as double black.
Case 1: X’s sibling is Red.
Case 2: X’s sibling W is Black , and both of W’s children are Black.
Case 3: X’s sibling W is Black ,W’s left child is Red, and W’s right child
is Black.
Case 4: X’s sibling W is Black ,and W’s right child is Red.
6/10/2017 Abhimanyu Mishra(CSE) JETGI 5
g
u p
p
xu
g
x
u
pg
x
8. Binomial Heap
• It is a data structure similar to binary heap but also supporting the operation of
merging two heaps .It is implemented by collection of binomial trees.
Structure of Binomial Heap
A binomial heap is implemented as a set of binomial trees that satisfy the binomial
heap properties:
• Each binomial tree in a heap obeys the minimum-heap property: the key of a node
is greater than or equal to the key of its parent.
• There can only be either one or zero binomial trees for each order, including zero
order.
• The first property ensures that the root of each binomial tree contains the smallest
key in the tree, which applies to the entire heap.
• The second property implies that a binomial heap with n nodes consists of at
most log n + 1 binomial trees. In fact, the number and orders of these trees are
uniquely determined by the number of nodes n: each binomial tree corresponds to
one digit in the binary representation of number n. For example number 13 is 1101
in binary, {display style 2^{3}+2^{2}+2^{0}}, and thus a binomial heap with 13
nodes will consist of three binomial trees of orders 3, 2, and 0 (see figure below).
6/10/2017 Abhimanyu Mishra(CSE) JETGI 8
9. 6/10/2017 Abhimanyu Mishra(CSE) JETGI 9
Example of a binomial heap containing 13 nodes with distinct keys.
The heap consists of three binomial trees with orders 0, 2, and 3.Implementation.
•Insert
Inserting a new element to a heap can be done by simply creating a new
heap containing only this element and then merging it with the original heap.
Due to the merge, insert takes O(log n) time. However, across a series
of n consecutive insertions, insert has an amortized time of O(1) (i.e.
constant).
11. 6/10/2017 Abhimanyu Mishra(CSE) JETGI 11
• Delete
To delete an element from the heap, decrease its key to negative infinity (that is, some
value lower than any element in the heap) and then delete the minimum in the
heap.