Coder Social home page Coder Social logo

diogolhc / fibonacci-heap Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 111 KB

:deciduous_tree: Implementation of a Fibonacci Heap in C++ guided by the Introduction to Algorithms book by Cormen, Leiserson, Rivest and Stein.

License: GNU General Public License v3.0

C++ 98.55% Makefile 1.45%
advanced-data-structures cpp data-structures fibonacci-heap

fibonacci-heap's Introduction

Fibonacci Heap

Fibonacci Heaps were introduced in Fibonacci heaps and their uses in improved network optimization algorithms by Fredman and Tarjan in 1987.

This implementation in C++ was guided by the Introduction to Algorithms book by Cormen, Leiserson, Rivest and Stein.

Usage

The Fibonacci Heap is implemented in the FibonacciHeap.hpp header file. It is templated on the type of the elements it stores. The Fibonacci Heap is a min-heap, i.e. the element with the smallest key is always at the top. This implementation supports the following operations:

  • insert(key): Inserts a new element with the given key into the heap.
  • unite(other_heap): Unites the heap with the given heap. The other heap is empty afterwards.
  • getMin(): Returns the smallest key in the heap.
  • extractMin(): Returns the smallest key in the heap and removes it from the heap.
  • decreaseKey(element, new_key): Decreases the key of the given element to the new key. The new key must be smaller than the old key.
  • deleteElement(element): Deletes the given element from the heap.
  • isEmpty(): Returns whether the heap is empty.

Visualization

The Fibonacci Heap can be visualized using the inherited class implemented in FibonacciHeapViz.hpp. The visualization is done using the GraphViz library in the dot format. The FibonacciHeapViz class has a method that dumps the current state of the heap to the given std::ostream, which can be a file or the standard output:

  • exportDot(ostream): Exports the current state of the heap to the given std::ostream.

Example

Refer to the main.cpp file for an example on how to use the Fibonacci Heap with the following final result visualized using GraphViz:

Example Visualization

References

Michael L. Fredman and Robert Endre Tarjan. 1987. Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM 34, 3 (July 1987), 596โ€“615. https://doi.org/10.1145/28869.28874

Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to Algorithms, Third Edition (3rd. ed.). The MIT Press.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.