diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index 1c88ee1..ab0ba15 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -186,7 +186,12 @@ "complete-tree.png", "non-complete-tree.png", "relation-ordering-example.png", - "infinite-cartesian-product.png" + "infinite-cartesian-product.png", + "b-tree-full-node.png", + "b-tree-split-node.png", + "b-tree-initial.png", + "b-tree-inserted-b.png", + "b-tree-inserted-q.png" ], "File Hashes": { "algorithms/index.md": "3ac071354e55242919cc574eb43de6f8", @@ -720,8 +725,10 @@ "_journal/2024-08/2024-08-07.md": "119c052f4109a3e098d825b771af89de", "_journal/2024-08-09.md": "2ce3e0c468f51750d8ad86a19bcc3264", "_journal/2024-08/2024-08-08.md": "b8211a4c576ff594217e2e9cae9396c0", - "data-structures/b-tree.md": "b6085d090b65e457e29d6d36cf4b226a", - "data-structures/binary-tree.md": "67b0b5b9688faa205983993fe507079a" + "data-structures/b-tree.md": "5f5e6f483ce6beca9fb3a4cd96264e22", + "data-structures/binary-tree.md": "67b0b5b9688faa205983993fe507079a", + "_journal/2024-08-10.md": "9e4c7c2c0fd9e855d5cf6b5eff18b111", + "_journal/2024-08/2024-08-09.md": "2ce3e0c468f51750d8ad86a19bcc3264" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-08-10.md b/notes/_journal/2024-08-10.md new file mode 100644 index 0000000..b142597 --- /dev/null +++ b/notes/_journal/2024-08-10.md @@ -0,0 +1,12 @@ +--- +title: "2024-08-10" +--- + +- [x] Anki Flashcards +- [x] KoL +- [ ] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Read through Chapter 3 of "Modern C". +* Notes on B-tree insertions. \ No newline at end of file diff --git a/notes/_journal/2024-08-09.md b/notes/_journal/2024-08/2024-08-09.md similarity index 100% rename from notes/_journal/2024-08-09.md rename to notes/_journal/2024-08/2024-08-09.md diff --git a/notes/data-structures/b-tree.md b/notes/data-structures/b-tree.md index 4f35964..cd40cec 100644 --- a/notes/data-structures/b-tree.md +++ b/notes/data-structures/b-tree.md @@ -18,6 +18,30 @@ A **B-tree of order $m$** is a tree that satisfies the following properties: 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). +%%ANKI +Basic +Why is a B-tree named the way it is? +Back: There is no definitive answer. +Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). + +END%% + +%%ANKI +Basic +What was the motivation behind the development of the B-tree? +Back: To find a data structure for efficient search that minimizes disk accesses. +Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). + +END%% + +%%ANKI +Basic +How is the order of a B-tree typically determined? +Back: By choosing a value that best aligns with the size of a memory block. +Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). + +END%% + %%ANKI Basic What hyperparameter is used to define a B-tree? @@ -106,14 +130,6 @@ Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Sear END%% -%%ANKI -Basic -*When* does a B-tree gain height? -Back: When the root node is split. -Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). - -END%% - %%ANKI Basic Consider a B-tree of order $7$. How many children $c$ can each non-root node have? @@ -172,26 +188,179 @@ END%% %%ANKI Basic -Why is a B-tree named the way it is? -Back: There is no definitive answer. -Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). - +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). + END%% %%ANKI Basic -What was the motivation behind the development of the B-tree? -Back: To find a data structure for efficient search that minimizes disk accesses. -Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). - +*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). + END%% %%ANKI Basic -How is the order of a B-tree typically determined? -Back: By choosing a value that best aligns with the size of a memory block. +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). + +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). + +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). + +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). + +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). + +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). + +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. Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). - + +END%% + +%%ANKI +Cloze +A node in a B-tree of order $m$ is considered full when it has {$m$} children. +Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). + +END%% + +%%ANKI +Basic +Which key(s) found in B-trees move levels during node splits? +Back: The split node's median key. +Reference: Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +What does it mean for a B-tree split to be left-biased? +Back: Prefer the median on the LHS. +Reference: Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +What does it mean for a B-tree split to be right-biased? +Back: Prefer the median on the RHS. +Reference: Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Consider splitting a node in a B-tree of order $m$. How many keys are in the split nodes? +Back: $\lfloor (m - 1) / 2 \rfloor$ and $\lceil (m - 1) / 2 \rceil$. +Reference: Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +*When* does a B-tree gain height? +Back: When the root node is split. +Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). + +END%% + +%%ANKI +Basic +Suppose the following B-tree node is full. What is the result after splitting? +![[b-tree-full-node.png]] +Back: +![[b-tree-split-node.png]] +Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995). + +END%% + +%%ANKI +Basic +Consider the following B-tree. What is the result of inserting `B`? +![[b-tree-initial.png]] +Back: Indeterminate. We do not know the order of the tree. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Consider the following B-tree of order $6$. What is the result of inserting `B`? +![[b-tree-initial.png]] +Back: +![[b-tree-inserted-b.png]] +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Consider the following B-tree of order $6$. What is the result of inserting `Q` (right biased)? +![[b-tree-inserted-b.png]] +Back: +![[b-tree-inserted-q.png]] +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +What is the insertion 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). + +END%% + +%%ANKI +Basic +How many disk accesses are performed when inserting into 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). + END%% ## Bibliography diff --git a/notes/data-structures/images/b-tree-full-node.png b/notes/data-structures/images/b-tree-full-node.png new file mode 100644 index 0000000..aaf7836 Binary files /dev/null and b/notes/data-structures/images/b-tree-full-node.png differ diff --git a/notes/data-structures/images/b-tree-initial.png b/notes/data-structures/images/b-tree-initial.png new file mode 100644 index 0000000..02efc5a Binary files /dev/null and b/notes/data-structures/images/b-tree-initial.png differ diff --git a/notes/data-structures/images/b-tree-inserted-b.png b/notes/data-structures/images/b-tree-inserted-b.png new file mode 100644 index 0000000..e803a38 Binary files /dev/null and b/notes/data-structures/images/b-tree-inserted-b.png differ diff --git a/notes/data-structures/images/b-tree-inserted-q.png b/notes/data-structures/images/b-tree-inserted-q.png new file mode 100644 index 0000000..ee434cd Binary files /dev/null and b/notes/data-structures/images/b-tree-inserted-q.png differ diff --git a/notes/data-structures/images/b-tree-split-node.png b/notes/data-structures/images/b-tree-split-node.png new file mode 100644 index 0000000..42cf753 Binary files /dev/null and b/notes/data-structures/images/b-tree-split-node.png differ