GithubHelp home page GithubHelp logo

f_heap's Introduction

FHeap
=====

This is an implementation of the Fibonacci Heap data structure in Ruby. The Fibonacci Heap is a collection of trees that satisfy the minimum heap property (that is to say, each child node has a value >= its parent's value), which elicits the trait of having a better amortized runtime than a binomial heap.

Example
=======

irb(main):002:0> heap = FHeap.new
=> #<FHeap:0x10164d0c8 @trees=[], @min_node=nil>

irb(main):003:0> heap.insert!(9)
irb(main):004:0> heap.insert!(7)
irb(main):005:0> heap.insert!(8)
irb(main):006:0> heap.insert!(6)
irb(main):007:0> heap.insert!(5)
irb(main):008:0> heap.insert!(3)
irb(main):009:0> heap.insert!(4)
irb(main):010:0> heap.insert!(2)
irb(main):011:0> heap.insert!(1)
irb(main):012:0> heap.insert!(0)

irb(main):013:0> heap.extract_minimum!.value
=> 0
irb(main):014:0> heap.extract_minimum!.value
=> 1
irb(main):015:0> heap.extract_minimum!.value
=> 2
irb(main):016:0> heap.extract_minimum!.value
=> 3
irb(main):017:0> heap.extract_minimum!.value
=> 4
irb(main):018:0> heap.extract_minimum!.value
=> 5
irb(main):019:0> heap.extract_minimum!.value
=> 6
irb(main):020:0> heap.extract_minimum!.value
=> 7
irb(main):021:0> heap.extract_minimum!.value
=> 8
irb(main):022:0> heap.extract_minimum!.value
=> 9
irb(main):023:0> heap.extract_minimum!
=> nil

Copyright (c) 2010 Evan Senter, released under the MIT license

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.