B-Trees - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

B-Trees

Description:

B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries to overcome ... – PowerPoint PPT presentation

Number of Views:98
Avg rating:3.0/5.0
Slides: 33
Provided by: sah130
Category:
Tags: about | trees

less

Transcript and Presenter's Notes

Title: B-Trees


1
B-Trees
  • Large degree B-trees used to represent very large
    dictionaries that reside on disk.
  • Smaller degree B-trees used for internal-memory
    dictionaries to overcome cache-miss penalties.

2
AVL Trees
  • n 230 109 (approx).
  • 30 lt height lt 43.
  • When the AVL tree resides on a disk, up to 43
    disk access are made for a search.
  • This takes up to (approx) 4 seconds.
  • Not acceptable.

3
m-way Search Trees
  • Each node has up to m 1 pairs and m children.
  • m 2 gt binary search tree.

4
4-Way Search Tree
k gt 35
k lt 10
10 lt k lt 30
30 lt k lt 35
5
Definition Of B-Tree
  • Definition assumes external nodes (extended m-way
    search tree).
  • B-tree of order m.
  • m-way search tree.
  • Not empty gt root has at least 2 children.
  • Remaining internal nodes (if any) have at least
    ceil(m/2) children.
  • External (or failure) nodes on same level.

6
2-3 And 2-3-4 Trees
  • B-tree of order m.
  • m-way search tree.
  • Not empty gt root has at least 2 children.
  • Remaining internal nodes (if any) have at least
    ceil(m/2) children.
  • External (or failure) nodes on same level.
  • 2-3 tree is B-tree of order 3.
  • 2-3-4 tree is B-tree of order 4.

7
Insert
8
4
15 20
1 3
5 6
30 40
9
16 17
Insertion into a full leaf triggers bottom-up
node splitting pass.
8
Insert
8
4
15 20
1 3
5 6
30 40
9
16 17
  • Insert a pair with key 2.
  • New pair goes into a 3-node.

9
Insert Into A Leaf 3-node
  • Insert new pair so that the 3 keys are in
    ascending order.
  • Split overflowed node around middle key.
  • Insert middle key and pointer to new node into
    parent.

10
Insert
8
4
15 20
1 3
5 6
30 40
9
16 17
  • Insert a pair with key 2.

11
Insert
8
4
2
15 20
3
1
5 6
30 40
9
16 17
  • Insert a pair with key 2 plus a pointer into
    parent.

12
Insert
  • Now, insert a pair with key 18.

13
Insert Into A Leaf 3-node
  • Insert new pair so that the 3 keys are in
    ascending order.
  • Split the overflowed node.
  • Insert middle key and pointer to new node into
    parent.

14
Insert
  • Insert a pair with key 18.

15
Insert
8
17
2 4
15 20
18
1
5 6
30 40
9
3
16
  • Insert a pair with key 17 plus a pointer into
    parent.

16
Insert
17
8
2 4
15
20
1
18
5 6
30 40
9
3
16
  • Insert a pair with key 17 plus a pointer into
    parent.

17
Insert
  • Now, insert a pair with key 7.

18
Insert
8 17
6
2 4
15
20
7
1
18
30 40
9
3
16
5
  • Insert a pair with key 6 plus a pointer into
    parent.

19
Insert
8 17
4
6
2
15
20
5
7
18
30 40
9
16
1
3
  • Insert a pair with key 4 plus a pointer into
    parent.

20
Insert
8
4
17
6
2
15
20
1
3
5
7
18
30 40
9
16
  • Insert a pair with key 8 plus a pointer into
    parent.
  • There is no parent. So, create a new root.

21
Insert
8
4
17
6
2
15
20
18
30 40
9
16
1
3
5
7
  • Height increases by 1.

22
Delete From A Leaf
  • Delete the pair with key 16.
  • 3-node becomes 2-node.

23
Delete From A Leaf
8
2 4
15 20
1
5 6
30 40
9
3
17
  • Delete the pair with key 17.
  • Deletion from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • If so borrow a pair and a subtree via parent
    node.

24
Delete From A Leaf
8
2 4
15 30
1
5 6
9
3
40
20
  • Delete the pair with key 20.
  • Deletion from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • If not, combine with sibling and parent pair.

25
Delete From A Leaf
8
2 4
15
1
30 40
5 6
9
3
  • Delete the pair with key 30.
  • Deletion from a 3-node.
  • 3-node becomes 2-node.

26
Delete From A Leaf
8
2 4
15
1
5 6
9
3
40
  • Delete the pair with key 3.
  • Deletion from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • If so borrow a pair and a subtree via parent
    node.

27
Delete From A Leaf
8
2 5
15
1
6
9
4
40
  • Delete the pair with key 6.
  • Deletion from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • If not, combine with sibling and parent pair.

28
Delete From A Leaf
8
2
15
1
4 5
9
40
  • Delete the pair with key 40.
  • Deletion from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • If not, combine with sibling and parent pair.

29
Delete From A Leaf
8
2
1
4 5
9 15
  • Parent pair was from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • If not, combine with sibling and parent pair.

30
Delete From A Leaf
2 8
1
4 5
9 15
  • Parent pair was from a 2-node.
  • Check an adjacent sibling and determine if it is
    a 3-node.
  • No sibling, so must be the root.
  • Discard root. Left child becomes new root.

31
Delete From A Leaf
2 8
1
4 5
9 15
  • Height reduces by 1.

32
Delete A Non-Leaf
  • Deletion from interior node is transformed into a
    deletion from a leaf node.
Write a Comment
User Comments (0)
About PowerShow.com