当前位置: 代码迷 >> 综合 >> Data Structure Lecture Note (Week 7, Lecture 20)
  详细解决方案

Data Structure Lecture Note (Week 7, Lecture 20)

热度:15   发布时间:2024-02-01 14:47:18.0

(Finally) The end of the course!

(2, 4) tree

Multi-way search tree:

an ordered tree such that:

  • each interval node has at least two children and stores d-1 key-element items k i , o i k_i, o_i , where d d is the number of children
  • for a node with children v 1 , v 2 , . . . , v d v_1, v_2,...,v_d storing keys k 1 , k 2 , . . . , k d ? 1 k_1, k_2, ..., k_{d-1}
    • keys in the subtree of v 1 v_1 are less than k 1 k_1
    • keys in the subtree of v i v_i are between k i ? 1 k_{i-1} and k i k_i (i=2,…d-1)
    • keys in the subtree of v d v_d are greater than k d k_d

An inorder traversal of a multi-way search tree visits the keys in increasing order.

A (2, 4) Tree:

  • Node-Size property: each internal node has at most 4 children
  • Depth property: all the external nodes have the same depth.

Theorem: Height of a (2,4) tree is O(log N)

relation with Red-Black tree:

2–3–4 trees are an isometry of red–black trees, meaning that they are equivalent data structures. In other words, for every 2–3–4 tree, there exists at least one red–black tree with data elements in the same order. Moreover, insertion and deletion operations on 2–3–4 trees that cause node expansions, splits and merges are equivalent to the color-flipping and rotations in red–black trees. Introductions to red–black trees usually introduce 2–3–4 trees first, because they are conceptually simpler. 2–3–4 trees, however, can be difficult to implement in most programming languages because of the large number of special cases involved in operations on the tree. Red–black trees are simpler to implement,[2] so tend to be used instead.

Reference

https://en.wikipedia.org/wiki/2%E2%80%933%E2%80%934_tree

Red-Black Tree

A red-black tree is a representation of a (2, 4) tree by means of a binary tree whose nodes are colored red or black.

In comparision with its associated (2, 4) tree, a red-black tree has:

  • Same logarithmic time performance
  • Simpler implementation with a single node type.

Property:

  • Root is black
  • Leaf is black
  • Children of a red node is black
  • all leaves have the same black depth
  相关解决方案