Download d-heaps

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Quadtree wikipedia , lookup

B-tree wikipedia , lookup

Interval tree wikipedia , lookup

Red–black tree wikipedia , lookup

Binary search tree wikipedia , lookup

Lattice model (finance) wikipedia , lookup

Transcript
d-heaps
d-heap—
5-heap
children of node in position i are in positions
parent of node in position i is in
advantages
disadvantages
Leftist Heaps
operations
A leftist heap
The null path length (x) denoted npl(x)
Nodes in the tree below are labeled with their null path lengths.
Leftist Heap operations
Basic operation: merge
H1 and H2 are leftist heaps
1.
2.
3.
Example:
Other leftist heap operations
Insert
What will the tree look like if the keys are inserted in decreasing
order: 9, 7, 5, 3, 1?
inserting keys in increasing order: 3, 5, 7, 9, 11, 13
The Delete Min Operation
Leftist heap merge
merge1(H1, H2: PRIORITY_Q): PRIORITY_Q
// Recursive function to merge two leftist heaps. The root of H1 is
smaller than the root of H2. When merge is called it determines
which heap has the smaller root value and then calls merge1. p.
232 Weiss Data Structures and Algorithm Analysis in C++ 2nd Ed.
Begin
if (H1^.left = null) then // H1 is a single node
H1^.left  H2
else begin
H1^.right  merge(H1^.right, H2)
if (H1^.left^.npl < H1^.right^.npl) then
swap(H1^.left, H1^.right);
H1^.npl  H1^.right^.npl + 1
end
return(H1)
end
Skew Heaps
Binomial Heaps
A binomial heap is a data structure for which
A binomial heap is a forest of heap-ordered trees satisfying:
1.
2.
3.
Height 0
Height 1
Height 2
Observations about the trees
a.
b.
c.
Height 3
Binomial heap operations
Merging two binomial heaps
H 1:
H 2:
Step 1: Merge trees of height 0 to get
Step 2: Choose one of the trees of height 1 to go into the result
and merge the other two. (The choice is arbitrary.)
Step 3: We now have two trees of height 2 so merge them.
Insertions and Deletions
H 1:
H 2:
1st step
2nd step
Complexity of building a binomial heap of size n
TW(n) =
3rd step
Delete min Complexity
Implementation
Considerations in deciding the representation:
1.
2.
3.
One implementation solution