fibonacci heap in daa, Essays (university) of Design and Analysis of Algorithms

fibonacci heap easy explanation

Typology: Essays (university)

2018/2019

Uploaded on 10/08/2019

Pravsl
Pravsl 🇮🇳

5

(1)

4 documents

1 / 89

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Last updated on Sep 8, 2013 7:00 AM
Copyright © 2013 Kevin Wayne
http://www.cs.princeton.edu/~wayne/kleinberg-tardos
FIBONACCI HEAPS
preliminaries
insert
extract the minimum
decrease key
bounding the rank
meld and delete
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59

Partial preview of the text

Download fibonacci heap in daa and more Essays (university) Design and Analysis of Algorithms in PDF only on Docsity!

Last updated on Sep 8, 2013 7:00 AM

Copyright © 2013 Kevin Wayne

h t t p : / / w w w. c s. p r i n c e t o n. e d u / ~ w a y n e / k l e i n b e r g - t a r d o s

FIBONACCI HEAPS

‣ preliminaries

‣ insert

‣ extract the minimum

‣ decrease key

‣ bounding the rank

‣ meld and delete

Ahead. O (1) INSERT and DECREASE-KEY, O (log n ) EXTRACT-MIN. Priority queues performance cost summary operation linked list binary heap binomial heap Fibonacci heap † MAKE-HEAP (^) O (1) O (1) O (1) O (1) IS-EMPTY O (1) O (1) O (1) O (1) INSERT (^) O (1) O (log n ) O (log n ) O (1) EXTRACT-MIN (^) O ( n ) O (log n ) O (log n ) O (log n ) DECREASE-KEY (^) O (1) O (log n ) O (log n ) O (1) DELETE (^) O (1) O (log n ) O (log n ) O (log n ) MELD (^) O (1) O ( n ) O (log n ) O (1) FIND-MIN (^) O ( n ) O (1) O (log n ) O (1) † amortized

Fibonacci heaps Theorem. [Fredman-Tarjan 1986] Starting from an empty Fibonacci heap, any sequence of m INSERT, EXTRACT-MIN, and DECREASE-KEY operations involving n INSERT operations takes O ( m + n log n ) time. History. Ingenious data structure and application of amortized analysis. Original motivation: improve Dijkstra's shortest path algorithm from O ( m log n ) to O ( m + n log n ). Also improved best-known bounds for all-pairs shortest paths, assignment problem, minimum spanning trees.

SECTION 19.

FIBONACCI HEAPS

‣ structure

‣ insert

‣ extract the minimum

‣ decrease key

‣ bounding the rank

‣ meld and delete

Set of heap-ordered trees. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: structure heap-ordered tree each child no smaller than its parent root heap H

Set of heap-ordered trees. Set of marked nodes. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: structure min used to keep trees bushy (stay tuned) 39 18 heap H^ marked 26

Node representation. Each node stores: A pointer to its parent. A pointer to any of its children. A pointer to its left and right siblings. Its rank = number of children. Whether it is marked. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: representation min 39 18 heap H children are in a circular doubly-linked list 26 rank = 3

Operations we can do in constant time: Determine rank of a node. Find the minimum element. Merge two root lists together. Add or remove a node from the root list. Remove a subtree and merge into root list. Link the root of a one tree to root of another tree. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: representation min 39 18 heap H 26 rank = 3

Potential function. 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: potential function min 39 18 Φ(H) = 5 + 23 = 11 trees(H) = 5 marks(H) = 3 heap H Φ( H ) = trees( H ) + 2 ⋅ marks( H ) 26

SECTION 19.

FIBONACCI HEAPS

‣ preliminaries

‣ insert

‣ extract the minimum

‣ decrease key

‣ bounding the rank

‣ meld and delete

Create a new singleton tree. Add to root list; update min pointer (if necessary). 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: insert 21 insert 21 min heap H 39 18 26

Actual cost. ci = O (1). Change in potential. ∆Φ = Φ( Hi ) – Φ( Hi– 1 ) = +1. Amortized cost. ĉi = ci + ∆Φ = O (1). 23 7 30 17 35 26 46 24 39 18 52 41 3 44 Fibonacci heap: insert analysis min heap H 21 39 18 Φ( H ) = trees( H ) + 2 ⋅ marks( H ) 26 one more tree; no change in marks

Linking operation Useful primitive. Combine two trees T 1 and T 2 of rank k. Make larger root be a child of smaller root. Resulting tree T ' has rank k + 1. 39 18 52 41 3 77 44 56 24 15 tree T 1 tree T 2 39 18 52 41 3 44 77 56 24 15 tree T' still heap-ordered 33 33

Delete min; meld its children into root list; update min. Consolidate trees so that no two roots have same rank. Fibonacci heap: extract the minimum 39 18 52 41 3 44 23 17 30 7 35 26 46 24 min 2626