Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Add AVL Tree Implementation #35

Open Kalkwst opened 1 year ago

Kalkwst commented 1 year ago

An AVL tree is a type of self-balancing binary search tree, which is used to efficiently store and retrieve data. It is similar to other types of self-balancing trees, such as AA and red-black trees, in that it automatically adjusts the structure of the tree to maintain a balance between its left and right branches. This ensures that the tree remains relatively balanced even as elements are added or removed, which improves the performance of search and insertion operations.

From a more technical perspective, an AVL tree is a self-balancing binary search tree that uses the concept of height balance to ensure the balance of the tree. Every node in the tree has a height, which is determined by the number of edges from the node to the leaf. The tree is balanced by ensuring that the difference in height between the left and right subtrees of any node is at most one. When a new node is added to the tree, it is placed in the correct position based on its value and the tree is adjusted accordingly to maintain the balance. The tree can be adjusted by performing rotations on the nodes, this way the tree can be adjusted to maintain the balance and keep the difference in height between the left and right subtrees of any node at most one. The time complexity for search, insertion and deletion operations in an AVL tree is O(log n), which is faster than the O(n) time complexity of a typical unbalanced binary search tree.