集成算法决策树算法_2 – 3树算法

集成算法决策树算法

2 – 3棵树 (2 – 3 Trees)

A 2 – 3 trees also known 3 – 2 trees is a tree in which each vertex, except leaf has 2 or 3 sons and one or two keys per node, and every path from the root to leaf is of the same length. The tree consisting of a single vertex is a 2 – 3 trees.

2 – 3棵树(也称为3 – 2棵树)是一棵树,其中每个顶点(叶子除外)具有2或3个子节点,每个节点一个或两个键,并且从根到叶子的每条路径的长度相同。 由单个顶点组成的树是2 – 3棵树。

Let T be a 2 – 3 trees of height h. The number of vertices of T is between (2^h+1 - 1) and (3^h+1 - 1)/2, and the number of leaves is in between 2^h and 3^h.

令T为高度为h的2 – 3棵树。 T的顶点数在(2 ^ h + 1-1)和(3 ^ h + 1-1)/ 2之间,叶数在2 ^ h和3 ^ h之间。

Inserting a key K into a B tree T of height h is done in a single pass down the tree, requiring O (h) disk accesses. The CPU time required is O (th) = O (t log n). the B tree insert procedure uses B tree split child to guarantee that the recursion never descends to a full node.

将密钥K插入到高度为h的B树T中,是在该树的向下一次传递中完成的,需要访问O(h)个磁盘。 所需的CPU时间为O(th)= O(t log n)。 B树插入过程使用B树拆分子节点来确保递归永远不会下降到完整节点。

2-3 trees

2 - 3 Trees

2-3棵树

Algorithm:

算法:

    1.	B tree insert (T, K)
    2.	r = root [T]
    3.	if n[r] = 2t – 1
    4.	then s = ALLOCATE – NODE ()
    5.	root [T] = s
    6.	leaf [s] = FALSE 
    7.	n [s] = 0
    8.	c1 [s] = r
    9.	B – TREE – SPLIT – CHILD (s, 1, r)
    10.	B – TREE – INSERT – NONFULL (s, k)
    11.	Else
    12.	B – TREE – INSERT – NONFULL (r, k)

The lines 4 to 10 deals with the case in which the root node r is full – the root is split and a new node s (having two children) becomes the root. Splitting the root is the only way to increase the height of a B tree. Unlike a binary search tree, a B tree increases in height at the top instead of at the bottom. Afterwards, the procedure finishes by calling B – TREE – INSERT – NONFULL to perform the insertion of key k in the tree rooted at the non-full root node. B – TREE – INSERT – NONFULL recurses as necessary down the tree, at all times guaranteeing that the node to which it recurses is not full by calling B – TREE- SPLIT – CHILD as necessary.

第4至10行处理了根节点r已满的情况-根被拆分,新节点s(具有两个子节点)成为根。 分裂根是增加B树的高度的唯一方法。 与二叉搜索树不同,B树的高度在顶部而不是底部增加。 然后,该过程通过调用B – TREE – INSERT – NONFULL结束,以在根于非完整根节点的树中执行密钥k的插入。 B – TREE – INSERT – NONFULL会根据需要在树中递归,并始终通过调用B – TREE-SPLIT – CHILD来确保其递归的节点未满。

B – TREE – INSERT – NONFULL inserts a key K into the node x, which is assumed to be non-full when the procedure is called. The operation of B – TREE – INSERT and the recursive operation of B – TREE – INSERT – NONFULL guarantees that this assumption is true.

B – TREE – INSERT – NONFULL将密钥K插入节点x,在调用该过程时假定该密钥不完整。 B – TREE – INSERT的操作以及B – TREE – INSERT – NONFULL的递归操作保证此假设是正确的。

Algorithm:

算法:

    1.	B – TREE – INSERT – NONFULL (x, k)
    2.	 i = n [x]
    3.	If leaf [x]
    4.	Then while i>= 1 and k< key(i) [x]
    5.	Do key(i+1)[x] = key (i) [x]
    6.	i = i – 1
    7.	key (i+1) [x] = k
    8.	n[x] = n[x] + 1
    9.	DISK_ WRITE (x)
    10.	Else while i>= 1 and K < key (i)[x]
    11.	Do i = i – 1
    12.	i = i + 1
    13.	DISK _ READ (c(i)[k])
    14.	If n [c(i)[x]] = 2t - 1 
    15.	Then B – TREE – SPLIT – CHILD (x, I, c(i)[x])
    16.	If k> key (i)[x]
    17.	Then i = i + 1
    18.	B – TREE – INSERT – NONFULL (c(i)[x], k)

References:

参考文献:

翻译自: https://www.includehelp.com/algorithms/2-3-trees.aspx

集成算法决策树算法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值