GithubHelp home page GithubHelp logo

balanced-bst's Introduction

Balanced Binary Search Tree

An exercise in building a balanced BST using Ruby.

Features

This project has a Tree class that can build binary search trees from an array of numbers. Tree also has several methods for traversing and managing the tree:

  1. #insert(value) -- inserts a new given value into the tree.
  2. #delete(value) -- deletes a given value from the tree.
  3. #find(value) -- returns the node in the tree with the given value.
  4. #level_order -- traverses the tree in breadth-first fashion
  5. #inorder -- traverses the tree inorder
  6. #preorder -- traverses the tree preorder
  7. #postorder -- traverses the tree postorder
  8. #height(node) -- returns the height of the given node (that is the number of edges in longest path from the node to a leaf node)
  9. #depth(target) -- returns the depth of the target node (that is the number of edge in path from the node to the tree's root)
  10. #balanced? -- returns true if the tree is balanced
  11. #rebalance -- rebalances a tree if it is unbalanced

In main.rb there is a short script that tests most of the above methods using a random dataset.

balanced-bst's People

Contributors

joshdevhub avatar

Watchers

 avatar

balanced-bst's Issues

๐Ÿ‘‹

This is the number 2 search result for "ruby balancing binary search tree". I see you just made the repo 3 hours ago, so I thought that was kinda funny and thought you might appreciate it. Good luck with the exercise!

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.