Search Trees

Binary Search Trees (BST)

Related homework questions: h3-6

Binary Tree

Complete Binary Tree

Every level of the tree is completely filled, except possibly the last level. Moreover, the last level has to be filled from left to right.

If a complete binary tree is also complete on the last level, then it is called a perfect binary tree.

Height of binary trees

Binary Search Tree

AVL Trees

Related homework questions: h3-7, h3-8

An AVL tree is a binary search tree where the left subtree and right subtree at each node differ by at most 1 in height.

Balance Factor

Insertion and Deletion Algorithms

UPDATE PHASE: Insert or delete as we would in a binary search tree.

Insertion Rebalancing

Deletion Rebalancing

Ratio/Weight Balanced Trees

Related homework questions: h4-3

Extended size:

Ratio:

ρ-ratio

Insertion and Deletion Algorithms

Rebalance(u)
  While (u != u.parent)
    u <- Rebalance-Step(u)
    u <- u.parent
Rebalance-Step(u)
  If (ratio(u) >= 3)
    v <- u.left
    If (ratio(v) >= 3/5)
      Return(rotate(v))
    Else \\ ratio(v) < 3/5
      Return(double-rotate(v.right))
  elif (ratio(u) <= 1/3)
    v <- u.right
    If (ratio(v) <= 3/5)
      Return(rotate(v))
    Else \\ ratio(v) > 3/5
      Return(double-rotate(v.left))
  else
    Return(u)

Generalized B-Trees: (2,3)-trees

Related homework questions: h4-1, h4-2

An (a,b)-tree is a rooted, ordered tree with the following structural constraints:

  • Depth property: All leaves are at the same depth.

(a,b)-search trees

Lecture Note 3, Page 80.

An (a,b)-search tree is an (a,b)-tree whose nodes are organized as an external search tree, which means items are only stored in leaves. Leaves are also called external nodes.

Reorganization of nodes

Simple Remedy: borrow or donate children

Strong Remedy: when simple remedy fails.

  • Split an overfull node

  • Merge an underfull node

Split-Merge Inequality

Last updated