TheAlgorithms / Ruby

All algorithms implemented in Ruby
MIT License
1.15k stars 289 forks source link

Adding `BinarySearchTree` implementation #199

Closed aparibocci closed 1 year ago

aparibocci commented 1 year ago

As per title, this MR aims to add a Ruby implementation of a binary search tree with distinct node keys.

The main operations of this data structure (insertion, deletion, membership) run - in worst case - in O(n), where n is the number of nodes in the tree. The average case for those operations is O(log(n)) due to the structure of the tree, since nodes are inserted following the BST property.

Traversal methods (pre-order, in-order, post-order) with custom consumer as argument are also exposed.