Binary Search Trees
Left subtree smaller, right subtree larger — search, insert and delete in O(log n) when balanced.
Intermediate
For every node: keys in the left subtree node keys in the right subtree. Searching follows one path from the root, so it takes where is the height.
A balanced tree has ; inserting sorted data into a plain BST makes it a linked list (). Self-balancing trees — AVL and red-black trees (used by C++ std::map and Java TreeMap) — keep operations at .
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.