Skip to content

basic-tutorials/Binary_Search_Trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

Binary Search Trees

This repository contains implementations of binary search trees (BST) in both JavaScript and Ruby.

Contents

  1. JavaScript Implementation
  2. Ruby Implementation
  3. Usage
  4. Contributing

JavaScript Implementation

The JavaScript implementation (Binary_Search_Trees.js) consists of classes for representing nodes and binary search trees.

Node Class

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.

Tree Class

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.

Ruby Implementation

The Ruby implementation (binary_search_trees.rb) also includes classes for representing nodes and binary search trees.

Node Class

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.

Tree Class

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.

Usage

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.

Contributing

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published