Deleting a Node in a Binary Search Tree (LeetCode 450: Delete Node in a BST)
- February 5, 2025
- Liu, An-Chi 劉安齊
Code makes the world a better place
A red-black tree is a special data structure that can automatically balance itself, similar to an AVL tree.
A red-black tree has the following properties:
NIL) is blackFollowing these rules ensures the tree stays balanced during insertions and deletions. A red-black tree guarantees that when the number of nodes is n, the height is at most 2log(n+1).
In practice, it is often used to implement sets and dictionaries. In C++, std::set and std::map are backed by red-black trees.