B-trees, binary trees, and trichotomy.

main
Joshua Potter 2024-08-09 17:15:58 -06:00
parent 618e016c1a
commit 3f1b3ec054
17 changed files with 946 additions and 496 deletions

View File

@ -31,7 +31,52 @@
"nix": "",
"posix": "",
"templates": "",
"algorithms/sorting": ""
"algorithms/sorting": "",
"_journal": "",
"_templates": "",
"abstract-data-types": "",
"algebra": "",
"binary": "",
"c17": "",
"combinatorics": "",
"data-structures": "",
"encoding": "",
"filesystems": "",
"formal-system": "",
"git": "",
"hashing": "",
"lambda-calculus": "",
"ontology": "",
"programming": "",
"proofs": "",
"set": "",
"startups": "",
"x86-64": "",
"_journal/2024-01": "",
"_journal/2024-02": "",
"_journal/2024-03": "",
"_journal/2024-04": "",
"_journal/2024-05": "",
"_journal/2024-06": "",
"_journal/2024-07": "",
"_journal/2024-08": "",
"algebra/images": "",
"algebra/sequences": "",
"algorithms/images": "",
"combinatorics/images": "",
"data-structures/images": "",
"encoding/images": "",
"formal-system/logical-system": "",
"formal-system/proof-system": "",
"hashing/images": "",
"lambda-calculus/images": "",
"logic/classical": "",
"ontology/philosophy": "",
"ontology/rdf": "",
"set/images": "",
"x86-64/instructions": "",
"algebra/sequences/images": "",
"ontology/rdf/images": ""
},
"FOLDER_TAGS": {
"algorithms": "",
@ -44,7 +89,52 @@
"nix": "",
"posix": "",
"templates": "",
"algorithms/sorting": ""
"algorithms/sorting": "",
"_journal": "",
"_templates": "",
"abstract-data-types": "",
"algebra": "",
"binary": "",
"c17": "",
"combinatorics": "",
"data-structures": "",
"encoding": "",
"filesystems": "",
"formal-system": "",
"git": "",
"hashing": "",
"lambda-calculus": "",
"ontology": "",
"programming": "",
"proofs": "",
"set": "",
"startups": "",
"x86-64": "",
"_journal/2024-01": "",
"_journal/2024-02": "",
"_journal/2024-03": "",
"_journal/2024-04": "",
"_journal/2024-05": "",
"_journal/2024-06": "",
"_journal/2024-07": "",
"_journal/2024-08": "",
"algebra/images": "",
"algebra/sequences": "",
"algorithms/images": "",
"combinatorics/images": "",
"data-structures/images": "",
"encoding/images": "",
"formal-system/logical-system": "",
"formal-system/proof-system": "",
"hashing/images": "",
"lambda-calculus/images": "",
"logic/classical": "",
"ontology/philosophy": "",
"ontology/rdf": "",
"set/images": "",
"x86-64/instructions": "",
"algebra/sequences/images": "",
"ontology/rdf/images": ""
},
"Syntax": {
"Begin Note": "%%ANKI",
@ -73,79 +163,8 @@
]
},
"Added Media": [
"insertion-sort.gif",
"selection-sort.gif",
"bubble-sort.gif",
"lattice-path-chessboard.png",
"lattice-path-chessboard-colored.png",
"lattice-path-before-recurrence.png",
"lattice-path-after-recurrence.png",
"merge-sort.gif",
"theta-notation.png",
"big-o-notation.png",
"big-omega-notation.png",
"ordering-y-repetition-y.jpg",
"ordering-repetition.jpg",
"ordering-y-repetition-n.jpg",
"ordering-n-repetition-y.jpg",
"ordering-n-repetition-n.jpg",
"triangular-gnomon.png",
"pascals-triangle.webp",
"square-gnomon.png",
"floor-negative.png",
"floor-positive.png",
"ceil-positive.png",
"ceil-negative.png",
"pascals-triangle.png",
"normalized-form.png",
"denormalized-form.png",
"infinity.png",
"nan.png",
"directed-graph-example.png",
"undirected-graph-example.png",
"free-tree.png",
"forest.png",
"cyclic-undirected.png",
"rooted-tree.png",
"ordered-rooted-tree.png",
"ordered-rooted-tree-cmp.png",
"ordered-binary-tree-cmp.png",
"complete-tree.png",
"nearly-complete-tree.png",
"non-nearly-complete-tree.png",
"perfect-tree.png",
"non-complete-tree.png",
"max-heap-tree.png",
"max-heap-array.png",
"max-heapify-1.png",
"max-heapify-2.png",
"heapsort.gif",
"array-1d-row-major.png",
"array-1d-col-major.png",
"array-multi-row-major.png",
"array-multi-col-major.png",
"graph-isomorphic.png",
"graph-induced-subgraph.png",
"graph-subgraph.png",
"graph-non-subgraph.png",
"lcrs-nodes.png",
"binary-tree-nodes.png",
"venn-diagram-union.png",
"venn-diagram-intersection.png",
"venn-diagram-rel-comp.png",
"venn-diagram-abs-comp.png",
"venn-diagram-symm-diff.png",
"relation-ordering-example.png",
"open-addressing.png",
"closed-addressing.png",
"function-bijective.png",
"function-injective.png",
"function-surjective.png",
"function-general.png",
"church-rosser.png",
"infinite-cartesian-product.png",
"function-kernel.png",
"triple-table-repr.png",
"open-addressing.png",
"binary-search-tree.png",
"bst-right-child.png",
"bst-right-child-after.png",
@ -154,7 +173,20 @@
"bst-right-succ.png",
"bst-right-succ-after.png",
"bst-deep-succ.png",
"bst-deep-succ-after.png"
"bst-deep-succ-after.png",
"free-tree.png",
"forest.png",
"cyclic-undirected.png",
"rooted-tree.png",
"ordered-rooted-tree-cmp.png",
"ordered-binary-tree-cmp.png",
"lcrs-nodes.png",
"binary-tree-nodes.png",
"perfect-tree.png",
"complete-tree.png",
"non-complete-tree.png",
"relation-ordering-example.png",
"infinite-cartesian-product.png"
],
"File Hashes": {
"algorithms/index.md": "3ac071354e55242919cc574eb43de6f8",
@ -334,7 +366,7 @@
"_journal/2024-03-18.md": "8479f07f63136a4e16c9cd07dbf2f27f",
"_journal/2024-03/2024-03-17.md": "23f9672f5c93a6de52099b1b86834e8b",
"set/directed-graph.md": "b4b8ad1be634a0a808af125fe8577a53",
"set/index.md": "6670c57f29c84eef8dcfff7a8901befe",
"set/index.md": "b43367d200334c53d66fc85a876b9524",
"set/graphs.md": "f0cd201673f2a999321dda6c726e8734",
"_journal/2024-03-19.md": "a0807691819725bf44c0262405e97cbb",
"_journal/2024-03/2024-03-18.md": "63c3c843fc6cfc2cd289ac8b7b108391",
@ -355,7 +387,7 @@
"x86-64/declarations.md": "75bc7857cf2207a40cd7f0ee056af2f2",
"x86-64/instructions.md": "06b7fbe1a7a9568b80239310eb72e87a",
"git/refs.md": "e20c2c9b14ba6c2bd235416017c5c474",
"set/trees.md": "f21182d92a480613f18c0a9d8839fb57",
"set/trees.md": "7fe6c967b4221afff80ec0a3a85517c5",
"_journal/2024-03-24.md": "1974cdb9fc42c3a8bebb8ac76d4b1fd6",
"_journal/2024-03/2024-03-23.md": "ad4e92cc2bf37f174a0758a0753bf69b",
"_journal/2024-03/2024-03-22.md": "a509066c9cd2df692549e89f241d7bd9",
@ -457,7 +489,7 @@
"_journal/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b",
"_journal/2024-05/2024-05-12.md": "ca9f3996272152ef89924bb328efd365",
"git/remotes.md": "cbe2cd867f675f156e7fe71ec615890d",
"programming/pred-trans.md": "2bf52362367f22f23353fcc1c8069b83",
"programming/pred-trans.md": "3c112418e7aa0970a9c38216a65b0932",
"set/axioms.md": "063955bf19c703e9ad23be2aee4f1ab7",
"_journal/2024-05-14.md": "f6ece1d6c178d57875786f87345343c5",
"_journal/2024-05/2024-05-13.md": "71eb7924653eed5b6abd84d3a13b532b",
@ -472,7 +504,7 @@
"_journal/2024-05/2024-05-16.md": "9fdfadc3f9ea6a4418fd0e7066d6b10c",
"_journal/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c",
"hashing/direct-addressing.md": "f75cc22e74ae974fe4f568a2ee9f951f",
"hashing/index.md": "760d1fad7a890814afecfd29c6675f67",
"hashing/index.md": "3a0fb5369b0d3adac5ac13b8b3689e2e",
"set/classes.md": "6776b4dc415021e0ef60b323b5c2d436",
"_journal/2024-05-19.md": "fddd90fae08fab9bd83b0ef5d362c93a",
"_journal/2024-05/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c",
@ -495,7 +527,7 @@
"_journal/2024-05/2024-05-25.md": "3e8a0061fa58a6e5c48d12800d1ab869",
"_journal/2024-05-27.md": "b36636d10eab34380f17f288868df3ae",
"_journal/2024-05/2024-05-26.md": "abe84b5beae74baa25501c818e64fc95",
"algebra/set.md": "30a13f1db3c53dbff179eca2873d7732",
"algebra/set.md": "97ee8ac4f147ed64496b8a757265d1d9",
"algebra/boolean.md": "fc47edb7d0080b73ce1ce0d3e0e16d7d",
"git/merge-conflicts.md": "761ad6137ec51d3877f7d5b3615ca5cb",
"_journal/2024-05-28.md": "0f6aeb5ec126560acdc2d8c5c6570337",
@ -520,7 +552,7 @@
"_journal/2024-06/2024-06-04.md": "52b28035b9c91c9b14cef1154c1a0fa1",
"_journal/2024-06-06.md": "3f9109925dea304e7172df39922cc95a",
"_journal/2024-06/2024-06-05.md": "b06a0fa567bd81e3b593f7e1838f9de1",
"set/relations.md": "9f59faf0f21dfe49ad89ac6e8115d269",
"set/relations.md": "4d7a00c8f68d5f72b4ab365b9b553f2c",
"_journal/2024-06-07.md": "795be41cc3c9c0f27361696d237604a2",
"_journal/2024-06/2024-06-06.md": "db3407dcc86fa759b061246ec9fbd381",
"_journal/2024-06-08.md": "b20d39dab30b4e12559a831ab8d2f9b8",
@ -608,7 +640,7 @@
"_journal/2024-07-13.md": "13b5101306b5542b8a1381a6477378ca",
"_journal/2024-07/2024-07-12.md": "6603ed8a3f9a9e87bf40e81b03e96356",
"hashing/static.md": "3ec6eaee73fb9b599700f5a56b300b83",
"hashing/addressing.md": "a5245396e39e11a012e786232b09a75b",
"hashing/addressing.md": "583da2fc0320a2f1daacc0e01ca66d83",
"ontology/index.md": "0994403dcd84415f1459752129b55f65",
"ontology/permissivism.md": "643e815a79bc5c050cde9f996aa44ef5",
"ontology/properties.md": "91ece501551c444afcd119d7197958ef",
@ -669,7 +701,7 @@
"_journal/2024-07/2024-07-28.md": "ff5dcfb3dc1b5592894363414e20b02f",
"_journal/2024-07-30.md": "025194b9b770b56a81b5a52d96a305f2",
"_journal/2024-07/2024-07-29.md": "ab496a55aacc60d9456378920c599871",
"data-structures/binary-search-tree.md": "34127d93a49d7c947008a37fecfe74ac",
"data-structures/binary-search-tree.md": "07c1a1640f5b1c6ac08aa028e61d8e2d",
"_journal/2024-08-01.md": "2e3da352cfbaf29b6b49e3c3a4f090df",
"_journal/2024-07/2024-07-31.md": "d397c5a4d42660eeaa290aa8316d55c1",
"_journal/2024-07/2024-07-30.md": "025194b9b770b56a81b5a52d96a305f2",
@ -679,7 +711,17 @@
"_journal/2024-08/2024-08-01.md": "2e3da352cfbaf29b6b49e3c3a4f090df",
"_journal/2024-08-04.md": "f3675ba4cd33f16a5695732bbe10473e",
"_journal/2024-08/2024-08-03.md": "7c1d3dbaf47d1120bb879110e827d1b3",
"c17/pointers.md": "c80957f5cab7403b85bcabcc9ce983ef"
"c17/pointers.md": "c80957f5cab7403b85bcabcc9ce983ef",
"_journal/2024-08-07.md": "0a71a471b2eb6b3d45c663e1eaa553e9",
"_journal/2024-08/2024-08-06.md": "ecb72760daef7db26825c59add0dc040",
"_journal/2024-08/2024-08-05.md": "632d0ccd84817d8f2b22275df6d433c0",
"_journal/2024-08/2024-08-04.md": "3838fa18f564e05586ebf3fed80e0ba5",
"_journal/2024-08-08.md": "efad4bb9a4842bedb5d1bc5f32af9918",
"_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": "229b32beb004364b213d2ef86c69c98f",
"data-structures/binary-tree.md": "67b0b5b9688faa205983993fe507079a"
},
"fields_dict": {
"Basic": [

View File

@ -0,0 +1,12 @@
---
title: "2024-08-09"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)
* First pass on [[b-tree|B-tree]] notes.
* Notes on [[relations#Trichotomy|trichotomy]].

View File

@ -0,0 +1,11 @@
---
title: "2024-08-04"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)
* Expanded notes on C [[c17/declarations|declarations]].

View File

@ -1,5 +1,5 @@
---
title: "2024-08-04"
title: "2024-08-05"
---
- [x] Anki Flashcards

View File

@ -0,0 +1,9 @@
---
title: "2024-08-06"
---
- [ ] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)

View File

@ -0,0 +1,9 @@
---
title: "2024-08-07"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)

View File

@ -0,0 +1,11 @@
---
title: "2024-08-08"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)
* Reading on B-trees in "Introduction to Algorithms".

View File

@ -55,6 +55,22 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre
<!--ID: 1717554445670-->
END%%
%%ANKI
Basic
Is the symmetric difference commutative?
Back: Yes.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187675-->
END%%
%%ANKI
Basic
Is the symmetric difference associative?
Back: Yes.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187680-->
END%%
## Cartesian Product
Given two sets $A$ and $B$, the **Cartesian product** $A \times B$ is defined as: $$A \times B = \{\langle x, y \rangle \mid x \in A \land y \in B\}$$

View File

@ -0,0 +1,176 @@
---
title: B-Tree
TARGET DECK: Obsidian::STEM
FILE TAGS: data_structure::b-tree
tags:
- b-tree
- data_structure
---
## Overview
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).
%%ANKI
Basic
What hyperparameter is used to define a B-tree?
Back: It's order, i.e. the maximum number of a children a node can have.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211541967-->
END%%
%%ANKI
Basic
In what direction do B-trees grow?
Back: From bottom to top.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211541998-->
END%%
%%ANKI
Basic
Consider B-tree of order $m$. What does $m$ refer to?
Back: The maximum number of children a node can have.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542004-->
END%%
%%ANKI
Basic
What is the maximum number of children a node in a B-tree have?
Back: N/A. It depends on the tree's order.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542010-->
END%%
%%ANKI
Basic
What is the maximum number of children a node in a B-tree of order $m$ can have?
Back: $m$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542016-->
END%%
%%ANKI
Basic
What is the minimum number of children a non-root node in a B-tree of order $m$ can have?
Back: $\lceil m / 2 \rceil$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542022-->
END%%
%%ANKI
Basic
What is the maximum number of keys a node in a B-tree of order $m$ can have?
Back: $m - 1$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542028-->
END%%
%%ANKI
Basic
What is the minimum number of keys a non-root node in a B-tree can have?
Back: N/A. It depends on the tree's order.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542035-->
END%%
%%ANKI
Basic
What is the minimum number of keys a non-root node in a B-tree of order $m$ can have?
Back: $\lceil m / 2 \rceil - 1$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542041-->
END%%
%%ANKI
Basic
A node in a B-tree of order $m$ has $k$ keys. How many children does it have?
Back: $k + 1$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542046-->
END%%
%%ANKI
Basic
A node in a B-tree of order $m$ has $k$ children. How many keys does it have?
Back: $k - 1$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542052-->
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).
<!--ID: 1723211542058-->
END%%
%%ANKI
Basic
Consider a B-tree of order $7$. How many children $c$ can each non-root node have?
Back: $4 \leq c \leq 7$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542063-->
END%%
%%ANKI
Basic
Consider a B-tree of order $7$. How many children $c$ can the root have?
Back: $0 \leq c \leq 7$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542069-->
END%%
%%ANKI
Basic
Consider a B-tree of order $7$. How many keys $k$ can each non-root node have?
Back: $3 \leq k < 7$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542076-->
END%%
%%ANKI
Basic
Consider a B-tree of order $7$. How many keys $k$ can the root have?
Back: $0 \leq k < 7$
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542082-->
END%%
%%ANKI
Basic
What instances exist of a B-tree of order $1$?
Back: Just the empty tree.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542088-->
END%%
%%ANKI
Basic
*Why* can't we define a nonempty B-tree of order $1$?
Back: Each node can have at most $1$ child, meaning each node contains $0$ keys.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542094-->
END%%
%%ANKI
Basic
How are keys arranged within a B-tree's nodes?
Back: In monotonically increasing order.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542105-->
END%%
## Bibliography
* Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
* Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -13,6 +13,14 @@ A binary search tree (BST) is a [[trees#Binary Trees|binary tree]] satisfying th
> Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $y.key \geq x.key$.
%%ANKI
Basic
*Why* can't we define a binary search tree as a B-tree of order $2$?
Back: A BST isn't guaranteed to be balanced.
Reference: Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
<!--ID: 1723211542110-->
END%%
## Traversals
Consider an arbitrary node $x$ of some BST. Then:
@ -455,14 +463,6 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (
<!--ID: 1722713303038-->
END%%
%%ANKI
Basic
When does insertion into a BST modify the root node?
Back: When the tree being inserted into is empty.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1722713303039-->
END%%
%%ANKI
Basic
In terms of the height $h$ of a BST, what is the runtime for inserting a node?
@ -522,7 +522,7 @@ END%%
%%ANKI
Basic
Delete BST node $z$ with two children. If replacing with its predecessor, what two subcases need to be considered?
Back: If $z$'s predessor is its left child or not.
Back: If $z$'s predecessor is its left child or not.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1722713303047-->
END%%
@ -586,4 +586,5 @@ END%%
## Bibliography
* Donald Ervin Knuth, _Art of Computer Programming, 3: Sorting and Searching_, 2. ed., 34. (Reading, Mass: Addison-Wesley, 1995).
* Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -0,0 +1,417 @@
---
title: Binary Tree
TARGET DECK: Obsidian::STEM
FILE TAGS: data_structure::bst
tags:
- data_structure
- graph
- tree
---
## Overview
A **binary tree** $T$ is a structure defined on a finite set of nodes that either
* contains no nodes, or
* is composed of three disjoint sets of nodes: a **root** node, a **left subtree**, and a **right subtree**.
The binary tree is a specialization of the [[trees#Positional Trees|k-ary tree]].
%%ANKI
Basic
Is a binary tree a $k$-ary tree?
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714089436138-->
END%%
%%ANKI
Basic
Is a binary tree a positional tree?
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
Is a binary tree an ordered tree?
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714089436144-->
END%%
%%ANKI
Basic
What does it mean for a binary tree to be full?
Back: Each node has $0$ or $2$ children.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1713118128213-->
END%%
%%ANKI
Basic
What does it mean for a binary tree to be perfect?
Back: Each leaf has the same depth and all internal nodes have degree $2$.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594570-->
END%%
%%ANKI
Basic
Is a perfect binary tree considered full?
Back: Yes.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438720-->
END%%
%%ANKI
Basic
Is a full binary tree considered perfect?
Back: Not necessarily.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438726-->
END%%
%%ANKI
Basic
Is a full binary tree considered complete?
Back: Not necessarily.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438729-->
END%%
%%ANKI
Basic
Is a complete binary tree considered full?
Back: Not necessarily.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438733-->
END%%
%%ANKI
Basic
What alternative term is sometimes used in favor of a "perfect binary tree"?
Back: A "complete binary tree".
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438737-->
END%%
%%ANKI
Basic
What alternative term is sometimes used in favor over a "complete binary tree"?
Back: Some authors may say "nearly complete" if the last level isn't completely filled.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438744-->
END%%
%%ANKI
Basic
What degrees are permitted in a full binary tree?
Back: $0$ or $2$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594576-->
END%%
%%ANKI
Basic
What degrees are permitted in a perfect binary tree?
Back: $0$ or $2$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594579-->
END%%
%%ANKI
Basic
What category of rooted tree does a binary tree fall under?
Back: A positional tree or $k$-ary tree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594582-->
END%%
%%ANKI
Basic
Is a binary tree a positional tree?
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1713118128227-->
END%%
%%ANKI
Basic
How many nodes are in a perfect binary tree of height $h$?
Back: $2^{h+1} - 1$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1713118128255-->
END%%
%%ANKI
Basic
How many internal nodes are in a perfect binary tree of height $h$?
Back: $2^h - 1$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353472-->
END%%
%%ANKI
Basic
How many external nodes are in a perfect binary tree of height $h$?
Back: $2^h$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353469-->
END%%
%%ANKI
Basic
How many nodes are on level $d$ of a perfect binary tree?
Back: $2^d$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353465-->
END%%
%%ANKI
Basic
How does the number of internal nodes compare to the number of external nodes in a perfect binary tree?
Back: There is one more external node than internal node.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353476-->
END%%
%%ANKI
Basic
Is the following a perfect binary tree?
![[perfect-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419777-->
END%%
%%ANKI
Basic
Is the following a complete binary tree?
![[perfect-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419781-->
END%%
%%ANKI
Basic
Is the following a full binary tree?
![[perfect-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419784-->
END%%
%%ANKI
Basic
Is the following a perfect binary tree?
![[complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419787-->
END%%
%%ANKI
Basic
Is the following a complete binary tree?
![[complete-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419789-->
END%%
%%ANKI
Basic
Is the following a full binary tree?
![[complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419793-->
END%%
%%ANKI
Basic
Is the following a perfect binary tree?
![[non-complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419802-->
END%%
%%ANKI
Basic
Is the following a complete binary tree?
![[non-complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419809-->
END%%
%%ANKI
Basic
Is the following a full binary tree?
![[non-complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419813-->
END%%
%%ANKI
Basic
What is the minimum number of nodes in a complete binary tree of height $h$?
Back: $2^h$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714082676010-->
END%%
%%ANKI
Basic
What is the base case used in the recursive definition of a binary tree?
Back: The empty set.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1712409466593-->
END%%
%%ANKI
Basic
What recurrence is used in the recursive definition of a binary tree?
Back: A binary tree is composed of a root node, a left subtree, and a right subtree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1712409466606-->
END%%
%%ANKI
Basic
How should the nil constructor of an inductive binary tree, say `Tree`, be defined?
Back:
```lean
| nil : Tree α
```
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466615-->
END%%
%%ANKI
Basic
How should the non-nil constructor of an inductive binary tree, say `Tree`, be defined?
Back:
```lean
| node : α → Tree α → Tree α → Tree α
```
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466621-->
END%%
%%ANKI
Basic
In the following binary tree type, what name is given to the first argument of `node`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: The root node.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466627-->
END%%
%%ANKI
Basic
In the following binary tree type, what name is given to the second argument of `node`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: The left subtree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466634-->
END%%
%%ANKI
Basic
In the following binary tree type, what name is given to the third argument of `node`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: The right subtree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466639-->
END%%
%%ANKI
Basic
Given the following binary tree implementation, how do you construct an empty tree?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: `nil`
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466643-->
END%%
%%ANKI
Basic
Given the following binary tree implementation, how do you construct a tree with root `a`, left child `b`, and right child `c`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: `node 'a' (node 'b' nil nil) (node 'c' nil nil)`
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466648-->
END%%
%%ANKI
Basic
Why isn't a binary tree considered an ordered tree?
Back: A left child is distinct from a right child, even if the child is the same in both cases.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1712409466653-->
END%%
%%ANKI
Basic
How many internal nodes are in a complete binary tree of $n$ nodes?
Back: $\lceil (n - 1) / 2 \rceil = \lfloor n / 2 \rfloor$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714349367662-->
END%%
%%ANKI
Basic
A node of a binary tree typically has what three pointers?
Back: The parent, left child, and right child.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1715969047059-->
END%%
%%ANKI
Basic
In what direction do binary trees grow?
Back: New nodes are added to the bottom of the tree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1723208264398-->
END%%
## Bibliography
* “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
* Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -555,7 +555,7 @@ END%%
%%ANKI
Basic
When is the load factor of an open addressing hash table $> 1$?
Back: N/A
Back: N/A.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1718759188186-->
END%%

View File

@ -585,7 +585,7 @@ END%%
%%ANKI
Basic
Consider universal family $\mathscr{H}$ and universe $U$. What does the following evaluate to? $$|\{h \in \mathscr{H} \mid h(x) = h(y)\}| \text{ for distinct } x, y \in U$$
Consider universal family $\mathscr{H}$ and universe $U$. What number does the following evaluate to? $$|\{h \in \mathscr{H} \mid h(x) = h(y)\}| \text{ for distinct } x, y \in U$$
Back: A value between $0$ and $|\mathscr{H}|$ inclusive.
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: hashing::random hashing::universal

View File

@ -971,7 +971,7 @@ END%%
%%ANKI
Basic
When is the first guarded command of the following executed? $$\begin{align*} \textbf{if } & x \geq 0 \rightarrow z \coloneqq x \\ \textbf{ | } & x \leq 0 \rightarrow z \coloneqq -x \\ \textbf{fi } & \end{align*}$$
Back: When $x \geq 0$.
Back: When $x > 0$ or (possibly) when $x = 0$.
Reference: Gries, David. *The Science of Programming*. Texts and Monographs in Computer Science. New York: Springer-Verlag, 1981.
<!--ID: 1722257348955-->
END%%

View File

@ -269,7 +269,7 @@ END%%
%%ANKI
Cloze
$P(x)$ is equivalently written as $x \in$ {$\{v \mid P(v)\}$}.
$P(x) = T$ is equivalently written as $x \in$ {$\{v \mid P(v)\}$}.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1720369624733-->
END%%

View File

@ -1008,7 +1008,7 @@ Reference: “Asymmetric Relation,” in _Wikipedia_, February 21, 2024, [https:
END%%
%%ANKI
Give an example of a relation that is both symmetric and asymmetric?
Give an example of a relation that is both symmetric and asymmetric.
Back: $\varnothing$
Reference: “Asymmetric Relation,” in _Wikipedia_, February 21, 2024, [https://en.wikipedia.org/w/index.php?title=Asymmetric_relation](https://en.wikipedia.org/w/index.php?title=Asymmetric_relation&oldid=1209290822).
END%%
@ -1030,9 +1030,11 @@ Reference: “Asymmetric Relation,” in _Wikipedia_, February 21, 2024, [https:
END%%
%%ANKI
Give an example of a nonempty relation that is both symmetric and asymmetric?
Basic
Give an example of a nonempty relation that is both symmetric and asymmetric.
Back: N/A.
Reference: “Asymmetric Relation,” in _Wikipedia_, February 21, 2024, [https://en.wikipedia.org/w/index.php?title=Asymmetric_relation](https://en.wikipedia.org/w/index.php?title=Asymmetric_relation&oldid=1209290822).
<!--ID: 1723245187584-->
END%%
%%ANKI
@ -1098,6 +1100,13 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre
<!--ID: 1722735199608-->
END%%
%%ANKI
Cloze
A relation $R$ is asymmetric iff $R$ is {antisymmetric} and {irreflexive}.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187594-->
END%%
## Transitivity
A relation $R$ is **transitive** iff whenever $xRy$ and $yRz$, then $xRz$. In relational algebra, we define $R$ to be transitive iff $R \circ R \subseteq R$.
@ -1272,6 +1281,137 @@ Reference: “Connected Relation,” in _Wikipedia_, July 14, 2024, [https://en.
<!--ID: 1722735199715-->
END%%
## Trichotomy
A binary relation $R$ on $A$ is **trichotomous** if for all $x, y \in A$, exactly one of the following holds: $$xRy, \quad x = y, \quad yRx$$
%%ANKI
Basic
How is trichotomy of relation $R$ on set $A$ defined in FOL?
Back: $\forall x, y \in A, (xRy \land x \neq y \land \neg yRx) \lor (\neg xRy \land x = y \land \neg yRx) \lor (\neg xRy \land x \neq y \land yRx)$
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187598-->
END%%
%%ANKI
Basic
Is $R = \{\langle 2, 3 \rangle, \langle 2, 5 \rangle, \langle 3, 5 \rangle\}$ trichotomous on $\{2, 3, 5\}$?
Back: Yes.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187602-->
END%%
%%ANKI
Basic
Is $R = \{\langle 2, 3 \rangle, \langle 3, 5 \rangle\}$ trichotomous on $\{2, 3, 5\}$?
Back: No.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187605-->
END%%
%%ANKI
Basic
*Why* isn't $R = \{\langle 2, 3 \rangle, \langle 3, 5 \rangle\}$ trichotomous on $\{2, 3, 5\}$?
Back: Because no ordered pair relates $2$ and $5$ together.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187609-->
END%%
%%ANKI
Basic
Is $R = \{\langle 2, 2 \rangle\}$ trichotomous on $\{2\}$?
Back: No.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187613-->
END%%
%%ANKI
Basic
*Why* isn't $R = \{\langle a, a \rangle\}$ trichotomous on $\{a\}$?
Back: Because $aRa$ and $a = a$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187617-->
END%%
%%ANKI
Basic
Can a relation be both reflexive and trichotomous?
Back: Yes.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187621-->
END%%
%%ANKI
Basic
Can a nonempty relation be both reflexive and trichotomous?
Back: No.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187628-->
END%%
%%ANKI
Basic
Can a nonempty relation be both irreflexive and trichotomous?
Back: Yes.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187633-->
END%%
%%ANKI
Basic
Which of trichotomy or irreflexivity is more general?
Back: Irreflexivity.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187638-->
END%%
%%ANKI
Basic
*Why* must trichotomous relations on (say) set $A$ be irreflexive?
Back: For any $x \in A$, it follows $x = x$. Then $\neg xRx$.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187643-->
END%%
%%ANKI
Basic
Can a nonempty relation be both symmetric and trichotomous?
Back: No.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187648-->
END%%
%%ANKI
Basic
Can a nonempty relation be both antisymmetric and trichotomous?
Back: Yes.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187654-->
END%%
%%ANKI
Basic
Which of antisymmetry or trichotomy is more general?
Back: Antisymmetry.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187659-->
END%%
%%ANKI
Basic
*Why* must trichotomous relations on (say) set $A$ be antisymmetric?
Back: For any $x, y \in A$, if $x \neq y$ then $xRy$ or $yRx$ but not both.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187664-->
END%%
%%ANKI
Cloze
A relation $R$ is trichotomous iff $R$ is {asymmetric} and {connected}.
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
<!--ID: 1723245187669-->
END%%
## Equivalence Relations
Given relation $R$ and set $A$, $R$ is an **equivalence relation on $A$** iff $R$ is a binary relation on $A$ that is reflexive on $A$, symmetric, and transitive.

View File

@ -55,7 +55,7 @@ END%%
%%ANKI
Basic
What additional properties must a free tree exhibit to be a forest?
Back: N/A
Back: N/A.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1711136844915-->
END%%
@ -852,7 +852,7 @@ END%%
### Positional Trees
A **positional tree** is a rooted tree in which each child is labeled with a specific positive integer. A **$k$-ary tree** is a positional tree with at most $k$ children/labels. A binary tree is a $2$-ary tree.
A **positional tree** is a rooted tree in which each child is labeled with a specific positive integer. A **$k$-ary tree** is a positional tree with at most $k$ children/labels. A [[binary-tree|binary tree]] is a $2$-ary tree.
A $k$-ary tree is **full** if every node has degree $0$ or $k$. A $k$-ary tree is **perfect** if all leaves have the same depth and all internal nodes have degree $k$. A $k$-ary tree is **complete** if the last level is not filled but all leaves have the same depth and are leftmost arranged.
@ -1197,400 +1197,6 @@ Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition
<!--ID: 1714349367655-->
END%%
#### Binary Trees
A **binary tree** $T$ is a structure defined on a finite set of nodes that either
* contains no nodes, or
* is composed of three disjoint sets of nodes: a **root** node, a **left subtree**, and a **right subtree**.
%%ANKI
Basic
Is a binary tree a $k$-ary tree?
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714089436138-->
END%%
%%ANKI
Basic
Is a binary tree a positional tree?
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
END%%
%%ANKI
Basic
Is a binary tree an ordered tree?
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714089436144-->
END%%
%%ANKI
Basic
What does it mean for a binary tree to be full?
Back: Each node has $0$ or $2$ children.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1713118128213-->
END%%
%%ANKI
Basic
What does it mean for a binary tree to be perfect?
Back: Each leaf has the same depth and all internal nodes have degree $2$.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594570-->
END%%
%%ANKI
Basic
Is a perfect binary tree considered full?
Back: Yes.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438720-->
END%%
%%ANKI
Basic
Is a full binary tree considered perfect?
Back: Not necessarily.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438726-->
END%%
%%ANKI
Basic
Is a full binary tree considered complete?
Back: Not necessarily.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438729-->
END%%
%%ANKI
Basic
Is a complete binary tree considered full?
Back: Not necessarily.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438733-->
END%%
%%ANKI
Basic
What alternative term is sometimes used in favor of a "perfect binary tree"?
Back: A "complete binary tree".
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438737-->
END%%
%%ANKI
Basic
What alternative term is sometimes used in favor over a "complete binary tree"?
Back: Some authors may say "nearly complete" if the last level isn't completely filled.
Reference: “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
<!--ID: 1714088438744-->
END%%
%%ANKI
Basic
What degrees are permitted in a full binary tree?
Back: $0$ or $2$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594576-->
END%%
%%ANKI
Basic
What degrees are permitted in a perfect binary tree?
Back: $0$ or $2$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594579-->
END%%
%%ANKI
Basic
What category of rooted tree does a binary tree fall under?
Back: A positional tree or $k$-ary tree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714081594582-->
END%%
%%ANKI
Basic
Is a binary tree a positional tree?
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1713118128227-->
END%%
%%ANKI
Basic
How many nodes are in a perfect binary tree of height $h$?
Back: $2^{h+1} - 1$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1713118128255-->
END%%
%%ANKI
Basic
How many internal nodes are in a perfect binary tree of height $h$?
Back: $2^h - 1$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353472-->
END%%
%%ANKI
Basic
How many external nodes are in a perfect binary tree of height $h$?
Back: $2^h$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353469-->
END%%
%%ANKI
Basic
How many nodes are on level $d$ of a perfect binary tree?
Back: $2^d$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353465-->
END%%
%%ANKI
Basic
How does the number of internal nodes compare to the number of external nodes in a perfect binary tree?
Back: There is one more external node than internal node.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: algebra::sequence
<!--ID: 1714080353476-->
END%%
%%ANKI
Basic
Is the following a perfect binary tree?
![[perfect-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419777-->
END%%
%%ANKI
Basic
Is the following a complete binary tree?
![[perfect-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419781-->
END%%
%%ANKI
Basic
Is the following a full binary tree?
![[perfect-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419784-->
END%%
%%ANKI
Basic
Is the following a perfect binary tree?
![[complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419787-->
END%%
%%ANKI
Basic
Is the following a complete binary tree?
![[complete-tree.png]]
Back: Yes.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419789-->
END%%
%%ANKI
Basic
Is the following a full binary tree?
![[complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419793-->
END%%
%%ANKI
Basic
Is the following a perfect binary tree?
![[non-complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419802-->
END%%
%%ANKI
Basic
Is the following a complete binary tree?
![[non-complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419809-->
END%%
%%ANKI
Basic
Is the following a full binary tree?
![[non-complete-tree.png]]
Back: No.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714180419813-->
END%%
%%ANKI
Basic
What is the minimum number of nodes in a complete binary tree of height $h$?
Back: $2^h$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714082676010-->
END%%
%%ANKI
Basic
What is the base case used in the recursive definition of a binary tree?
Back: The empty set.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1712409466593-->
END%%
%%ANKI
Basic
What recurrence is used in the recursive definition of a binary tree?
Back: A binary tree is composed of a root node, a left subtree, and a right subtree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1712409466606-->
END%%
%%ANKI
Basic
How should the nil constructor of an inductive binary tree, say `Tree`, be defined?
Back:
```lean
| nil : Tree α
```
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466615-->
END%%
%%ANKI
Basic
How should the non-nil constructor of an inductive binary tree, say `Tree`, be defined?
Back:
```lean
| node : α → Tree α → Tree α → Tree α
```
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466621-->
END%%
%%ANKI
Basic
In the following binary tree type, what name is given to the first argument of `node`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: The root node.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466627-->
END%%
%%ANKI
Basic
In the following binary tree type, what name is given to the second argument of `node`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: The left subtree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466634-->
END%%
%%ANKI
Basic
In the following binary tree type, what name is given to the third argument of `node`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: The right subtree.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466639-->
END%%
%%ANKI
Basic
Given the following binary tree implementation, how do you construct an empty tree?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: `nil`
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466643-->
END%%
%%ANKI
Basic
Given the following binary tree implementation, how do you construct a tree with root `a`, left child `b`, and right child `c`?
```lean
inductive Tree α where
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
```
Back: `node 'a' (node 'b' nil nil) (node 'c' nil nil)`
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: lean
<!--ID: 1712409466648-->
END%%
%%ANKI
Basic
Why isn't a binary tree considered an ordered tree?
Back: A left child is distinct from a right child, even if the child is the same in both cases.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1712409466653-->
END%%
%%ANKI
Basic
How many internal nodes are in a complete binary tree of $n$ nodes?
Back: $\lceil (n - 1) / 2 \rceil = \lfloor n / 2 \rfloor$
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1714349367662-->
END%%
%%ANKI
Basic
A node of a binary tree typically has what three pointers?
Back: The parent, left child, and right child.
Reference: Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1715969047059-->
END%%
## Bibliography
* “Binary Tree,” in _Wikipedia_, March 13, 2024, [https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees](https://en.wikipedia.org/w/index.php?title=Binary_tree&oldid=1213529508#Types_of_binary_trees).
* Thomas H. Cormen et al., _Introduction to Algorithms_, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).