Study notes for B-tree and R-tree
B-tree
- B-tree is a tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic time.
- B-trees are balanced search trees: height
for the worst case, where t >2 is the order of tree, i.e., the maximum number of pointers for each node.
- Note that t is typically set so that one node fits into one disk block or page.
- B-trees are balanced search trees: height
- B-tree is a generalization of a binary search tree (i.e., a multiway tree) in that a node can have more than two children.
- Similar to red-black trees, but show better performance on disk I/O operations.
- Binary trees may be useful for rapid searching in main memory, but not appropriate for data stored on disks.
- When accessing data on a disk, an entire block (or page) is input at once, so it makes sense to design the tree so that each node essentially occupies one entire block.
- B-tree is optimized for systems that read and write large blocks of data. B-trees (and its variants) are commonly used in databases and file systems.
- Structure: every node x has four fields
- The number of keys currently stored in node x, i.e., n, which is between [t/2]-1 and t-1.
- The n keys themselves, stored in non-decreasing order:
- A boolean value
- n+1 pointers:
to its children, represented by:
- Properties:
- All leaves have the same height, which is the tree's height h.
- B-tree guarantees a storage utilization of at least 50%, i.e., at least half of each allocated page actually stores index entries.
- There are upper and lower bounds on the number of keys on a node.
- Lower bound: every node other than root must have at least t-1 keys => at least t children
- Upper bound: every node can contain at most 2t-1 keys => every internal node has at most 2t children.
- Example is shown as follows:
- Conventions:
- Root of B-tree is always in main memory
- Any node pased as parameter must have had a Disk-Read operation performed on them.
B+-tree
- A B-tree is very efficient with respect to search and modification operations that involve a single record.
- But it is not particularly suited for sequential operations nor for range searches, B+-tree is to solve this issue.
- B+-tree is the most widely used index structure for databases.
- Main idea:
- The leaf nodes contain all the key values (and the associated information)
- The internal nodes (organized as a B-tree) store some separators which have the only function of determining the path to follow during searching
- The leaf nodes are linked in a (doubly linked) list, in order to efficiently support range searches or sequential searches.
- Comparison with B-trees:
- The search of a single key value is in general more expensive in a B+-tree because we have always to reach a leaf node to fetch the pointer to the data file.
- For operations requiring an ordering of the retrieved records according to the search key values or for range queries, the B+-tree is to be preferred.
- The B-tree requires less storage since the key values are stored only once.
B*-tree
- B*-tree is a variation of the B+-tree where the storage utilization for nodes must be at least 66% (2/3) instead of 50%.
- The non-root and non-leaf nodes of B*-tree contain pointers to sibling nodes.
R-tree
- The B-tree and its variants are useful to index and search data in one-dimensional space (where data is stored on disks rather than main memory). The basic idea is to separate a line into several segments and gradually reduce to the minimum segment where the searched data is located, illustrated as follows (figure is obtained from July et al.'s blog):
- However, for high-dimensional data, B-tree and its variants are not efficient. Other tree index structures such as R-tree, kd-tree are more suited in this case.
- R-tree is a generalization of B-tree for indexing and searching multi-dimensional data such as geographical coordinates, rectangles or polygons.
- A commonly real-world usage for an R-tree might be to store spatial objects such as restaurant locations, or the polygons that typical maps are made of scuh as streets, buildings, outlines of lakes, coastlines, etc, and then find answers quickly to queries such as "Find all museums within 2km of my current location". => It is useful for map.
- Main points:
- The key idea is to group nearby objects and represent them with their minimum bounding rectangle in the next higher level of the tree.
- At the leaf level, each rectangle describes a single object; at higher levels, the aggregation of an increasing number of objects.
- R-tree is a balanced search tree (i.e., all leaf nodes are at the same height), organizes the data in pages, and is designed for storage on disk (as used in databases).
- R-tree only guarantees a minimum usage of 30-40%. The reason is the more complex balancing required for spatial data as opposed to linear data stored in B-trees.
- The key difficulty of R-tree is to build an efficient tree that on one hand is balanced, on the other hand the rectangles do not cover too much empty space and do not overlap too much.
- A typical R-tree is represented as follows (figure is originally from Wikipedia).
References
- B-tree: http://en.wikipedia.org/wiki/B-tree
- R-tree: http://en.wikipedia.org/wiki/R-tree
- Lecture notes, CMSC 420, B-trees
- Andreas Kaltenbrunner et al., B-trees
- Other online tutorials
- July et al. 从B 树、B+ 树、B* 树谈到R 树
Study notes for B-tree and R-tree的更多相关文章
- SQLite R*Tree 模块测试
目录 SQLite R*Tree 模块测试 1.SQLite R*Tree 模块特性简介 2.SQLite R*Tree 模块简单测试代码 SQLite R*Tree 模块测试 相关参考: MySQL ...
- Machine Learning Algorithms Study Notes(2)--Supervised Learning
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Machine Learning Algorithms Study Notes(3)--Learning Theory
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- Machine Learning Algorithms Study Notes(1)--Introduction
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 目 录 1 Introduction 1 1.1 ...
- B-Tree、B+Tree和B*Tree
B-Tree(这儿可不是减号,就是常规意义的BTree) 是一种多路搜索树: 1.定义任意非叶子结点最多只有M个儿子:且M>2: 2.根结点的儿子数为[2, M]: 3.除根结点以外的非叶子结点 ...
- 【Luogu1501】Tree(Link-Cut Tree)
[Luogu1501]Tree(Link-Cut Tree) 题面 洛谷 题解 \(LCT\)版子题 看到了顺手敲一下而已 注意一下,别乘爆了 #include<iostream> #in ...
- 【BZOJ3282】Tree (Link-Cut Tree)
[BZOJ3282]Tree (Link-Cut Tree) 题面 BZOJ权限题呀,良心luogu上有 题解 Link-Cut Tree班子提 最近因为NOIP考炸了 学科也炸了 时间显然没有 以后 ...
- [LeetCode] Encode N-ary Tree to Binary Tree 将N叉树编码为二叉树
Design an algorithm to encode an N-ary tree into a binary tree and decode the binary tree to get the ...
- 平衡二叉树(Balanced Binary Tree 或 Height-Balanced Tree)又称AVL树
平衡二叉树(Balanced Binary Tree 或 Height-Balanced Tree)又称AVL树 (a)和(b)都是排序二叉树,但是查找(b)的93节点就需要查找6次,查找(a)的93 ...
- WPF中的Visual Tree和Logical Tree与路由事件
1.Visual Tree和Logical TreeLogical Tree:逻辑树,WPF中用户界面有一个对象树构建而成,这棵树叫做逻辑树,元素的声明分层结构形成了所谓的逻辑树!!Visual Tr ...
随机推荐
- 让Qt支持Win7的Aero和毛玻璃效果
Qt5增加了许多特性,其中 Qt Windows Extras 模块就增加了对Win7 Aero 效果的支持. 官网的介绍如下: Qt Windows Extras provide classes a ...
- hibernate 数据关联一对一 3.2
第一种一对一 person和card,card的id即作为主键,又作为外键 // 各村对方的一个对象 public class Person { private Integer id; privat ...
- BNU 沙漠之旅
http://www.bnuoj.com/bnuoj/problem_show.php?pid=29376 我直接暴力搜索的. 剪枝: 1.步骤最多只有4步,超过4步则退出 2.油的行程相加后的总和距 ...
- android -- 蓝牙 bluetooth (二) 打开蓝牙
4.2的蓝牙打开流程这一部分还是有些变化的,从界面上看蓝牙开关就是设置settings里那个switch开关,widget开关当然也可以,起点不同而已,后续的流程是一样的.先来看systemServe ...
- img 的 align 属性
AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐. AbsMiddle 图像的中间与同一行中最大元素的中间对齐. Baseline 图像的下边缘与第一行文本的下边缘对齐. Bottom ...
- 移动端rem,scale动态设置
pt:物理像素(电容屏上像素块个数) px:逻辑像素.设备独立像素 高清屏:1px = 4pt 普通屏:1px = 1pt dpr:设备像素比:(某一方向上)物理像素/逻辑像素 通常设置1rem=屏幕 ...
- Swipe JS滑动插件
Swipe JS 是一个轻量级的移动滑动组件,支持 1:1 的触摸移动,阻力以及防滑性能都不错,可以让移动web应用展现更多的内容,能解决我们对于移动Web对滑动的需求. 官网:http://www. ...
- 我的Python成长之路---第四天---Python基础(15)---2016年1月23日(寒风刺骨)
二.装饰器 所谓装饰器decorator仅仅是一种语法糖, 可作用的对象可以是函数也可以是类, 装饰器本身是一个函数, 其主要工作方式就是将被装饰的类或者函数当作参数传递给装饰器函数.本质上, ...
- iOS8的屏幕旋转的问题
判断横竖屏.http://www.cocoachina.com/ask/questions/show/121301 //self.cameraView是相机view - (NSUInteger)sup ...
- 为什么国内的网盘公司都在 TB 的级别上竞争,成本会不会太高?(还有好多其它回复)
作者:杜鑫链接:http://www.zhihu.com/question/21591490/answer/18762821来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处 ...