Professional Documents
Culture Documents
Case 3
Case 3
Case 3
The Condition fails as the order of B tree is 5, so 4 keys and 5 child should be there. So we going to
split the B- tree into two half
UNIT 4 Page 33
16CS3202 - Data Structures II Yr CSE / III Sem
3.10 Heaps
3.10.1 Binary Heap
Heap is a complete binary tree or a almost complete binary tree in which every parent node be
either greater or lesser than its child nodes.
In this Heap can be MIN or MAX.
MAX Heap in the tree in which each node is greater than or equal to the value of the
children node
MIN Heap in the tree in which each node is lesser than or equal too the value of the
children nodes.
MAX Heap:
In MAX Heap every parent node is greater than or equal to than its child node.
18
13 4
11 10
MIN Heap:
In MIN Heap every parent node is lesser than its children.
13 14
12 20
Parental Property
Parent node being greater or lesser in heap so its called parental property.
Heap having two important property
Heap should satisfy following two conditions.
It should be a complete binary tree or almost a complete binary tree
Its should satisfy the parental property
UNIT 4 Page 34
16CS3202 - Data Structures II Yr CSE / III Sem
18 18
18
13 4 13 4
13 4
11 10
11 10
In A:Binary tree
satisfying properties, its level 2 and 1 but left and right child is present for each level.
10
A B C
In B: Binary tree doesn't satisfying the 2nd property than the leaves at level 3 and level 1 are
not adjacent. So its not complete binary tree.
In C: Binary tree doesn't satisfying the 1st property than 2nd level but only right child is
present.
UNIT 4 Page 35
16CS3202 - Data Structures II Yr CSE / III Sem
18
18 13 4 11 10
13 4
11 10
To insert the element 19 in the given tree
18 18
13 4 13 4
11 10 11 10 19
18
18
13 4
13 19
11 10 19
11 10 4
UNIT 4 Page 36
16CS3202 - Data Structures II Yr CSE / III Sem
18 19
13 19 13 18
11 10 4 11 10 4
19 19
13 18 13 18
4 4 4
11 10 13 4 18 13 18 13 18
11 10 4
11 10 19 11 10 19 11 10
13 18
UNIT 4 11 10 Page 37
16CS3202 - Data Structures II Yr CSE / III Sem
18
13 4
11 10
UNIT 4 Page 38
16CS3202 - Data Structures II Yr CSE / III Sem
Binomial Heap:
A Binomial Heap is a set of Binomial Trees where each Binomial Tree follows Min Heap
property. And there can be at-most one Binomial Tree of any degree.
UNIT 4 Page 39
16CS3202 - Data Structures II Yr CSE / III Sem
(00001101), hence 3 Binomial Trees. We can also relate degree of these Binomial Trees with positions
of set bits. With this relation we can conclude that there are O(Logn) Binomial Trees in a Binomial
b) getMin(H): A simple way to getMin() is to traverse the list of root of Binomial Trees and return
the minimum key. This implementation requires O(Logn) time. It can be optimized to O(1) by
maintaining a pointer to minimum key root.
c) extractMin(H): This operation also uses union(). We first call getMin() to find the minimum key
Binomial Tree, then we remove the node and create a new Binomial Heap by connecting all subtrees of
the removed minimum node. Finally we call union() on H and the newly created Binomial Heap. This
operation requires O(Logn) time.
d) delete(H): Like Binary Heap, delete operation first reduces the key to minus infinite, then calls
extractMin().
e) decreaseKey(H): decreaseKey() is also similar to Binary Heap. We compare the decreases key
reach a node whose parent has smaller key or we hit the root node. Time complexity of decreaseKey()
is O(Logn).
UNIT 4 Page 40
16CS3202 - Data Structures II Yr CSE / III Sem
UNIT 4 Page 41
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 1
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 2
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 3
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 4
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 5
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 6
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 7
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 8
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 9
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 10
16CS3202 - DATA STRUCTURES - NOTES
UNIT 4 Page 11