Skip to content

XAJX179/binary-search-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Table of contents

Binary Search Tree

BST is a data structure consisting of nodes containing data with left and right pointers both of which points either to a other node or nil and when BST is balanced meaning its root is almost a middle value and for each node its left subtree/node is of smaller value and right subtree/node is bigger, it looks like a tree.


πŸ“¦ Structure

β”œβ”€β”€ lib
β”‚Β Β  β”œβ”€β”€ binary_search_tree
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helpers
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── helpers.rb
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ node.rb
β”‚Β Β  β”‚Β Β  └── tree.rb
β”‚Β Β  └── binary_search_tree.rb
└── main.rb // just a file i used for testing my trees

πŸ›  Features

  • #insert(value) - inserts a new node with given value into the tree.
  • #delete(value) - deletes a node with given value from the tree.
  • #find(value) - finds returns the node in the tree with the given value.
  • #level_order - breadth-first-search tree traversal.

breadth-first-search

  • #inorder - traverse the tree in preorder DLR.
  • #preorder - traverse the tree in inorder LDR.
  • #postorder - traverse the tree in postorder LRD.

  • #height(node) - returns the height of the given node (number of edges in longest path from the node to a leaf node)
  • #depth(target) - returns the depth of the target node (number of edge in path from the node to the tree's root)
  • #balanced? - returns true if the tree is balanced. (currently incomplete)
  • #rebalance - rebalances tree.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages