Skip to content

pricees/algoruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

algoruby

Algorithms in a Nutshell, Ruby Implementations

Algoruby

Translating algorithms from:

"Algorithms in a Nutshell: A Desktop Reference" George T. Heineman Gary Police & Stanley Selkow O'reilly

into Ruby. Just for fun and educational purposes.

Installation

Add this line to your application's Gemfile:

gem 'algoruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install algoruby

Usage

Searches

Search Medley

  • Binary
  • Binary Tree (Red-Black, see test)
  • Hash
  • Sequential

Syntax

Algoruby::Search::Binary.search(haystack, needle)

Algoruby::Search::BinaryTree.search(tree, needle)

Algoruby::Search::Hash.search(haystack, needle)

Algoruby::Search::Sequential.search(haystack, needle)

Sorts

Sort Medley

  • Blum-Floyd-Pratt-Rivest-Tarjan ver (unfinished)
  • Bucket
  • Counting
  • Heap
  • Insertion
  • Median
  • Quicksort
  • Selection

How to choose?

CriteriaAlgorithm
Only a few itemsInsertion
Items are mostly sorted alreadyInsertion
Concerned about worst-case scenariosHeap
Interested in a good average-case resultQuicksort
Items are drawn from a dense universeBucket
Desire to write as little code as possibleInsertion

Syntax

ary = [1, 2, 3, ..., x ]

Algoruby::Sort::Bucket.sort(ary)

Algoruby::Sort::Counting.sort(ary)

Algoruby::Sort::Heap.sort(ary)

Algoruby::Sort::Insertion.sort(ary)

Algoruby::Sort::Median.sort(ary)

Algoruby::Sort::Quicksort.sort(ary)

Algoruby::Sort::Selection.sort(ary)

About

Algorithms in a Nutshell, Ruby Implementations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages