//Insertion in binary tree // Big O notation: O(height of BST) //takes in a node to insert as val and the root element if newNode.data < root.data if root.left is null root.left = newNode else recursively call self (newNode, root.left) else if root.right is null root.right = newNode else recursively call self (newNode, root.right)
//Deletion in binary tree // Big O notation: O(height of BST) //takes in value to delete and a root node if value < root.data root.left = recursively call self(value, root.left) return root else if value > root.data root.right = recursively call self(value, root.right) return root else if root.left equals null and root.right equals null root = null return root if root.left equals null return root.right if root.right equals null return root.left aux = root.right while aux.left not equals null aux = aux.left root.data = aux.data root.right = recursively call self(aux.data,root.right) return root
//Traversal // Big O notation: O(height of BST) //returns all the values in a tree //takes in root element if root equals null return result = result + root.data + " " if root.left not equals null recursively call self(root.left) if root.right not equals null recursively call self(root.right) return result
//takes in root and value to search //returns found or not found = false while root not equals null and not found if value < root.data root = root.left; found = recursively calls self(root, value); else if value > root.data root = root.right; found = recursively calls self(root, value); else found = true break return found