Advanced heaps Flashcards

1
Q

Mergable heap methods (5 basic +2 extra)

A

Make-Heap, Insert, Minimum, Extract-Min, Union, Decrease-Key, Delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Binomial tree features (B(k)) (4 features)

A
  1. Built out of two connected B(k-1) trees.
  2. Has 2powk nodes.
  3. Height of k.
  4. At level I there are exactly (k i) nodes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Binomial heap definition

A
  1. A group of binomial trees that maintain the heap property.
  2. At most one binomial tree of a certain degree h.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Binomial heap implementation

A
  1. All the binomial trees roots point to the next one, where the first is the tree with the lowest degree, and last the highest.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Binomial heap similarity

A

Binomial heaps are very similar to the binary counting system. The number of nodes directly corresponds to the binary counting system with correlation to k. Merging two heaps is same to adding to binary numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Binomial heap facts to know (2 facts)

A
  1. the right tree of each node is a root of a tree of one level lower.
  2. 0≀x.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’β‰€x.𝑝.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’βˆ’, the degree of a son node is always at least one less than the father node.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Binomial heap union steps

A
  1. Merge two BH to be one sorted linked list that includes all binomial trees.
  2. Merge every two trees of the same degree until there is a maximum of one treefor a certain degree.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Tree merging cases (4)

A
  1. Current degree is different than next one (π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’β‰ π‘›π‘’π‘₯π‘‘βˆ’π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’) -> increment pointers.
  2. x is first of a 3 same degree trees (π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’=𝑛𝑒π‘₯π‘‘βˆ’π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’=𝑛𝑒π‘₯π‘‘βˆ’π‘₯.𝑠𝑖𝑏𝑙𝑖𝑛𝑔.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’) -> continue.
  3. x is first of two same degree keys (π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’=𝑛𝑒π‘₯π‘‘βˆ’π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’β‰ π‘›π‘’π‘₯π‘‘βˆ’π‘₯.𝑠𝑖𝑏𝑙𝑖𝑛𝑔.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’). and 𝒙.π’Œπ’†π’šβ‰€π’π’†π’™π’•βˆ’π’™.π’Œπ’†π’š -> merge them with x as root.
  4. x is first of two same degree keys (π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’=𝑛𝑒π‘₯π‘‘βˆ’π‘₯.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’β‰ π‘›π‘’π‘₯π‘‘βˆ’π‘₯.𝑠𝑖𝑏𝑙𝑖𝑛𝑔.π‘‘π‘’π‘”π‘Ÿπ‘’π‘’). and 𝒙.π’Œπ’†π’š>π’π’†π’™π’•βˆ’π’™.π’Œπ’†π’š -> merge them with next-x as root.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Binomial-Heap-Insert

A

Insert new Binomial tree and then merge

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Binomial-Heap-Extract-Min

A

Find smallest root (to return). Then for each child left add it as its own tree (in opposite order so that the sort is preserved) and merge all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Binomial-Heap-Decrease-Key

A

Increase the key and then bubble it up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Binomial-Heap-Delete

A

Decrease key to -inf and remove minimum.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Fibonacci heap (idea)

A

A linked list of trees. The pointer to the heap is the smallest root node. Each node has a degree field and a mark to specify if it has lost a child.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fibonacci heap (insert, min, union)

A

When inserting a new element, add the element as a new node. The minimum is pointed to by the heap so it’s easy to get the value. For union, just combine the two root lists but make sure to update the minimum pointer. All done in O(1).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fibonacci heap (extract min)

A

Take all the children nodes and add them to the root list. Then start merging trees with the same degree. The amortized cost is O(logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fibonacci heap (decrease key)

A

If the heap property Is affected, remove the node and it and its sub tree to the root list. Mark the parent, if it is already marked, add it to the root list as well. Do this recursively until reaching an unmarked node or the root of the tree. Amortized cost of O(1)