Ruborithms
Algorithms and data structures implemented on pure Ruby.
Install
gem install ruborithmsRequire library:
require 'ruborithms'Algorithms
Linear Search
Include:
class Array; include Ruborithms::Algorithms::LinearSearch; endLinear search can now be used as a class singleton method:
irb(main):006:0> Array.linear_search([1, 55, 22, 44], 55)
=> 1Or in the instance context:
irb(main):007:0> [1, 55, 22, 44].linear_search(55)
=> 1Binary Search
Include:
class Array; include Ruborithms::Algorithms::BinarySearch; end Binary search can now be used as a class singleton method:
irb(main):008:0> Array.binary_search([1, 55, 22, 44], 55)
=> 1Or in the instance context:
irb(main):009:0> [1, 55, 22, 44].binary_search(55)
=> 1Selection Sort
Include:
class Array; include Ruborithms::Algorithms::SelectionSort; end Binary search can now be used as a class singleton method:
irb(main):017:0> Array.selection_sort([1, 55, 22, 44])
=> [1, 22, 44, 55]Or in the instance context:
irb(main):019:0> [1, 55, 22, 44].selection_sort
=> [1, 22, 44, 55]