Coder Social home page Coder Social logo

fibonacci_heap's Introduction

fibonacci_heap

This repository contains my implementation of Fibonacci Heap data structure in Python, done as part of the Advanced Algorithms and Data Structures course at the Faculty of Electrical Engineering in Sarajevo. The implementation was modeled after the pseudocode found in the book "Introduction to Algorithms ".

Fibonacci Heap

A Fibonacci Heap is a versatile data structure that provides efficient implementations of various priority queue operations such as insert, extract minimum, decrease key, and union. It is particularly useful in algorithms like Dijkstra's shortest path and Prim's minimum spanning tree.

๐Ÿ“ Project structure

The project is organized with the following directory structure:

Fibonacci_heap/
โ”‚
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test.py
โ”‚
โ””โ”€โ”€ classes/
    โ”œโ”€โ”€ FibNode.py
    โ””โ”€โ”€ FibHeap.py
  • main.py - main entry point, contains a simple example of a Fibonacci Heap.

  • tests/ - holds unit tests for the project

    • test.py - contains 12 unit tests testing different scenarios
  • classes/ - contains the main classes required for implementation

    • FibNode.py - definition of the node structure used in the Fibonacci Heap
    • FibHeap.py - implementation of the Fibonacci Heap data structure

๐Ÿ”Ž Implementation details

The Fibonacci Heap itself is represented by FibHeap class with following attributes:

  • root_list - a pointer to one of the nodes in a doubly linked list of root nodes
  • min - a pointer to the node with minimum key value
  • n - number of nodes in the heap

Singular nodes are instances of class FibNode, representing a node of a Fibonacci Heap using the following attributes:

  • key - key value of node
  • parent - parent of node
  • child - pointer to one of the nodes in a doubly linked list of child nodes
  • left - left sibling of node
  • right - right sibling of node
  • degree - degree of node (number of node's children)
  • marked - mark of node (True or False)
  • id - unique id of node

Main Methods

  • fib_heap_insert(key) - inserts new node with given key into heap
  • fib_extract_min() - removes and returns node with minimum key
  • fib_heap_decrease_key(key, new_key) - decreases key value of node with given key to new key value
  • fib_heap_delete(key) - removes node with given key from heap
  • fib_heap_union(h1, h2) - performs concatenation of two given heaps into a new heap

fibonacci_heap's People

Contributors

nkokor avatar

Stargazers

 avatar

Watchers

 avatar

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.