Balanced Search Trees and Rotations
Use a local rotation to preserve key ordering and derive why bounded height difference gives logarithmic depth.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A rotation preserves the order of subtrees
Consider a node with key \(x\) and left child \(y<x\), with ordered subtrees \(A,B,C\): keys in \(A<y\), between \(y\) and \(x\) in \(B\), and above \(x\) in \(C\). A right rotation makes \(y\) the root of this fragment, \(x\) its right child, and moves \(B\) to the left of \(x\). Its inorder sequence remains \(A,y,B,x,C\). No search comparison changes its interpretation.
A local balance rule gives a global depth bound
In an AVL tree, the children’s heights differ by at most one. A minimum-size tree of height \(h\) therefore has child heights \(h-1\) and \(h-2\), giving \(N(h)=1+N(h-1)+N(h-2)\) beyond the bases. Fibonacci-like growth gives \(h=O(\log n)\). Insertion or deletion repairs the affected ancestor path through appropriate rotations and height recomputation. Order-statistic trees maintain subtree sizes through the same changes. A page-oriented tree uses a different branching rule when disk transfers dominate.[1]