For this exercise you must get the tests to pass.
Given the following constructor functions
function Node(val){
this.val = val;
this.left = null;
this.right = null;
}
function BinarySearchTree(){
this.root = null;
}
Implement the following functions on the BinarySearchTree.prototype
This function should insert a node in a binary tree. This should be solved using iteration.
This function should insert a node in a binary tree. This should be solved using recursion.
This function should find a node in a binary tree. It should return the node if found, otherwise return undefined
. This should be solved using iteration. The tests for this method assume that insertIteratively has been implemented correctly.
This function should find a node in a binary tree. It should return the node if found, otherwise return undefined
. This should be solved using recursion. The tests for this method assume that insertIteratively has been implemented correctly.
This function should convert a binary search tree into an array of nodes from smallest to largest. The tests for this method assume that insertIteratively has been implemented correctly.
Implement the following functions on the BinarySearchTree.prototype
This function should search through each node in the binary search tree using pre-order depth first search and return an array containing each node's value.
This function should search through each node in the binary search tree using in-order depth first search and return an array containing each node's value.
This function should search through each node in the binary search tree using post-order depth first search and return an array containing each node's value.
This function should search through each node in the binary search tree using breadth first search and return an array containing each node's value.
Implement the following function on the BinarySearchTree.prototype
This function should remove a node from a binary search tree. Your remove function should be able to handle removal of the root node, removal of a node with one child and removal of a node with two children. The function should return the node removed.