You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This includes both depth-first and breadth-first approaches to searching a BST.
4
+
5
+
The following methods are included in this project:
6
+
7
+
-[ ]`#build_tree(array)` -- takes an array of data and returns a balanced tree of `Node` objects, and returns the level 0 root node.
8
+
-[ ]`#pretty_print` -- returns a visually pleasing showcase of the tree.
9
+
-[ ]`#insert(value)` -- inserts the value provided into the tree, keeping it balanced.
10
+
-[ ]`#delete(value)` -- deletes the value provided if it is in the tree, keeping it balanced afterwards. Returns nil if the value is not found.
11
+
-[ ]`#find(value)` -- searches through the tree to find the value provided. Returns nil if the value is not found
12
+
-[ ]`#level_order(&block)` -- traverses the tree in breadth-first level order and yields each node to the provided block. Returns an array of values if no block is given. Also uses an array acting as a queue to keep track of all the child nodes that it has yet to traverse and will add new ones to the list when needed.
13
+
-[ ]`#inorder(&block)` -- traverses the tree in depth-first using inorder traversal and yields each node to the provided block. Returns an array of values if no block is given.
14
+
-[ ]`#preorder(&block)` -- traverses the tree in depth-first using preorder traversal and yields each node to the provided block. Returns an array of values if no block is given.
15
+
-[ ]`#postorder(&block)` -- traverses the tree in depth-first using postorder traversal and yields each node to the provided block. Returns an array of values if no block is given.
16
+
-[ ]`#height(value)` -- accepts the value of a node on the tree and returns its height. Height is defined as the number of edges in longest path from a given node to a leaf node. Returns nil if the value isn't found on the tree.
17
+
-[ ]`#depth(value)` -- accepts the value of a node on the tree and returns its depth. Depth is defined as the number of edges in path from a given node to the tree’s root node. Returns nil if the value isn't found on the tree.
18
+
-[ ]`#balanced?` -- checks if the tree is balanced. A balanced tree is one where the difference between heights of left subtree and right subtree of every node is not more than 1. Returns true or fals.
19
+
-[ ]`#rebalance` -- rebalances an unbalanced tree.
0 commit comments