Class BinarySearchTree
java.lang.Object
com.amritpandey23.dsalibrary.tree.BinarySearchTree
Binary Search Tree Algorithms: Search, Insert, Delete, Validate.
All the algorithms are implemented on
TreeNode node.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDeletes a specified value from the binary search tree.Inserts a specified value into the binary search tree.static booleanSearches for a specified value in the binary search tree.static booleanValidates if the given binary tree is a binary search tree (BST).
-
Constructor Details
-
BinarySearchTree
public BinarySearchTree()
-
-
Method Details
-
search
Searches for a specified value in the binary search tree.- Parameters:
node- the root of the binary search treeval- the value to search for- Returns:
trueif the value is found in the tree,falseotherwise
-
insert
Inserts a specified value into the binary search tree. If the value already exists in the tree, it will not be duplicated.- Parameters:
node- the root of the binary search treeval- the value to insert- Returns:
- the root of the tree after insertion
-
delete
Deletes a specified value from the binary search tree.- Parameters:
node- the root of the binary search treeval- the value to delete- Returns:
- the root of the tree after deletion
-
validate
Validates if the given binary tree is a binary search tree (BST).- Parameters:
node- the root of the binary tree to validate- Returns:
trueif the tree is a valid binary search tree,falseotherwise
-