B-Trees: Worst-Case and Average Disk Accesses, Delete Operation and Node Structure, Slides of Computer Science

An in-depth analysis of b-trees, focusing on the worst-case and average number of disk accesses during an insert operation, delete operation, and the structure of b-tree nodes. It covers the concepts of docsity.com, including worst-case disk accesses, average disk accesses, delete from a leaf, delete from a node, and node structure.

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharmakeerti
dharmakeerti 🇮🇳

4.2

(27)

89 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
B-Trees (continued)
Analysis of worst-case and average number
of disk accesses for an insert.
Delete and analysis.
Structure for B-tree node
Worst-Case Disk Accesses
15 20
4
1 3 5 6 30 4013 16 17
7 12
9
810
Insert 2.
Insert 18.
Insert 14.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download B-Trees: Worst-Case and Average Disk Accesses, Delete Operation and Node Structure and more Slides Computer Science in PDF only on Docsity!

B-Trees (continued)

• Analysis of worst-case and average numberof disk accesses for an insert.

• Delete and analysis.• Structure for B-tree node

Worst-Case Disk Accesses

Insert 2. Insert 18.^ Insert 14.

Worst-Case Disk Accesses

• Assume enough memory to hold all h nodesaccessed on way down.

• h read accesses on way down.• 2s+1 write accesses on way up, s = number

• Total h+2s+1 disk accesses.of nodes that split.

• Max is 3h+1.

• Start with empty B-tree.^ Average Disk Accesses

  • •• Insert n pairs.Resulting B-tree has p nodes.# splits <= p –2, p > 2.

• • # pairs >= 1+(ceil(m/2)savg <= (p – 2)/(1+(ceil(m/2) – 1)(p – – 1)(p 1). – 1)).

  • •• So, sm = 200 => sAverage disk accesses < h + 2/99 + 1 ~ h + 1.avg < 1/(ceil(m/2) – 1).avg < 1/99.
  • Nearly minimum.

Delete From A Leaf

  • Delete the pair with key = 16.• 3-node becomes 2-node.

Delete From A Leaf

  • 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.

Delete From A Leaf

  • 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.

Delete From A Leaf

  • Delete the pair with key = 30.• Deletion from a 3-node.
  • 3-node becomes 2-node.

Delete From A Leaf 8

  • Delete the pair with key = 40.^1 4 5
  • 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.

Delete From A Leaf 8

  • Parent pair was from a 2-node.^1 4
  • Check an adjacent sibling and determine if it is a 3-node.• If not, combine with sibling and parent pair.

Delete From A Leaf

  • Parent pair was from a 2-node.^1 4
  • 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.

Delete From A Leaf

  • Height reduces by 1.

Worst-Case Disk Accesses

• Assume enough memory to hold all h nodes• h read accesses on way down.accessed on way down.

• h• h – – 1 sibling read accesses on way up.2 writes of combined nodes on way up.

• 3 writes of root and level 2 nodes for sibling• Total is 3h.borrowing at level 2.

• Start with B-tree that has n pairs and p nodes.^ Average Disk Accesses

• Delete the pairs one by one.• n >= 1+(ceil(m/2) – 1)(p – 1).

• p <= 1 + (n – 1)/(ceil(m/2) – 1).• Upper bound on total number of disk accesses.

  Each delete does a borrow.The deletes together do at most p –1 combines/merges.

• # accesses <= n(h+4) + 2(p – 1).

Average Disk Accesses

• Average # accesses <= [n(h+4) + 2(p – 1)]/ n~h + 4.

• Nearly minimum.

Worst Case

• Alternating sequence of inserts and deletes.• Each insert does h splits at a cost of 3h + 1

• Each delete moves back up to root at a costdisk accesses.

• Average for this sequence is 3h + 1 for anof 3h disk accesses.

insert and 3h for a delete.

Node Operations For Insert

  Find middle pair.3-way split around middle pair.

ceil(m/2)-1 a^ m a^0 p^1 a^1 p^2 a^2 … pm^ am

m-ceil(m/2) a^0 ceil(m/2)p^1 a^1 p 2 p^ aceil(m/2)+1^2 … pceil(m/2)-1 aceil(m/2)+1^ aceil(m/2)-1 … pm am

 Insert a dictionary pair and a pointer (p, a).

Node Operations For Delete

  • • Delete a dictionary pair.Borrow.  Delete, replace, insert.
  • Combine.  3-way join.

Node Structure

• Each B-tree node is an array partitioned intoindexed red-black tree nodes that will keep onedictionary pair each.

• Indexed red-black tree is built using simulatedpointers (integer pointers).

Complexity Of B-Tree NodeOperations

• Search a B-tree node … O(log m).• Find middle pair … O(log m).

• Insert a pair … O(log m).• Delete a pair … O(log m).

• Split a B-tree node … O(log m).• Join 2 B-tree nodes … O(m).

 Need to copy indexed red-black tree that representsone B-tree node into the array space of the other B-tree node.