Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook...

95
Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement from the slides of Prof. Hsin-Hsi Chen (NTU). Chapter 9 Heap Structures
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    216
  • download

    1

Transcript of Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook...

Page 1: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Instructors: C. Y. Tang and J. S. Roger Jang

All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement from the slides of Prof. Hsin-Hsi Chen (NTU).

Chapter 9Heap Structures

Page 2: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Outline

MIN-MAX Heaps Deaps Leftist Trees Binomial Heaps Fibonacci Heaps

Page 3: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

MIN-MAX Heaps

Definition

Page 4: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

MIN-MAX Heaps

Complete binary tree. Set root on a min level. A node x in min level would have

smaller key value than all its descendents. (x is a min node.)

Page 5: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

MIN-MAX Heaps

7

70 40

30 109 15

5045 2030 12

min

max

min

max

Page 6: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

MIN-MAX Heaps

Insertion into a min-max heap

Page 7: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

7

70 40

30 109 15

5045 2030 12

min

max

min

max

5

Page 8: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

7

70 40

30 59 15

5045 2030 12

min

max

min

max

10

Page 9: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

5

70 40

30 79 15

5045 2030 12

min

max

min

max

10

Page 10: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

Check if it satisfies min heap.(Compare with its parent.)If no, move the key of current parent to current position.If yes, skip.

Page 11: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

Initial

Heap={7,70,40,30,9,10,15,45,50,30,20,12}*n=13item=80parent=6

80>10→verify_max(heap,13,80)

7

70 40

30 109 15

5045 2030 12

min

max

min

max

80

Page 12: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

Input

verify_max(Heap,13,80)grandparent=380>40 →heap[13]=heap[3]

i=3grandparent=0

7

70 40

30 109 15

5045 2030 12

min

max

min

max

80

Page 13: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

Input

verify_max(Heap,3,80) → grandparent=null

break;heap[3]=80;

7

70 80

30 109 15

5045 2030 12

min

max

min

max

40

Page 14: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a min-max heap

The time complexity of insertion into a min-max heap with n elements is O(log n). A min-max heap with n elements has O(lo

g n) levels.

Page 15: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

MIN-MAX Heaps

Deletion of min element

Page 16: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

The smallest element is in the root.

We do the deletion as follows:1. Remove the root node and the node

x which is the end of the heap.2. Reinsert the key of x into the heap.

Page 17: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

7

70 40

30 109 15

5045 2030 12

min

max

min

max

Page 18: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

70 40

30 109 15

5045 2030

min

max

min

max

12

Page 19: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

The reinsertion may have 2 cases:

1. No child. (Only one node in the heap)i i

It means the item is the only one element, so it should be at root in heap.

Page 20: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

2. The root has at least one childFind the min value. (Let this be node k.)

a. A item.key≦ heap[k].keyi i

It means the item is the min element, and the min element should be at root in heap.

Page 21: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

b. item.key> heap[k].key and k is child of root.

i

Since k is in max level, it has no descendants.

k

k

i

Page 22: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

c. item.key> heap[k].key and k is grandchild of root.

i

Example (p>i,): We should make sure the node in max level contains the largest key. Then redo insertion to the subtree with the root in red line.

p

k

k

p

i

Page 23: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

Get the min value of the heap.

Move k to the root of this heap.

Swap i and p in case 2c.

Page 24: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

Deletion of min element of a min-max heap with n elements need O(log n) time. In each iteration, i moves down two level

s. Since a min-max heap is a complete binary tree, heap has O(log n) levels.

Page 25: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deaps

Definition

Page 26: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deaps Complete binary tree. Either empty or satisfies the properties

1. The root contains no element.2. The left subtree is a min-heap.3. The right subtree is a max-heap.4. If the right subtree is not empty. Let i be any n

ode in left subtree, and j be the corresponding node in the right subtree. If no, choose the parent one. i_key≦ j_key.

Page 27: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deaps The relation between i and j.

;2/

)(if

;2 1log2

j

nj

ij i

1

2 3

4 65 7

98 1110 12

Ex1:

i=4; j=4+2^(2-1)=6;

Ex2:

i=9; j=9+2^(3-1)=13; j>12 j=6;

Page 28: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deaps

5 45

10 258 40

1915 309 20

Page 29: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deaps

Insertion into a deap

Page 30: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap The insertion steps

1. max_heap(n): Check iff n is a position in the max-heap of the deap.

2. min_partner(n) or max_partner(n) : Compute the min-heap/max-heap node that corresponding to n. ( / )

3. Compare key of i and j to satisfy deap.4. min_insert or max_insert.

1log22 nn 2/)2( 1log2 nn

Page 31: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap

5 45

10 258 40

1915 309 20 4

j

Page 32: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap

5 45

10 258 40

1915 309 20 4

ji

Page 33: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap

5 45

10 258 40

415 309 20 19

Page 34: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap

4 45

5 258 40

1015 309 20 19

Page 35: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap

Step 1. max_heap.

Step 2. min_partner.

Step 3. Compare key of i and j.

Step 4. min_insert or max_insert.

Page 36: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap The time complexity is O(log n) as the

height of the deap is O(log n).

Page 37: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deaps

Deletion of min element

Page 38: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Insertion into a deap The insertion steps

1. Save the last element as temp and remove this node from deap.

2. Find the node with smaller key from the children of removed minimum element and loop down until reaching leaves.

3. Insert temp into the left subtree of deap.

Page 39: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

5 45

10 258 40

1915 309 20temp

Page 40: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

45

10 258 40

1915 309

j

temp:20

i

Page 41: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

8 45

10 25 40

1915 309

j

i

temp:20

Page 42: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

8 45

10 259 40

1915 30

i

temp:20

Page 43: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

8 45

10 259 40

1915 30

i

temp:20

Page 44: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

8 45

10 259 40

1915 3020

Page 45: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

Step 1. Save the min element.

Step 2. Find the node with smaller key.

Step 3. (Exercise 2).

Page 46: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion of min element

The time complexity is O(log n) as the height of the deap is O(log n).

Page 47: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

Definition

Page 48: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees Linked binary tree. Can do everything a heap can do and in th

e same asymptotic complexity. Can meld two leftist tree priority queues i

n O(log n) time. For any node x in an extended binary tree,

let shortest(x) be the length of a shortest path from x to an external node in the subtree rooted at x.

node externalan is if 0otherwise ))}(_()),(_(min{1)( x

ychildrightshortestxchildleftshortestxshortest

Page 49: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

A G

B HC I

ED F J

Two binary trees

Page 50: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Extended binary trees

Leftist Trees

A G

B HC I

ED F J

Page 51: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

The number inside each internal node x is shortest(x).

Leftist Trees

2 2

2 11 1

11 1 1

Page 52: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

DefinitionA leftist tree is a binary tree such that if it is not empty, then for every internal node x: ))(_())(_( xchildrightshortestxchildleftshortest

2 2

2 11 1

11 1 1

Page 53: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

By the definitionLet x be the root of a leftist tree that has n internal nodes.a) 12 )( xshortestn

x

shortest(x)

A binary tree whose shortest height is shortest(x) means for every path from root to leaf has at least shortest(x) nodes.

Such that it has at least 2shortest(x)-1 nodes.

Page 54: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

b) The rightmost root to external node path is the shortest root to external node path.

x

shortest(x)

Base on the definition of leftist tree. ))(_())(_( xchildrightshortestxchildleftshortest

Page 55: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

DefinitionA min-leftist tree (max leftist tree) is a leftist tree in which the key value in each node is no larger (smaller) than the key values in its children (if any).

2

7 50

11 80

13

Page 56: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Leftist Trees

Combination of leftist trees

Page 57: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

The combination step (min-leftist trees)1. Choose minimum root of the two trees, A a

nd B. 2. Leave the left subtree of smaller root (supp

ose A) unchanged and combine the right subtree of A with B. Back to step 1, until no remaining vertices.

3. Compare shortest(x) and swap to make it satisfy the definition of leftist trees.

Page 58: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

Step 1. Choose smaller root and set as a.

Step 2. If a has no right_chlid, set b as a’s right_child. Else, recursively combine a’s right_child and b.

Step 3. Make the combined tree satisfied the leftist tree property.

Page 59: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

2

7 50

11 80

13

5

9 8

12 10

20 1518

Page 60: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

2

7

5011

8013

5

9 8

12 10

20 1518

Page 61: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

2

7

50

11

80

13

5

9

812

1020

15

18

Page 62: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

2

7

50

11

80

13

5

9 8

12 10

20 1518

Page 63: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

2

7

50

11

80

13

5

9 8

12 10

20 1518

2

1

1

1

2

2

1

1111

2

1

1

Page 64: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

2

7

50

11

80

13

5

98

1210

2015 18

2

1

1

1

2

2

1

11 11

2

1

1

Page 65: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of leftist trees

Both insert and delete min operations can be implemented by using the combine operation. Insert: Treat the inserting node as a singl

e node binary tree. Combine with the original one.

Delete: Remove the node can get two separate subtrees. Combine the two trees.

Page 66: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Heaps

Definition

Page 67: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Trees

[Definition] Binomial trees A binomial tree Bk has 2k nodes with heig

ht be k.

Bk

Bk-1

Bk-1

B0 B1 B2 B3

Page 68: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Trees It has nodes at depth i. The ith child of root is the root of subtree

Bi-1. B4

B2B3 B1 B0

Depth 1 : 4 nodes.

Depth 2 : 6 nodes.

Depth 3 : 4 nodes.

)(ki

Page 69: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Heaps

Collection of min (max) trees. The min trees should be Binomial

trees.

10

8 5

3

6

4 15

12

20

30

7

1

16

9

Page 70: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Heaps

The representation of B-heap: Degree: number of children a node has. Child: point to any one of its children. Left_link, Right_link: maintain doubly lin

ked circular list of siblings. The position of pointer a is the min ele

ment.

Page 71: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

Siblings

parent

child

a

pointera

Page 72: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Binomial Heaps

Combination of binomial heaps

Page 73: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

40

Page 74: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

40

Page 75: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 76: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 77: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 78: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 79: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 80: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 81: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 82: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Pairwise combine

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 83: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of binomial heaps

8

10

3

5 4

6

1

7 1612

15 30

20

9

a

20

40

Page 84: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Combination of binomial heaps

The insertion is to combine a single vertex b-heap to original b-heap.

After we delete the min element , we get several b-heaps that originally subtrees of the removed vertex. Then combine them together.

Page 85: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Time complexity

Binomial heaps Leftist trees Actual Amortized

Insert O(log n) O(1) O(1)

Delete min (or max) O(log n) O(n) O(log n)

Meld O(log n) O(1) O(1)

Page 86: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Fibonacci Heaps

Definition

Page 87: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Fibonacci Heaps

Collection of min (max) trees. The min trees need not be Binomial

trees. B-heaps are a special case of F-heaps.

So that what B-heaps can do can be done in F-heaps.

More than that, F-heap may delete an arbitrary node and decrease key.

Page 88: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Fibonacci Heaps

Deletion and Decrease key

Page 89: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion and Decrease key

Deletion

8

10

3

5 4

6

1

7 1612

15 30

20

9

Page 90: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion and Decrease key

Deletion

8

10

3

5 4

6

1

7 16

15 30

20

9

Page 91: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion and Decrease key

Deletion

8

10

3

5 4

6

1

7 16

15 30

20

9

Page 92: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion and Decrease key

Decrease key

8

10

3

5 4

6

1

7 1612

15 30

20

911

Page 93: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion and Decrease key

Decrease key

8

10

3

5 4

6

1

7 1612

11 30

20

9

Page 94: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Deletion and Decrease key

Decrease key

8

10

3

5 4

6

1

7 1612

11 30

20

9

Page 95: Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.

Time complexity

Actual Amortized Insert O(1) O(1)

Delete min (or max) O(n) O(log n)

Meld O(1) O(1)

Delete O(n) O(log n)

Decrease key (or increase)

O(n) O(1)