B(B-)树、B+树、字典(trie)树、外部多路归并排序、败者树外部排序

本文深入探讨了B树、B-树、B+树和字典(Trie)树的数据结构,以及外部多路归并排序与败者树在外部排序中的应用。通过链接提供了详细解释,包括B树到B+树的演变,Trie树到后缀树的转换,以及外排序的多路归并思想和败者树的实现原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B(B-)树、B+树、字典(trie)树、外部多路归并排序

B树和B-

http://blog.youkuaiyun.com/gukesdo/article/details/7439865

 

从B树(也就是中文译的B-树)到B+、B*树再到R树

http://blog.youkuaiyun.com/v_JULY_v/article/details/6530142

 

trie

http://www.cnblogs.com/cherish_yimi/archive/2009/10/12/1581666.html

从trie树(字典树)到后缀树

http://blog.youkuaiyun.com/v_july_v/article/details/6897097

 

外排序多路归并的讲解在这篇博客的中间部分(第二节)

http://blog.youkuaiyun.com/v_JULY_v/article/details/6451990

归并排序可以分为多路归并排序和两路归并排序。如果归并的有序表有两个,则为二路归并,若归并的有序表有k个,则成为k路归并。二路归并最为简单和常用,既适合于内部排序,也适合于外部排序(时间复杂度为O(m+n-1));而k路归并多应用于外部排序。

思想是:首先把大文件分割成多个内存可以容纳的小文件,之后先将每个小文件进行排序;最后从每个小文件中的最开始的第一个数中再选取最小的数,依次写到一个文件中去,直至所有小文件中数据处理完毕即可。

败者树(归并完全二叉树)

http://blog.sina.com.cn/s/blog_6407c0c60100qjjw.html

其实他是一个比较经典的外部排序方法,也就是将n个已经排序好的文件归并为一个有序序列。它和胜者树都是一个完全二叉树。它可以用数组实现的原理是相同的,唯一的区别是堆的所有节点都是数据节点,而败者树只有叶子节点时数据节点,所有非叶子节点只是存储的叶子的下标。2个子节点比较之后失败的放入它们的父节点,而胜者则送到父节点的父节点中再进行比赛,直至得到一个最终的胜利者。经常用在k路外部平衡排序中。

败者树所需要的空间是堆的一倍,但是比较次数会相对减少一些,是一个拿空间换时间的算法。在这一点上和字典树trie有点类似。

 

先让我们看看原题的三个任务介绍: Task 1: Sorting the LINEITEM table by External Merge Sort Consider two cases: 1) using 5 buffer pages in memory for the external merge sort; 2) using 129 buffer pages in memory for the external merge sort. In the implementation, each buffer page occupies 8K bytes. The ORDERKEY attribute of the LINEITEM table is assumed to be the sort key in the external merge sort. Please report the number of passes and also the running time of the external merge sort in each case. Task 2: Organizing the sorted LINEITEM table into disk pages Please use the page format for storing variable-length records to organize the LINEITEM table sorted in Task 1. In the implementation, each disk page occupies 1K bytes. For each page we maintain a directory of slots, with a pair per slot. Both “record offset” and “record length” are 4 bytes wide. Task 3: Building a B-Tree over LINEITEM disk pages by Bulk Loading. Please use bulk loading to build a B-Tree over the disk pages of the LINEITEM table, which are generated in Task 2. The ORDERKEY attribute of the LINEITEM table is used as the (search) key for building the B-Tree. In the B-Tree, each internal node corresponds to a page of 1K bytes, both key and pointer are 4 bytes wide. Please report the running time of the bulk loading. A query interface is required for checking the B-Tree. For a reasonable ORDERKEY value, please print out all the pages visited along the path to find the corresponding record. Please also report the running time of the search.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值