A **B-tree of order $m$** is a tree that satisfies the following properties:
* Every node has at most $m$ children.
* Every node, except for the root, has at least $m / 2$ children.
* All leaves appear on the same level.
* A node with $k$ children contains $k - 1$ keys sorted in monotonically increasing order.
The above is a modification of Knuth's definition in his "Art of Computer Programming" that defines leaves of the tree more consistently with how I use the term elsewhere. It also pulls in concepts from CLRS (such as keys needing to be sorted within nodes).
What is the search runtime of a B-tree of order $m$ and height $h$?
Back: $O(mh)$
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489725-->
END%%
%%ANKI
Basic
*Why* does searching a B-tree of order $m$ and height $h$ take $O(mh)$ time?
Back: Each node may have $m - 1$ keys, and we may check $h$ nodes.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489726-->
END%%
%%ANKI
Basic
How many disk accesses are performed when searching a B-tree of order $m$ and height $h$?
Back: $O(h)$
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489727-->
END%%
%%ANKI
Basic
*Why* does the number of disk accesses when searching a B-tree of height $h$ equal $O(h)$?
Back: The size of each node presumably corresponds to a block of memory.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489728-->
END%%
%%ANKI
Basic
What is the search runtime of a B-tree of order $m$ containing $n$ keys?
Back: $O(m\log_m{n})$
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489729-->
END%%
%%ANKI
Basic
*Why* does searching a B-tree of order $m$ containing $n$ keys take $O(m\log_m{n})$ time?
Back: Each node may have $m - 1$ keys, and we may check $\log_m{n}$ nodes.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489730-->
END%%
%%ANKI
Basic
How many disk accesses are performed when searching a B-tree of order $m$ containing $n$ keys?
Back: $O(\log_m{n})$
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489731-->
END%%
%%ANKI
Basic
*Why* does the number of disk accesses when searching a B-tree of order $m$ containing $n$ keys equal $O(\log_m{n})$?
Back: The size of each node presumably corresponds to a block of memory.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723321489732-->
END%%
## Insertions
A node of a B-tree of order $m$ is considered full when it has $m$ children (or equivalently $m - 1$ keys). Insertion operates analagously to a binary tree. If the node the key was inserted into then contains $m$ keys, split the node into two and place the median into the original parent node. This action may propagate upwards. If the root node becomes full, create a new root containing the median of the original root.
%%ANKI
Cloze
A node in a B-tree of order $m$ is considered full when it has {$m - 1$} keys.
The **B+ tree** is a B-tree with the following differences:
* Internal nodes do not store values; that is, all values are stored in the leaf nodes.
* Leaf nodes may include a pointer to the next leaf node to speed sequential access.
%%ANKI
Basic
What is the *required* distinction between B-trees and B+ trees?
Back: Values in B+ trees are only stored in leaf nodes.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926214-->
END%%
%%ANKI
Basic
In a B-tree, where can values be found?
Back: In any node.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926220-->
END%%
%%ANKI
Basic
In a B+ tree, where can values be found?
Back: In the leaf nodes.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926224-->
END%%
%%ANKI
Basic
What is the *optional* distinction between B-trees and B+ trees?
Back: A B+ tree leaf node may include a pointer to the next leaf node.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926227-->
END%%
%%ANKI
Basic
How is a B+ tree defined in terms of B-trees?
Back: As a B-tree in which all values must reside in the leaf nodes.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926231-->
END%%
%%ANKI
Basic
Why might a B+ tree implementation include pointers from leaf to leaf?
Back: To speed up sequential access.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926235-->
END%%
%%ANKI
Basic
Which of B-trees and B+ trees likely have a higher order?
Back: B+ trees.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926239-->
END%%
%%ANKI
Basic
Why do B+ trees typically have higher orders than B-trees?
Back: Their internal nodes do not have values, leaving room for more keys.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926244-->
END%%
%%ANKI
Basic
Which of B+ trees and B-trees are likely deeper?
Back: B-trees.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
<!--ID: 1723325926249-->
END%%
%%ANKI
Basic
Why are B+ trees typically shallower than B-trees?
Back: Their internal nodes do not have values, leaving room for more keys.
Reference: “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).
* “B-Tree,” in _Wikipedia_, August 7, 2024, [https://en.wikipedia.org/w/index.php?title=B-tree](https://en.wikipedia.org/w/index.php?title=B-tree&oldid=1239132600).