Notes on binary search trees.
|
@ -146,7 +146,15 @@
|
|||
"infinite-cartesian-product.png",
|
||||
"function-kernel.png",
|
||||
"triple-table-repr.png",
|
||||
"binary-search-tree.png"
|
||||
"binary-search-tree.png",
|
||||
"bst-right-child.png",
|
||||
"bst-right-child-after.png",
|
||||
"bst-left-child.png",
|
||||
"bst-left-child-after.png",
|
||||
"bst-right-succ.png",
|
||||
"bst-right-succ-after.png",
|
||||
"bst-deep-succ.png",
|
||||
"bst-deep-succ-after.png"
|
||||
],
|
||||
"File Hashes": {
|
||||
"algorithms/index.md": "3ac071354e55242919cc574eb43de6f8",
|
||||
|
@ -253,7 +261,7 @@
|
|||
"combinatorics/inclusion-exclusion.md": "c27b49ee03cc5ee854d0e8bd12a1d505",
|
||||
"_journal/2024-02-21.md": "b9d944ecebe625da5dd72aeea6a916a2",
|
||||
"_journal/2024-02/2024-02-20.md": "af2ef10727726200c4defe2eafc7d841",
|
||||
"algebra/radices.md": "662a3e2f611dd9655f1ef6c7ed0a9943",
|
||||
"algebra/radices.md": "474178afb07f3d5037c1547cc1a132f2",
|
||||
"_journal/2024-02-22.md": "e01f1d4bd2f7ac2a667cdfd500885a2a",
|
||||
"_journal/2024-02/2024-02-21.md": "f423137ae550eb958378750d1f5e98c7",
|
||||
"_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd",
|
||||
|
@ -464,7 +472,7 @@
|
|||
"_journal/2024-05/2024-05-16.md": "9fdfadc3f9ea6a4418fd0e7066d6b10c",
|
||||
"_journal/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c",
|
||||
"hashing/direct-addressing.md": "f75cc22e74ae974fe4f568a2ee9f951f",
|
||||
"hashing/index.md": "90be101304334dc8771ca141fae0092c",
|
||||
"hashing/index.md": "760d1fad7a890814afecfd29c6675f67",
|
||||
"set/classes.md": "6776b4dc415021e0ef60b323b5c2d436",
|
||||
"_journal/2024-05-19.md": "fddd90fae08fab9bd83b0ef5d362c93a",
|
||||
"_journal/2024-05/2024-05-18.md": "c0b58b28f84b31cea91404f43b0ee40c",
|
||||
|
@ -487,7 +495,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": "f7a775cd9f6bf0b3a127fc9c3b9a3c15",
|
||||
"algebra/set.md": "b4d5ce4b914abe5063bf6043cf7a0aee",
|
||||
"algebra/boolean.md": "fc47edb7d0080b73ce1ce0d3e0e16d7d",
|
||||
"git/merge-conflicts.md": "761ad6137ec51d3877f7d5b3615ca5cb",
|
||||
"_journal/2024-05-28.md": "0f6aeb5ec126560acdc2d8c5c6570337",
|
||||
|
@ -512,7 +520,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": "7ed656318eb661b9cc65d4007311f392",
|
||||
"set/relations.md": "84a66a74805014d3b88ea5e8a3e763bc",
|
||||
"_journal/2024-06-07.md": "795be41cc3c9c0f27361696d237604a2",
|
||||
"_journal/2024-06/2024-06-06.md": "db3407dcc86fa759b061246ec9fbd381",
|
||||
"_journal/2024-06-08.md": "b20d39dab30b4e12559a831ab8d2f9b8",
|
||||
|
@ -651,8 +659,8 @@
|
|||
"_journal/2024-07/2024-07-26.md": "c167f734a5037e1a5537b1e95ca6790f",
|
||||
"_journal/2024-07-28.md": "8a2393673132ac57a86b3b528bfc4a16",
|
||||
"_journal/2024-07/2024-07-27.md": "7c48690746d8320494e29e92390eb6ee",
|
||||
"ontology/rdf/uri.md": "5d9f355f314a54c5fb5099d751070656",
|
||||
"ontology/rdf/index.md": "4875a042ed4e2ff0448e03bb17f1a736",
|
||||
"ontology/rdf/uri.md": "07999207f65ffb35f55af42c9922e7c5",
|
||||
"ontology/rdf/index.md": "36424c9bad6088cdee67f74e3b8a019f",
|
||||
"ontology/philosophy/permissivism.md": "643e815a79bc5c050cde9f996aa44ef5",
|
||||
"ontology/philosophy/nominalism.md": "46245c644238157e15c7cb6def27d90a",
|
||||
"ontology/philosophy/index.md": "6c7c60f91f78fdc1cdd8c012b1ac4ebd",
|
||||
|
@ -661,11 +669,14 @@
|
|||
"_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": "c2076aa12f7afacc96fa504dd89dae5e",
|
||||
"data-structures/binary-search-tree.md": "34127d93a49d7c947008a37fecfe74ac",
|
||||
"_journal/2024-08-01.md": "2e3da352cfbaf29b6b49e3c3a4f090df",
|
||||
"_journal/2024-07/2024-07-31.md": "d397c5a4d42660eeaa290aa8316d55c1",
|
||||
"_journal/2024-07/2024-07-30.md": "025194b9b770b56a81b5a52d96a305f2",
|
||||
"_journal/2024-08-02.md": "24648f61c675c1c52e4cb19cbac6f0dc"
|
||||
"_journal/2024-08-02.md": "24648f61c675c1c52e4cb19cbac6f0dc",
|
||||
"_journal/2024-08-03.md": "27f1316f792f7673cd7ea1b1e44444be",
|
||||
"_journal/2024-08/2024-08-02.md": "076c35545f292eddd3c7253a41fbd40c",
|
||||
"_journal/2024-08/2024-08-01.md": "2e3da352cfbaf29b6b49e3c3a4f090df"
|
||||
},
|
||||
"fields_dict": {
|
||||
"Basic": [
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
title: "2024-08-03"
|
||||
---
|
||||
|
||||
- [ ] Anki Flashcards
|
||||
- [x] Anki Flashcards
|
||||
- [x] KoL
|
||||
- [ ] OGS
|
||||
- [ ] Sheet Music (10 min.)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
- [ ] Korean (Read 1 Story)
|
||||
|
||||
* Additional notes on binary search trees.
|
|
@ -277,7 +277,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which hexadecimal digits are encoded in binary with a leading `1` bit?
|
||||
Back: `8` through `F`
|
||||
Back: `8` through `F`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: binary::hex
|
||||
<!--ID: 1708631918825-->
|
||||
|
@ -286,7 +286,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Which hexadecimal digits are encoded in binary with a leading `0` bit?
|
||||
Back: `0` through `7`
|
||||
Back: `0` through `7`.
|
||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||
Tags: binary::hex
|
||||
<!--ID: 1708631918829-->
|
||||
|
|
|
@ -13,6 +13,8 @@ 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$.
|
||||
|
||||
## Traversals
|
||||
|
||||
Consider an arbitrary node $x$ of some BST. Then:
|
||||
|
||||
* An **inorder** traversal visits $x$'s left child, then $x$, then $x$'s right child.
|
||||
|
@ -190,6 +192,398 @@ Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (
|
|||
<!--ID: 1722342235784-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In terms of the height $h$ of a BST, what is the runtime of search?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303021-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In terms of the height $h$ of a BST, what is the runtime for finding the minimum?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303023-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In terms of the height $h$ of a BST, what is the runtime for finding the maximum?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303025-->
|
||||
END%%
|
||||
|
||||
### Successors
|
||||
|
||||
The **successor** of a node in a binary search tree is the node whose value would appear immediately after in an in-order traversal.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How do we define the successor of a BST node in terms of in-order traversals?
|
||||
Back: As the node encountered immediately after in an in-order traversal.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623599-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node is the successor of $7$ in the following BST?
|
||||
![[binary-search-tree.png]]
|
||||
Back: $8$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623601-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node is the successor of $2$ in the following BST?
|
||||
![[binary-search-tree.png]]
|
||||
Back: $5$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623603-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node is the successor of $5$ in the following BST?
|
||||
![[binary-search-tree.png]]
|
||||
Back: Either $5$ or $6$.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623604-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node(s) in a BST have no successor?
|
||||
Back: The maximum.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623606-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two cases are considered when finding the successor of a BST node?
|
||||
Back: If the node has a right subtree or not.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623607-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node has a right subtree. What is its successor?
|
||||
Back: The minimum of the right subtree.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623608-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node does not have a right subtree. What is its successor?
|
||||
Back: The first proper ancestor reached from the LHS.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623610-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
If a BST node has a right subtree, it's successor cannot have a {left} subtree.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303026-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node has a right subtree. *Why* can't its successor have a left subtree?
|
||||
Back: Because then a node in that left subtree would be the actual successor.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303028-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node has a right subtree. *Why* can't its successor have a right subtree?
|
||||
Back: N/A. It can.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303029-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In terms of the height $h$ of a BST, what is the runtime for finding a node's successor?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303030-->
|
||||
END%%
|
||||
|
||||
### Predecessors
|
||||
|
||||
The **predecessor** of a node in a binary search tree is the node whose value would appear immediately before in an in-order traversal.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How do we define the predecessor of a BST node in terms of in-order traversals?
|
||||
Back: As the node encountered immediately before in an in-order traversal.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623611-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node is the predecessor of $7$ in the following BST?
|
||||
![[binary-search-tree.png]]
|
||||
Back: $6$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623613-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node is the predecessor of $2$ in the following BST?
|
||||
![[binary-search-tree.png]]
|
||||
Back: N/A.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623614-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node is the predecessor of $5$ in the following BST?
|
||||
![[binary-search-tree.png]]
|
||||
Back: Either $2$ or $5$.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623615-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Which node(s) in a BST have no predecessor?
|
||||
Back: The minimum.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623616-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What two cases are considered when finding the predecessor of a BST node?
|
||||
Back: If the node has a left subtree or not.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623617-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node has a left subtree. What is its predecessor?
|
||||
Back: The maximum of the left subtree.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623618-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node does not have a left subtree. What is its predecessor?
|
||||
Back: The first proper ancestor reached from the RHS.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722709623619-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Cloze
|
||||
If a BST node has a left subtree, it's predecessor cannot have a {right} subtree.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303031-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node has a left subtree. *Why* can't its successor have a left subtree?
|
||||
Back: N/A. It can.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303033-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Suppose a BST node has a left subtree. *Why* can't its predecessor have a right subtree?
|
||||
Back: Because then a node in that right subtree would be the actual predecessor.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303034-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In terms of the height $h$ of a BST, what is the runtime for finding a node's predecessor?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303035-->
|
||||
END%%
|
||||
|
||||
## Deletions
|
||||
|
||||
Consider deleting node $z$ from a BST. There are three conceptual cases to consider corresponding to the number of children $z$ has:
|
||||
|
||||
* If $z$ has no children we can just replace $z$ with `NIL`.
|
||||
* If $z$ has one child, we can replace $z$ with its child.
|
||||
* If $z$ has two children, we swap $z$ with either its predecessor or successor, updating pointers as necessary to maintain the binary-search-tree property.
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Insert node $7.5$ into the following BST. Where is the new node located?
|
||||
![[binary-search-tree.png]]
|
||||
Back: As $8$'s left child.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303036-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Insert node $6.5$ into the following BST. Where is the new node located?
|
||||
![[binary-search-tree.png]]
|
||||
Back: As $7$'s left child.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303037-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Insert node $5.5$ into the following BST. Where is the new node located?
|
||||
![[binary-search-tree.png]]
|
||||
Back: As the lower $5$'s right child.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--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?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303040-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
How many cases are there to consider when deleting a node from a BST?
|
||||
Back: Three.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303041-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What corresponds to the cases to consider when deleting a node from a BST?
|
||||
Back: The number of children the node in question has.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303042-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete BST node $z$ with no children. Which node is $z$ replaced with?
|
||||
Back: `NIL`
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303043-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete BST node $z$ with one child. Which node is $z$ replaced with?
|
||||
Back: Its one child.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303044-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete BST node $z$ with two children. Which node is $z$ replaced with?
|
||||
Back: Either its successor or predecessor.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303045-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete BST node $z$ with two children. If replacing with its successor, what two subcases need to be considered?
|
||||
Back: If $z$'s successor is its right child or not.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303046-->
|
||||
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.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303047-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
In terms of the height $h$ of a BST, what is the runtime for deleting a node?
|
||||
Back: $O(h)$
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303048-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete $z$ from the following BST. What does the resulting tree look like?
|
||||
![[bst-right-child.png]]
|
||||
Back:
|
||||
![[bst-right-child-after.png]]
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303049-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete $z$ from the following BST. What does the resulting tree look like?
|
||||
![[bst-left-child.png]]
|
||||
Back:
|
||||
![[bst-left-child-after.png]]
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303050-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete $z$ from the following BST. What does the resulting tree look like?
|
||||
![[bst-right-succ.png]]
|
||||
Back:
|
||||
![[bst-right-succ-after.png]]
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303051-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
Delete $z$ from the following BST. What does the resulting tree look like?
|
||||
![[bst-deep-succ.png]]
|
||||
Back:
|
||||
![[bst-deep-succ-after.png]]
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713303052-->
|
||||
END%%
|
||||
|
||||
%%ANKI
|
||||
Basic
|
||||
What arbitrary choice was implied in the deletion algorithm of the following BST?
|
||||
![[bst-deep-succ.png]]
|
||||
Back: To replace deleted nodes with their successor instead of predecessor.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
<!--ID: 1722713414719-->
|
||||
END%%
|
||||
|
||||
## Bibliography
|
||||
|
||||
* Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 23 KiB |
|
@ -328,7 +328,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Let $h$ be a division method hash function. What does $h(10)$ evaluate to?
|
||||
Back: To $10 \bmod{m}$, where $m$ is the number of slots in the hash table.
|
||||
Back: $10 \bmod{m}$, where $m$ is the number of slots in the hash table.
|
||||
Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
|
||||
Tags: hashing::static
|
||||
<!--ID: 1720889385419-->
|
||||
|
|
|
@ -123,7 +123,7 @@ END%%
|
|||
|
||||
%%ANKI
|
||||
Basic
|
||||
RDF identifiers are represented using what?
|
||||
RDF identifiers use what encoding?
|
||||
Back: URIs.
|
||||
Reference: Allemang, Dean, James A. Hendler, and Fabien L. Gandon. _Semantic Web for the Working Ontologist_. 3e ed. ACM Books 33. New York: Association for computing machinery, 2020.
|
||||
<!--ID: 1722191359882-->
|
||||
|
|
|
@ -67,7 +67,7 @@ where the `<authority>` is further composed as
|
|||
Cloze
|
||||
A URI has the following generic syntax:
|
||||
|
||||
{`<schema>`}`:`{`[//<authority>]`}`]`{`<path>`}{`[?<query>]`}{`[#<fragment>]`}.
|
||||
{`<scheme>`}`:`{`[//<authority>]`}{`<path>`}{`[?<query>]`}{`[#<fragment>]`}.
|
||||
Reference: “Uniform Resource Identifier.” In _Wikipedia_, July 22, 2024. [https://en.wikipedia.org/w/index.php?title=Uniform_Resource_Identifier](https://en.wikipedia.org/w/index.php?title=Uniform_Resource_Identifier&oldid=1235957234).
|
||||
<!--ID: 1722211276499-->
|
||||
END%%
|
||||
|
@ -488,7 +488,7 @@ A **compact URI** (CURIE) is a denser representation of URIs. In its simplest fo
|
|||
%%ANKI
|
||||
Basic
|
||||
URIs in RDF are usually represented in what condensed format?
|
||||
Back: CURIE.
|
||||
Back: CURIEs.
|
||||
Reference: Allemang, Dean, James A. Hendler, and Fabien L. Gandon. _Semantic Web for the Working Ontologist_. 3e ed. ACM Books 33. New York: Association for computing machinery, 2020.
|
||||
<!--ID: 1722191359875-->
|
||||
END%%
|
||||
|
@ -496,7 +496,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
What is CURIE an acronym for?
|
||||
Back: **C**ompact **URI**&.
|
||||
Back: **C**ompact **URI**s.
|
||||
Reference: Allemang, Dean, James A. Hendler, and Fabien L. Gandon. _Semantic Web for the Working Ontologist_. 3e ed. ACM Books 33. New York: Association for computing machinery, 2020.
|
||||
<!--ID: 1722191359876-->
|
||||
END%%
|
||||
|
|
|
@ -647,7 +647,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Given $R = \{\langle a, a \rangle, \langle b, c \rangle\}$, is $R$ reflexive on $a$?
|
||||
Back: N/A. We must ask if $R$ is reflexive on a set.
|
||||
Back: N/A. We should ask if $R$ is reflexive on set $\{a\}$.
|
||||
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
|
||||
<!--ID: 1720967429808-->
|
||||
END%%
|
||||
|
@ -729,7 +729,7 @@ END%%
|
|||
%%ANKI
|
||||
Basic
|
||||
Given $R = \{\langle a, a \rangle, \langle b, c \rangle\}$, is $R$ irreflexive on $a$?
|
||||
Back: N/A. We must ask if $R$ is irreflexive on a set.
|
||||
Back: N/A. We should ask if $R$ is irreflexive on set $\{a\}$.
|
||||
Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977).
|
||||
<!--ID: 1721870888391-->
|
||||
END%%
|
||||
|
|