mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 05:14:06 -06:00
24 lines
975 B
Markdown
24 lines
975 B
Markdown
---
|
|
title: "balancing-binary-search-trees"
|
|
aliases: Balancing BST, balancing
|
|
tags:
|
|
- cosc201
|
|
---
|
|
|
|
the height of a [BST](notes/binary-search-tree.md) is the length of its longest chain. Most operations are $O(n)$ where n is the height of the tree. In an Ideal situation each layer of the tree is full. The height of the tree is logarithmic to the number of nodes.
|
|
|
|
When a tree is being used only occainsonally, we can afford to simply rebalance is periodically. However when it is in constant use we cannot afford this cost
|
|
|
|
# Rotations
|
|
|
|

|
|
sometimes two rotations are needed
|
|
|
|
## When to rotate and how to do them
|
|
|
|
basic idea is to modify the add and delete operations fo the BST to be somewhat self-balancing. This does not need to be perfect
|
|
|
|
We need a rule to decide when the tree is "balanced enough" and also strategies for fixing problems when the rule is violated.
|
|
|
|
We only need to fix the area local to the add or delete operations
|