Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Add Binary Search Tree Implementation #36

Open Kalkwst opened 1 year ago

Kalkwst commented 1 year ago

A binary search tree (BST) is a type of data structure that is used to efficiently store and retrieve data. It organizes the data in a hierarchical structure, where each node has a value, the left subtree of a node contains values that are less than the node's value, and the right subtree of a node contains values that are greater than the node's value. This allows for efficient searching, insertion, and deletion operations, as the tree can be traversed starting from the root node to reach the desired node in logarithmic time complexity.

From a more technical perspective, a binary search tree (BST) is a binary tree data structure where each node has up to two children, left and right and every node in the left subtree of a node has a value less than the node, and every node in the right subtree of a node has a value greater than the node. This property allows for efficient searching, insertion, and deletion operations, as the tree can be traversed starting from the root node to reach the desired node in a logarithmic time complexity O(log n) where n is the number of nodes in the tree. However, if the tree is not balanced, the time complexity of the operation can be worse than O(n), where n is the number of nodes in the tree. Therefore, it is important to keep the tree balanced by using techniques such as AVL tree or red-black tree to ensure that the time complexity of the operations remains logarithmic.