15
1 Root B+Tree Example n=3 100 120 150 180 30 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200

Root

Embed Size (px)

DESCRIPTION

Root. B+Tree Example n=3. 100. 120 150 180. 30. 3 5 11. 120 130. 180 200. 100 101 110. 150 156 179. 30 35. 1. B+ tree i n textbook’s notation n=3. Leaf: Non-leaf:. 30 35. 30. 35. 30. 30. 2. Size of nodes:n+1 pointers n keys. (fixed). 3. - PowerPoint PPT Presentation

Citation preview

Page 1: Root

1

Root

B+Tree Example n=3

100

120

150

180

30

3 5 11

30

35

100

101

110

120

130

150

156

179

180

200

Page 2: Root

2

B+ tree in textbook’s notationn=3

Leaf:

Non-leaf:

30

35

30

30 35

30

Page 3: Root

3

Size of nodes: n+1 pointers

n keys (fixed)

Page 4: Root

4

Don’t want nodes to be too empty

• Use at least

Non-leaf: (n+1)/2 pointers

Leaf: (n+1)/2 pointers to data

Page 5: Root

5

B+tree rules tree of order n

(1) All leaves at same lowest level(balanced tree)

(2) Pointers in leaves point to recordsexcept for “sequence pointer”

(to next leaf)

Page 6: Root

6

(3) Number of pointers/keys for B+tree

Non-leaf(non-root) n+1 n (n+1)/2 (n+1)/2- 1

Leaf(non-root) n+1 n

Root n+1 n 1 1

Max Max Min Min ptrs keys ptrsdata keys

(n+1)/2 (n+1)/2

Page 7: Root

7

Insert into B+tree

(a) simple case (insert 32)– space available in leaf

(b) leaf overflow (insert 7)

(c) non-leaf overflow (insert 160)

(d) new root (insert 45)

Page 8: Root

8

(a) Simple case - no example

(b) Coalesce with neighbor (delete 50)

(c) Re-distribute keys (delete 50)

(d) Cases (b) or (c) at non-leaf (delete 37)

Deletion from B+tree

Page 9: Root

9

B+tree deletions in practice

– Often, coalescing is not implemented– Too hard and not worth it!

Page 10: Root

10

Variation on B+tree: B-tree (no +)

• Idea:– Avoid duplicate keys (leaf and non-leaf)

– Have record pointers in non-leaf nodes

Page 11: Root

11

to record to record to record with K1 with K2 with K3

to keys to keys to keys to keys < K1 K1<x<K2 K2<x<k3 >k3

K1 P1 K2 P2 K3 P3

Page 12: Root

12

B-tree example n=2

65

125

145

165

85

105

25

45

10

20

30

40

110

120

90

100

70

80

170

180

50

60

130

140

150

160

Page 13: Root

13

B-tree example n=2

65

125

145

165

85

105

25

45

10

20

30

40

110

120

90

100

70

80

170

180

50

60

130

140

150

160

• sequence pointers not useful now! (but keep space for simplicity)

Page 14: Root

14

Note on inserts

• Say we insert record with key = 25

10

20

30 n=3

leaf

Page 15: Root

15

Note on inserts

• Say we insert record with key = 25

10

20

30 n=3

leaf

10

– 20 –

25

30

• Afterwards: