🌳 BinarySearchTree Overview
🎯 Purpose
The BinarySearchTree
is designed to:
- Store elements in a sorted manner.
- Allow efficient insertion and search operations.🔑 Key Features
📦 Node Structure:
Each node contains:
- A value (
val
) of type Comparable
.
- References to its left and right child nodes (
left
and right
).
- big -parent node se bhi big
➕ Insertion:
- The
insert
method adds a new value to the tree.
- Values smaller than the current node go to the left subtree, and larger values go to the right subtree.
🔍 Search:
- The
contains
method checks if a value exists in the tree.
- It traverses the tree based on comparisons, moving left or right depending on the value.