fibonacci heaps

Click here to load reader

Post on 30-Jan-2016

24 views

Category:

Documents

4 download

Embed Size (px)

DESCRIPTION

fibonacci Heaps

TRANSCRIPT

  • Last updated on Sep 8, 2013 7:00 AM

    Copyright 2013 Kevin Waynehttp://www.cs.princeton.edu/~wayne/kleinberg-tardos

    FIBONACCI HEAPS

    preliminaries insert extract the minimum decrease key bounding the rank meld and delete

  • 2Ahead. 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

  • 3Fibonacci heaps

    Theorem. [Fredman-Tarjan 1986] Starting from an empty Fibonacci heap,

    any sequence of m INSERT, EXTRACT-MIN, and DECREASE-KEY operationsinvolving n INSERT operations takes O(m + n log n) time.

    Fibonacci Heaps and Their Uses in Improved Network Optimization Algorithms

    MICHAEL L. FREDMAN

    University of California, San Diego, L.a Jolla, California

    AND

    ROBERT ENDRE TARJAN

    AT&T Bell Laboratories, Murray HilI, New Jersey

    Abstract. In this paper we develop a new data structure for implementing heaps (priority queues). Our structure, Fibonacci heaps (abbreviated F-heaps), extends the binomial queues proposed by Vuillemin and studied further by Brown. F-heaps support arbitrary deletion from an n-item heap in qlogn) amortized time and all other standard heap operations in o( 1) amortized time. Using F-heaps we are able to obtain improved running times for several network optimization algorithms. In particular, we obtain the following worst-case bounds, where n is the number of vertices and m the number of edges in the problem graph:

    ( 1) O(n log n + m) for the single-source shortest path problem with nonnegative edge lengths, improved from O(m logfmh+2)n);

    (2) O(n*log n + nm) for the all-pairs shortest path problem, improved from O(nm lo&,,,+2,n); (3) O(n*logn + nm) for the assignment problem (weighted bipartite matching), improved from

    O(nm log0dn+2)n); (4) O(mj3(m, n)) for the minimum spanning tree problem, improved from O(mloglo&,,.+2,n), where

    j3(m, n) = min {i 1 log% 5 m/n). Note that B(m, n) 5 log*n if m 2 n.

    Of these results, the improved bound for minimum spanning trees is the most striking, although all the results give asymptotic improvements for graphs of appropriate densities.

    Categories and Subject Descriptors: E.l [Data]: Data Structures--trees; graphs; F.2.2 [Analysis of Algorithms and Problem Complexity]: Nonnumerical Algorithms and Problems-computations on discrete structures; sorting and searching; G.2.2 [Discrete Mathematics]: Graph Theory-graph algo- rithms; network problems; trees General Terms: Algorithms, Theory Additional Key Words and Phrases: Heap, matching, minimum spanning tree, priority queue, shortest Pati

    A preliminary version of this paper appeared in the Proceedings of the 25th IEEE Symposium on the Foundations of Computer Science (Singer Island, Fla., Oct. 24-26). IEEE, New York, 1984, pp. 338- 346, 0 IEEE. Any portion of this paper that appeared in the preliminary version is reprinted with permission. This research was supported in part by the National Science Foundation under grant MCS 82-0403 1. Authors addresses: M. L. Fredman, Electrical Engineering and Computer Science Department, Uni- versity of California, San Diego, La Jolla, CA 92093; R. E. Tarjan, AT&T Bell Laboratories, Murray Hill, NJ 07974. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. 0 1987 ACM 0004-541 l/87/0700-0596 $1.50

    Journal ofthe Association for Computing Machinery, Vol. 34, No. 3, July 1987, Pages 596-615.

    this statement is a bit weakerthan the actual theorem

  • 4Fibonacci heaps

    Theorem. [Fredman-Tarjan 1986] Starting from an empty Fibonacci heap,

    any sequence of m INSERT, EXTRACT-MIN, and DECREASE-KEY operationsinvolving 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.1

    FIBONACCI HEAPS

    structure insert extract the minimum decrease key bounding the rank meld and delete

  • 6Fibonacci heaps

    Basic idea.

    Similar to binomial heaps, but less rigid structure.Binomial heap: eagerly consolidate trees after each INSERT;

    implement DECREASE-KEY by repeatedly exchanging node with its parent.

    Fibonacci heap: lazily defer consolidation until next EXTRACT-MIN;implement DECREASE-KEY by cutting off node and splicing into root list.

    Remark. Height of Fibonacci heap is (n) in worst case, but it doesn't use sink or swim operations.

  • Set of heap-ordered trees.

    7

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: structure

    heap-ordered tree

    each child no smallerthan its parent

    root

    heap H

  • Set of heap-ordered trees.Set of marked nodes.

    8

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: structure

    min

    used to keep trees bushy(stay tuned)

    39

    18

    markedheap H

    26

  • Heap representation.

    Store a pointer to the minimum node.Maintain tree roots in a circular, doubly-linked list.

    9

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: structure

    min

    39

    18

    heap H

    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.

    10

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    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.

    11

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: representation

    min

    39

    18

    heap H

    26

    rank = 3

  • 12

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: notation

    min

    39

    18

    rank(H) = 3 trees(H) = 5 marks(H) = 3n = 14

    notation meaning

    n number of nodes

    rank(x) number of children of node xrank(H) max rank of any node in heap Htrees(H) number of trees in heap H

    marks(H) number of marked nodes in heap H

    heap H

    26

    rank = 3rank = 1

  • Potential function.

    13

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: potential function

    min

    39

    18

    trees(H) = 5 marks(H) = 3(H) = 5 + 23 = 11

    heap H

    (H) =trees(H) + 2 marks(H)

    26

  • SECTION 19.2

    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).

    15

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: insert

    21

    insert 21

    min

    heap H39

    1826

  • Create a new singleton tree.Add to root list; update min pointer (if necessary).

    16

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    3

    44

    Fibonacci heap: insert

    21

    insert 21

    min

    heap H39

    1826

  • Actual cost. ci = O(1).

    Change in potential. = (Hi) (Hi1) = +1.

    Amortized cost. i = ci + = O(1).

    17

    723

    30

    17

    35

    26 46

    24

    39

    4118 52

    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

  • SECTION 19.2

    FIBONACCI HEAPS

    preliminaries insert extract the minimum decrease key bounding the rank meld and delete

  • 19

    Linking operation

    Useful primitive. Combine two trees T1 and T2 of rank k.Make larger root be a child of smaller root.Resulting tree T ' has rank k + 1.

    39

    4118 52

    3

    4477

    56 24

    15

    tree T1 tree T2

    39

    4118 52

    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.

    20

View more