Giter VIP home page Giter VIP logo

priority_queues's Introduction

What is this?

For AcademyPGH book club, we wanted to explore some different data structures. I chose to look at a priority queue, where you can insert items with priorities, and the highest priority one is the one you get when you call pop.

Herein we have:

  • array_sort_prioritizer.rb: This is a naive implementation using an array as the base data structure and keeping it sorted with .sort.
  • sorted_list_prioritizer.rb: This is a slightly less naive implementation using a linked list as the base data structure and inserting the new item in place in the list to keep it sorted.
  • gap_array_prioritizer.rb: Uses a sparse array of arrays, where the priority determines the position. Slower at popping.
  • heap_prioritizer.rb: Pushes into a max binary heap. The 'usual implementation' of a priority queue.

Some performance results:

performance comparisons
sorting 5000 random numbers
Prioritizer type         push time          pop time
ArraySortPrioritizer     11.078591          0.000538
SortedListPrioritizer    1.540706           0.00056
GapArrayPrioritizer      0.002294           1.145813
HeapPrioritizer          0.00411            0.005171

sorting 5000 small to big numbers
Prioritizer type         push time          pop time
ArraySortPrioritizer     2.500763           0.000522
SortedListPrioritizer    0.002954           0.000549
GapArrayPrioritizer      0.000689           1.012277
HeapPrioritizer          0.004136           0.004615

sorting 5000 big to small numbers
Prioritizer type         push time          pop time
ArraySortPrioritizer     19.483607          0.00054
SortedListPrioritizer    3.076326           0.00057
GapArrayPrioritizer      0.001985           1.017181
HeapPrioritizer          0.005252           0.004831

priority_queues's People

Contributors

jeanlange avatar uugengiven avatar

Watchers

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