Algorithms in a Nutshell, Ruby Implementations
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.
Add this line to your application's Gemfile:
gem 'algoruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install algoruby
- Binary
- Binary Tree (Red-Black, see test)
- Hash
- Sequential
Algoruby::Search::Binary.search(haystack, needle)
Algoruby::Search::BinaryTree.search(tree, needle)
Algoruby::Search::Hash.search(haystack, needle)
Algoruby::Search::Sequential.search(haystack, needle)
- Blum-Floyd-Pratt-Rivest-Tarjan ver (unfinished)
- Bucket
- Counting
- Heap
- Insertion
- Median
- Quicksort
- Selection
Criteria | Algorithm |
Only a few items | Insertion |
Items are mostly sorted already | Insertion |
Concerned about worst-case scenarios | Heap |
Interested in a good average-case result | Quicksort |
Items are drawn from a dense universe | Bucket |
Desire to write as little code as possible | Insertion |
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)