This repository contains implementations of binary search trees (BST) in both JavaScript and Ruby.
The JavaScript implementation (Binary_Search_Trees.js
) consists of classes for representing nodes and binary search trees.
The Node
class represents each node in the binary search tree. Each node has a data
attribute to store the node's value, as well as left
and right
attributes to reference its left and right children.
The Tree
class represents the binary search tree itself. It has methods for building a balanced tree from an array, inserting and deleting nodes, finding nodes, traversing the tree in various orders (level order, in-order, pre-order, post-order), calculating heights and depths, checking if the tree is balanced, and rebalancing the tree.
The Ruby implementation (binary_search_trees.rb
) also includes classes for representing nodes and binary search trees.
Similar to the JavaScript implementation, the Node
class in Ruby represents each node in the binary search tree. It has attributes for data
, left
, and right
children.
The Tree
class represents the binary search tree in Ruby. It provides methods for building a balanced tree from an array, inserting and deleting nodes, finding nodes, traversing the tree in various orders (level order, in-order, pre-order, post-order), calculating heights and depths, checking if the tree is balanced, and rebalancing the tree.
To use either implementation, simply include the respective JavaScript or Ruby file (Binary_Search_Trees.js
or binary_search_trees.rb
) in your project. You can then create instances of the Tree
class and perform various operations on the binary search tree.
Contributions to this repository are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.