Notes on graphs.

c-declarations
Joshua Potter 2024-03-18 18:28:34 -06:00
parent 809414ede4
commit 33466a2583
17 changed files with 1340 additions and 277 deletions

View File

@ -100,12 +100,14 @@
"normalized-form.png", "normalized-form.png",
"denormalized-form.png", "denormalized-form.png",
"infinity.png", "infinity.png",
"nan.png" "nan.png",
"directed-graph-example.png",
"undirected-graph-example.png"
], ],
"File Hashes": { "File Hashes": {
"algorithms/index.md": "cd7c7ba91fb2f961c9f2437777e8e2ac", "algorithms/index.md": "f63290ca8d7aad1840797ec699188e9e",
"algorithms/sorting/index.md": "2d5a18a3079d96fa9e3d4289181a8b6c", "algorithms/sorting/index.md": "2d5a18a3079d96fa9e3d4289181a8b6c",
"algorithms/sorting/insertion-sort.md": "10525c1e013a341ef51656bedf41a61b", "algorithms/sorting/insertion-sort.md": "bdac9a5836611d6136b65367bed521e7",
"bash/index.md": "3e4738d8d3531bb7a5afc53a2d73036c", "bash/index.md": "3e4738d8d3531bb7a5afc53a2d73036c",
"bash/prompts.md": "61cb877e68da040a15b85af76b1f68ba", "bash/prompts.md": "61cb877e68da040a15b85af76b1f68ba",
"bash/quoting.md": "b1d8869a91001f8b22f0cdc54d806f61", "bash/quoting.md": "b1d8869a91001f8b22f0cdc54d806f61",
@ -142,11 +144,11 @@
"logic/equiv-trans.md": "315997b803b0748f5fc76d912ad97cda", "logic/equiv-trans.md": "315997b803b0748f5fc76d912ad97cda",
"_journal/2024-02-07.md": "8d81cd56a3b33883a7706d32e77b5889", "_journal/2024-02-07.md": "8d81cd56a3b33883a7706d32e77b5889",
"algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2", "algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2",
"algorithms/loop-invariant.md": "29f9f9090a3109890d333a78acc18b50", "algorithms/loop-invariant.md": "e39f4aa253f0baf908067bea81f6bced",
"algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65", "algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65",
"algorithms/order-growth.md": "0148c1e9f4aa89cc8a7fcf44666805d0", "algorithms/order-growth.md": "53d41d9abbd1d8118793bad3996d249a",
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac", "_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
"algorithms/sorting/selection-sort.md": "3e4f059f01210d050ec6e7279e93e43c", "algorithms/sorting/selection-sort.md": "997feca70660168b3a115df6b5d5672e",
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
"binary/hexadecimal.md": "c3d485f1fd869fe600334ecbef7d5d70", "binary/hexadecimal.md": "c3d485f1fd869fe600334ecbef7d5d70",
"binary/index.md": "9089c6f0e86a0727cd03984f51350de0", "binary/index.md": "9089c6f0e86a0727cd03984f51350de0",
@ -154,7 +156,7 @@
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555", "c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
"logic/quantification.md": "346ebe70e1fad9d95d81056ec9029793", "logic/quantification.md": "346ebe70e1fad9d95d81056ec9029793",
"c/declarations.md": "2de27f565d1020819008ae80593af435", "c/declarations.md": "2de27f565d1020819008ae80593af435",
"algorithms/sorting/bubble-sort.md": "96c4b9426bcb4284de60b9144ba09b9e", "algorithms/sorting/bubble-sort.md": "a350fb36d1e677659142bf38f7abc89b",
"_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f", "_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
"_journal/2024-01/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970", "_journal/2024-01/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
"_journal/2024-02/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109", "_journal/2024-02/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109",
@ -189,7 +191,7 @@
"_journal/2024-02/2024-02-15.md": "16cb7563d404cb543719b7bb5037aeed", "_journal/2024-02/2024-02-15.md": "16cb7563d404cb543719b7bb5037aeed",
"algebra/floor-ceiling.md": "556406772daaa415d546b1a8bf41b5dd", "algebra/floor-ceiling.md": "556406772daaa415d546b1a8bf41b5dd",
"algebra/index.md": "90b842eb694938d87c7c68779a5cacd1", "algebra/index.md": "90b842eb694938d87c7c68779a5cacd1",
"algorithms/binary-search.md": "27189885f0bc1e8b8b9049da3ed92f98", "algorithms/binary-search.md": "f88a5b9f38f1856f2bd4f578d6079548",
"_journal/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048", "_journal/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
"_journal/2024-02/2024-02-16.md": "e701902e369ec53098fc2deed4ec14fd", "_journal/2024-02/2024-02-16.md": "e701902e369ec53098fc2deed4ec14fd",
"binary/integer-encoding.md": "7ace6ab6c5a4191ae0abdfe7e5abb6a2", "binary/integer-encoding.md": "7ace6ab6c5a4191ae0abdfe7e5abb6a2",
@ -214,9 +216,9 @@
"_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b", "_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b",
"c17/strings.md": "3335356dee2b0e28a356adc851ee1375", "c17/strings.md": "3335356dee2b0e28a356adc851ee1375",
"c17/index.md": "78576ee41d0185df82c59999142f4edb", "c17/index.md": "78576ee41d0185df82c59999142f4edb",
"c17/escape-sequences.md": "ebc63c6cdfbe60bbc2708c1b0c8da8bb", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500",
"c17/declarations.md": "cec6866dff8ad160467df62cfceb6872", "c17/declarations.md": "cec6866dff8ad160467df62cfceb6872",
"algorithms/sorting/merge-sort.md": "fdc6311b0f9e7d85899fc77a95872a2f", "algorithms/sorting/merge-sort.md": "e0e9108566d2de0ff9fd211a573fca8d",
"_journal/2024-02-24.md": "9bb319d5014caf962a9ce3141076cff4", "_journal/2024-02-24.md": "9bb319d5014caf962a9ce3141076cff4",
"_journal/2024-02/2024-02-23.md": "0aad297148e8cc4058b48b7e45787ca7", "_journal/2024-02/2024-02-23.md": "0aad297148e8cc4058b48b7e45787ca7",
"_journal/2024-02-25.md": "fb1a48208c11d12262facc647749ca6f", "_journal/2024-02-25.md": "fb1a48208c11d12262facc647749ca6f",
@ -276,7 +278,12 @@
"_journal/2024-03/2024-03-15.md": "e54b2513beac5f46313b4c37622adf39", "_journal/2024-03/2024-03-15.md": "e54b2513beac5f46313b4c37622adf39",
"_journal/2024-03-17.md": "72e99c7630085aee2c7f340a06b5ada7", "_journal/2024-03-17.md": "72e99c7630085aee2c7f340a06b5ada7",
"_journal/2024-03/2024-03-16.md": "ab7629c24ebe70838072cf6acec47cb0", "_journal/2024-03/2024-03-16.md": "ab7629c24ebe70838072cf6acec47cb0",
"encoding/floating-point.md": "6aa91498473ea5f8504dfa7f87bf77f4" "encoding/floating-point.md": "6aa91498473ea5f8504dfa7f87bf77f4",
"_journal/2024-03-18.md": "8479f07f63136a4e16c9cd07dbf2f27f",
"_journal/2024-03/2024-03-17.md": "23f9672f5c93a6de52099b1b86834e8b",
"set/directed-graph.md": "b4b8ad1be634a0a808af125fe8577a53",
"set/index.md": "b82a215fbee3c576186fc1af93c82fcb",
"set/graphs.md": "938b5313e97eb364c97d752fdb262a52"
}, },
"fields_dict": { "fields_dict": {
"Basic": [ "Basic": [

View File

@ -0,0 +1,15 @@
---
title: "2024-03-18"
---
- [x] Anki Flashcards
- [x] KoL
- [ ] Sheet Music (10 min.)
- [ ] Go (1 Life & Death Problem)
- [ ] Korean (Read 1 Story)
- [ ] Interview Prep (1 Practice Problem)
- [ ] Log Work Hours (Max 3 hours)
* Finished [buffer pool manager project](https://15445.courses.cs.cmu.edu/fall2022/project1/).
* Added notes on [[graphs|graph]]-related terminology. Updated "Introduction to Algorithms" to fourth edition.
* Watched [How My Student Became 1 Dan](https://www.youtube.com/watch?v=ZvHL_lwfYYI&t=595s).

View File

@ -18,7 +18,7 @@ Aux. Memory | $O(1)$
Basic Basic
What precondition must the input of `BINARY_SEARCH` satisfy? What precondition must the input of `BINARY_SEARCH` satisfy?
Back: It must already be sorted. Back: It must already be sorted.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708781334247--> <!--ID: 1708781334247-->
END%% END%%
@ -26,7 +26,7 @@ END%%
Basic Basic
What is the best case running time of `BINARY_SEARCH`? What is the best case running time of `BINARY_SEARCH`?
Back: $\Omega(1)$ Back: $\Omega(1)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708117310004--> <!--ID: 1708117310004-->
END%% END%%
@ -34,7 +34,7 @@ END%%
Basic Basic
What input does `BINARY_SEARCH` perform best on? What input does `BINARY_SEARCH` perform best on?
Back: One in which the value being searched for is already in the middle. Back: One in which the value being searched for is already in the middle.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708117310011--> <!--ID: 1708117310011-->
END%% END%%
@ -42,7 +42,7 @@ END%%
Basic Basic
What is the worst case running time of `BINARY_SEARCH`? What is the worst case running time of `BINARY_SEARCH`?
Back: $O(\lg{n})$ Back: $O(\lg{n})$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708117310015--> <!--ID: 1708117310015-->
END%% END%%
@ -50,7 +50,7 @@ END%%
Basic Basic
What input does `BINARY_SEARCH` perform worst on? What input does `BINARY_SEARCH` perform worst on?
Back: One in which the value does not exist. Back: One in which the value does not exist.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708117310018--> <!--ID: 1708117310018-->
END%% END%%
@ -58,7 +58,7 @@ END%%
Basic Basic
What is the typical output of `BINARY_SEARCH`? What is the typical output of `BINARY_SEARCH`?
Back: The index of the element in the array being searched for, if found. Back: The index of the element in the array being searched for, if found.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708117310021--> <!--ID: 1708117310021-->
END%% END%%
@ -108,7 +108,7 @@ int binary_search(const int needle, const int n, int A[static n]) {
Basic Basic
In `BINARY_SEARCH`, when could using floor for midpoint calculations yield different answers than ceiling? In `BINARY_SEARCH`, when could using floor for midpoint calculations yield different answers than ceiling?
Back: When there exist duplicate members. Back: When there exist duplicate members.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708174545522--> <!--ID: 1708174545522-->
END%% END%%
@ -116,10 +116,10 @@ END%%
Basic Basic
In `BINARY_SEARCH`, what ensures left pointer `L` and right pointers `R` eventually satisfy `L > R`? In `BINARY_SEARCH`, what ensures left pointer `L` and right pointers `R` eventually satisfy `L > R`?
Back: The found midpoint is always excluded from the next `BINARY_SEARCH` invocation. Back: The found midpoint is always excluded from the next `BINARY_SEARCH` invocation.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708174545527--> <!--ID: 1708174545527-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -14,7 +14,7 @@ An **incremental** approach to algorithm design involves acting on a single elem
Basic Basic
What does an incremental approach to algorithm design refer to? What does an incremental approach to algorithm design refer to?
Back: An algorithm that acts on a single element at a time. Back: An algorithm that acts on a single element at a time.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467144--> <!--ID: 1708742467144-->
END%% END%%
@ -22,7 +22,7 @@ END%%
Basic Basic
What does a divide-and-conquer approach to algorithm design refer to? What does a divide-and-conquer approach to algorithm design refer to?
Back: An algorithm that breaks a problem into similar but simpler subproblems. Back: An algorithm that breaks a problem into similar but simpler subproblems.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467147--> <!--ID: 1708742467147-->
END%% END%%
@ -30,7 +30,7 @@ END%%
Basic Basic
What does it mean for a divide-and-conquer algorithm to "bottom out"? What does it mean for a divide-and-conquer algorithm to "bottom out"?
Back: An input that cannot (or should not) be divided any further is encountered. Back: An input that cannot (or should not) be divided any further is encountered.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467151--> <!--ID: 1708742467151-->
END%% END%%
@ -38,14 +38,14 @@ END%%
Basic Basic
In the context of algorithms, what does a "sentinel" refer to? In the context of algorithms, what does a "sentinel" refer to?
Back: A special value used to simplify code. Back: A special value used to simplify code.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467155--> <!--ID: 1708742467155-->
END%% END%%
%%ANKI %%ANKI
Cloze Cloze
Insertion sort is to an {incremental} design approach whereas merge sort is to a {divide-and-conquer} design approach. Insertion sort is to an {incremental} design approach whereas merge sort is to a {divide-and-conquer} design approach.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467159--> <!--ID: 1708742467159-->
END%% END%%
@ -53,7 +53,7 @@ END%%
Basic Basic
What ideas does the term "divide-and-conquer" invoke? What ideas does the term "divide-and-conquer" invoke?
Back: Breaking a problem into subproblems that are easier to solve. Back: Breaking a problem into subproblems that are easier to solve.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467164--> <!--ID: 1708742467164-->
END%% END%%
@ -61,7 +61,7 @@ END%%
Basic Basic
According to Cormen et al., what three steps do divide-and-conquer algorithms take? According to Cormen et al., what three steps do divide-and-conquer algorithms take?
Back: Divide, conquer, and combine. Back: Divide, conquer, and combine.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467167--> <!--ID: 1708742467167-->
END%% END%%
@ -69,7 +69,7 @@ END%%
Basic Basic
What is the "divide" step of a divide-and-conquer algorithm? What is the "divide" step of a divide-and-conquer algorithm?
Back: Breaking the problem into smaller instances of the same problem. Back: Breaking the problem into smaller instances of the same problem.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467172--> <!--ID: 1708742467172-->
END%% END%%
@ -77,7 +77,7 @@ END%%
Basic Basic
What is the "conquer" step of a divide-and-conquer algorithm? What is the "conquer" step of a divide-and-conquer algorithm?
Back: Solving subproblems recursively or, if small enough, in a straightforward manner. Back: Solving subproblems recursively or, if small enough, in a straightforward manner.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467178--> <!--ID: 1708742467178-->
END%% END%%
@ -85,7 +85,7 @@ END%%
Basic Basic
What is the "combine" step of a divide-and-conquer algorithm? What is the "combine" step of a divide-and-conquer algorithm?
Back: Manipulating solutions to smaller problems into a solution for the original problem. Back: Manipulating solutions to smaller problems into a solution for the original problem.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467182--> <!--ID: 1708742467182-->
END%% END%%
@ -93,10 +93,10 @@ END%%
Basic Basic
What is a running time recurrence? What is a running time recurrence?
Back: A formula that describes overall running time in terms of running time on smaller inputs. Back: A formula that describes overall running time in terms of running time on smaller inputs.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467187--> <!--ID: 1708742467187-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -21,7 +21,7 @@ A loop invariant $P$ is a condition that holds before, during, and after each it
Basic Basic
What are the three necessary properties of a loop invariant? What are the three necessary properties of a loop invariant?
Back: Initialization, maintenance, and termination. Back: Initialization, maintenance, and termination.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329732922--> <!--ID: 1707329732922-->
END%% END%%
@ -29,7 +29,7 @@ END%%
Basic Basic
What does it mean for loop invariant $P$ to respect initialization? What does it mean for loop invariant $P$ to respect initialization?
Back: $P$ is true before the first iteration of the loop. Back: $P$ is true before the first iteration of the loop.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329732926--> <!--ID: 1707329732926-->
END%% END%%
@ -37,7 +37,7 @@ END%%
Basic Basic
What does it mean for loop invariant $P$ to respect maintenance? What does it mean for loop invariant $P$ to respect maintenance?
Back: If $P$ is true before an iteration, $P$ is also true before the next iteration. Back: If $P$ is true before an iteration, $P$ is also true before the next iteration.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329732928--> <!--ID: 1707329732928-->
END%% END%%
@ -45,7 +45,7 @@ END%%
Basic Basic
What does it mean for loop invariant $P$ to respect termination? What does it mean for loop invariant $P$ to respect termination?
Back: $P$ provides a condition used to prove an algorithm's correctness. Back: $P$ provides a condition used to prove an algorithm's correctness.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329732929--> <!--ID: 1707329732929-->
END%% END%%
@ -56,7 +56,7 @@ At what point in the following should initialization of a loop invariant be chec
for (int i = 0; i < n; ++i) { ... } for (int i = 0; i < n; ++i) { ... }
``` ```
Back: After `int i = 0` but before `i < n`. Back: After `int i = 0` but before `i < n`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
Tags: c17 Tags: c17
<!--ID: 1707329732931--> <!--ID: 1707329732931-->
END%% END%%
@ -66,14 +66,14 @@ Notice loop invariants mirror mathematical induction. Initialization is analogou
%%ANKI %%ANKI
Cloze Cloze
Loop invariants are to {initialization} whereas mathematical induction is to {a base case}. Loop invariants are to {initialization} whereas mathematical induction is to {a base case}.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329951146--> <!--ID: 1707329951146-->
END%% END%%
%%ANKI %%ANKI
Cloze Cloze
Loop invariants are to {maintenance} whereas mathematical induction is to {the inductive step}. Loop invariants are to {maintenance} whereas mathematical induction is to {the inductive step}.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329951148--> <!--ID: 1707329951148-->
END%% END%%
@ -81,10 +81,10 @@ END%%
Basic Basic
Which loop invariant property has no analogy to mathematical induction? Which loop invariant property has no analogy to mathematical induction?
Back: Termination Back: Termination
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329951150--> <!--ID: 1707329951150-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@ Adaptive | Yes
Basic Basic
Describe `BUBBLE_SORT` in a single sentence. Describe `BUBBLE_SORT` in a single sentence.
Back: Repeatedly swap the smaller of adjacent records downward. Back: Repeatedly swap the smaller of adjacent records downward.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707589393196--> <!--ID: 1707589393196-->
END%% END%%
@ -32,7 +32,7 @@ END%%
Basic Basic
What is `BUBBLE_SORT`'s best case runtime? What is `BUBBLE_SORT`'s best case runtime?
Back: $\Omega(n)$ Back: $\Omega(n)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634781--> <!--ID: 1707504634781-->
END%% END%%
@ -40,7 +40,7 @@ END%%
Basic Basic
How is it `BUBBLE_SORT` achieves best case linear runtime? How is it `BUBBLE_SORT` achieves best case linear runtime?
Back: By terminating when no swaps occurred on a given iteration. Back: By terminating when no swaps occurred on a given iteration.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634782--> <!--ID: 1707504634782-->
END%% END%%
@ -48,7 +48,7 @@ END%%
Basic Basic
What input value does `BUBBLE_SORT` perform best on? What input value does `BUBBLE_SORT` perform best on?
Back: An already sorted array. Back: An already sorted array.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634784--> <!--ID: 1707504634784-->
END%% END%%
@ -56,7 +56,7 @@ END%%
Basic Basic
What is `BUBBLE_SORT`'s worst case runtime? What is `BUBBLE_SORT`'s worst case runtime?
Back: $O(n^2)$ Back: $O(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634785--> <!--ID: 1707504634785-->
END%% END%%
@ -64,7 +64,7 @@ END%%
Basic Basic
What input value does `BUBBLE_SORT` perform worst on? What input value does `BUBBLE_SORT` perform worst on?
Back: An array in reverse-sorted order. Back: An array in reverse-sorted order.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634787--> <!--ID: 1707504634787-->
END%% END%%
@ -72,7 +72,7 @@ END%%
Basic Basic
What is `BUBBLE_SORT`'s average case runtime? What is `BUBBLE_SORT`'s average case runtime?
Back: $O(n^2)$ Back: $O(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634788--> <!--ID: 1707504634788-->
END%% END%%
@ -80,7 +80,7 @@ END%%
Basic Basic
Is `BUBBLE_SORT` in place? Is `BUBBLE_SORT` in place?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634789--> <!--ID: 1707504634789-->
END%% END%%
@ -88,7 +88,7 @@ END%%
Basic Basic
Is `BUBBLE_SORT` stable? Is `BUBBLE_SORT` stable?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634791--> <!--ID: 1707504634791-->
END%% END%%
@ -96,7 +96,7 @@ END%%
Basic Basic
Is `BUBBLE_SORT` adaptive? Is `BUBBLE_SORT` adaptive?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634792--> <!--ID: 1707504634792-->
END%% END%%
@ -126,7 +126,7 @@ Basic
What sorting algorithm does the following demonstrate? What sorting algorithm does the following demonstrate?
![[bubble-sort.gif]] ![[bubble-sort.gif]]
Back: `BUBBLE_SORT` Back: `BUBBLE_SORT`
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634794--> <!--ID: 1707504634794-->
END%% END%%
@ -149,7 +149,7 @@ We prove $P$ maintains the requisite properties:
Basic Basic
Given array `A[0..n-1]`, what is `BUBBLE_SORT`'s loop invariant? Given array `A[0..n-1]`, what is `BUBBLE_SORT`'s loop invariant?
Back: `A[0..i-1]` is a sorted array of the `i` least elements of `A`. Back: `A[0..i-1]` is a sorted array of the `i` least elements of `A`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634796--> <!--ID: 1707504634796-->
END%% END%%
@ -157,7 +157,7 @@ END%%
Basic Basic
What is initialization of `BUBBLE_SORT`'s loop invariant? What is initialization of `BUBBLE_SORT`'s loop invariant?
Back: Sorting starts with an empty array which is trivially sorted. Back: Sorting starts with an empty array which is trivially sorted.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634797--> <!--ID: 1707504634797-->
END%% END%%
@ -165,7 +165,7 @@ END%%
Basic Basic
What is maintenance of `BUBBLE_SORT`'s loop invariant? What is maintenance of `BUBBLE_SORT`'s loop invariant?
Back: Each iteration puts the next least element into the sorted subarray. Back: Each iteration puts the next least element into the sorted subarray.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634798--> <!--ID: 1707504634798-->
END%% END%%
@ -176,7 +176,7 @@ Back:
``` ```
[ sorted | unsorted ] [ sorted | unsorted ]
``` ```
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634800--> <!--ID: 1707504634800-->
END%% END%%
@ -187,17 +187,17 @@ Which element will `BUBBLE_SORT` move to `sorted`?
[ sorted | unsorted ] [ sorted | unsorted ]
``` ```
Back: The least element in `unsorted`. Back: The least element in `unsorted`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634801--> <!--ID: 1707504634801-->
END%% END%%
%%ANKI %%ANKI
Cloze Cloze
Selection sort makes fewer {swaps} than `BUBBLE_SORT` in the average case. Selection sort makes fewer {swaps} than `BUBBLE_SORT` in the average case.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634803--> <!--ID: 1707504634803-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -24,7 +24,7 @@ Adaptive | Yes
Basic Basic
Describe `INSERTION_SORT` in a single sentence. Describe `INSERTION_SORT` in a single sentence.
Back: Repeatedly put the next record into a sorted array from right to left. Back: Repeatedly put the next record into a sorted array from right to left.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707589393194--> <!--ID: 1707589393194-->
END%% END%%
@ -32,7 +32,7 @@ END%%
Basic Basic
What is `INSERTION_SORT`'s best case runtime? What is `INSERTION_SORT`'s best case runtime?
Back: $\Omega(n)$ Back: $\Omega(n)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706925879541--> <!--ID: 1706925879541-->
END%% END%%
@ -40,7 +40,7 @@ END%%
Basic Basic
What input value does `INSERTION_SORT` perform best on? What input value does `INSERTION_SORT` perform best on?
Back: An already sorted array. Back: An already sorted array.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706925921544--> <!--ID: 1706925921544-->
END%% END%%
@ -48,7 +48,7 @@ END%%
Basic Basic
What is `INSERTION_SORT`'s worst case runtime? What is `INSERTION_SORT`'s worst case runtime?
Back: $O(n^2)$ Back: $O(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706926586947--> <!--ID: 1706926586947-->
END%% END%%
@ -56,7 +56,7 @@ END%%
Basic Basic
What input value does `INSERTION_SORT` perform worst on? What input value does `INSERTION_SORT` perform worst on?
Back: An array in reverse-sorted order. Back: An array in reverse-sorted order.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706926586951--> <!--ID: 1706926586951-->
END%% END%%
@ -64,7 +64,7 @@ END%%
Basic Basic
What is `INSERTION_SORT`'s average case runtime? What is `INSERTION_SORT`'s average case runtime?
Back: $O(n^2)$ Back: $O(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707329732933--> <!--ID: 1707329732933-->
END%% END%%
@ -72,7 +72,7 @@ END%%
Basic Basic
Is `INSERTION_SORT` in place? Is `INSERTION_SORT` in place?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706926586955--> <!--ID: 1706926586955-->
END%% END%%
@ -80,7 +80,7 @@ END%%
Basic Basic
Is `INSERTION_SORT` stable? Is `INSERTION_SORT` stable?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706926586959--> <!--ID: 1706926586959-->
END%% END%%
@ -88,7 +88,7 @@ END%%
Basic Basic
Is `INSERTION_SORT` adaptive? Is `INSERTION_SORT` adaptive?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634779--> <!--ID: 1707504634779-->
END%% END%%
@ -110,7 +110,7 @@ Basic
What sorting algorithm does the following demonstrate? What sorting algorithm does the following demonstrate?
![[insertion-sort.gif]] ![[insertion-sort.gif]]
Back: `INSERTION_SORT` Back: `INSERTION_SORT`
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707400559085--> <!--ID: 1707400559085-->
END%% END%%
@ -140,7 +140,7 @@ END%%
Basic Basic
What is initialization of `INSERTION_SORT`'s loop invariant? What is initialization of `INSERTION_SORT`'s loop invariant?
Back: Sorting starts with an singleton array which is trivially sorted. Back: Sorting starts with an singleton array which is trivially sorted.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707332638373--> <!--ID: 1707332638373-->
END%% END%%
@ -148,14 +148,14 @@ END%%
Basic Basic
What is maintenance of `INSERTION_SORT`'s loop invariant? What is maintenance of `INSERTION_SORT`'s loop invariant?
Back: Each iteration puts the current element into sorted order. Back: Each iteration puts the current element into sorted order.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707332638375--> <!--ID: 1707332638375-->
END%% END%%
%%ANKI %%ANKI
Cloze Cloze
`INSERTION_SORT` makes fewer {comparisons} than `SELECTION_SORT` in the average case. `INSERTION_SORT` makes fewer {comparisons} than `SELECTION_SORT` in the average case.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708002185982--> <!--ID: 1708002185982-->
END%% END%%
@ -169,7 +169,7 @@ If you repeat this process for every card in the deck, your left hand will event
Basic Basic
What analogy does Cormen et al. use to explain `INSERTION_SORT`? What analogy does Cormen et al. use to explain `INSERTION_SORT`?
Back: Sorting a shuffled deck of playing cards. Back: Sorting a shuffled deck of playing cards.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706927594729--> <!--ID: 1706927594729-->
END%% END%%
@ -177,7 +177,7 @@ END%%
Basic Basic
What invariant does the left hand maintain in Cormen et al.'s `INSERTION_SORT` analogy? What invariant does the left hand maintain in Cormen et al.'s `INSERTION_SORT` analogy?
Back: It contains all drawn cards in sorted order. Back: It contains all drawn cards in sorted order.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1706927594732--> <!--ID: 1706927594732-->
END%% END%%
@ -188,7 +188,7 @@ Back:
``` ```
[ sorted | unsorted ] [ sorted | unsorted ]
``` ```
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707399790957--> <!--ID: 1707399790957-->
END%% END%%
@ -199,7 +199,7 @@ How many comparisons does `INSERTION_SORT` typically perform with `x`?
[ sorted | x : unsorted ] [ sorted | x : unsorted ]
``` ```
Back: One plus however many elements in `sorted` are greater than `x`. Back: One plus however many elements in `sorted` are greater than `x`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707399790958--> <!--ID: 1707399790958-->
END%% END%%
@ -210,10 +210,10 @@ Which element will `INSERTION_SORT` move to `sorted`?
[ sorted | unsorted ] [ sorted | unsorted ]
``` ```
Back: The first element of `unsorted`. Back: The first element of `unsorted`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707399790960--> <!--ID: 1707399790960-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -24,7 +24,7 @@ Adaptive | -
Basic Basic
What does the term "merge" in `MERGE_SORT` refer to? What does the term "merge" in `MERGE_SORT` refer to?
Back: The primary operation used to combine array halves. Back: The primary operation used to combine array halves.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467101--> <!--ID: 1708742467101-->
END%% END%%
@ -32,7 +32,7 @@ END%%
Basic Basic
What is `MERGE_SORT`'s best case runtime? What is `MERGE_SORT`'s best case runtime?
Back: $\Omega(n\lg{n})$ Back: $\Omega(n\lg{n})$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467109--> <!--ID: 1708742467109-->
END%% END%%
@ -40,7 +40,7 @@ END%%
Basic Basic
What is `MERGE_SORT`'s worst case runtime? What is `MERGE_SORT`'s worst case runtime?
Back: $O(n\lg{n})$ Back: $O(n\lg{n})$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467112--> <!--ID: 1708742467112-->
END%% END%%
@ -48,7 +48,7 @@ END%%
Basic Basic
What is `MERGE_SORT`'s average case runtime? What is `MERGE_SORT`'s average case runtime?
Back: $O(n\lg{n})$ Back: $O(n\lg{n})$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467115--> <!--ID: 1708742467115-->
END%% END%%
@ -56,7 +56,7 @@ END%%
Basic Basic
What is the "divide" step of `MERGE_SORT`? What is the "divide" step of `MERGE_SORT`?
Back: Divide the input array into two subarrays of half size. Back: Divide the input array into two subarrays of half size.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467118--> <!--ID: 1708742467118-->
END%% END%%
@ -64,7 +64,7 @@ END%%
Basic Basic
What is the "conquer" step of `MERGE_SORT`? What is the "conquer" step of `MERGE_SORT`?
Back: Call `MERGE_SORT` on the "divide"-step's two subarrays. Back: Call `MERGE_SORT` on the "divide"-step's two subarrays.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467121--> <!--ID: 1708742467121-->
END%% END%%
@ -72,7 +72,7 @@ END%%
Basic Basic
What is the "combine" step of `MERGE_SORT`? What is the "combine" step of `MERGE_SORT`?
Back: Merge the sorted subarrays produced by the "conquer" step. Back: Merge the sorted subarrays produced by the "conquer" step.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467125--> <!--ID: 1708742467125-->
END%% END%%
@ -80,7 +80,7 @@ END%%
Basic Basic
When does `MERGE_SORT` "bottom out"? When does `MERGE_SORT` "bottom out"?
Back: When the sequence to be sorted has length 1 or less. Back: When the sequence to be sorted has length 1 or less.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467133--> <!--ID: 1708742467133-->
END%% END%%
@ -130,7 +130,7 @@ void merge_sort(int i, int j, int *A) {
Basic Basic
Where in `MERGE_SORT`'s implementation are sentinels useful? Where in `MERGE_SORT`'s implementation are sentinels useful?
Back: As the last elements of the two arrays to combine. Back: As the last elements of the two arrays to combine.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467137--> <!--ID: 1708742467137-->
END%% END%%
@ -138,7 +138,7 @@ END%%
Basic Basic
What sentinel values are typically used in `MERGE_SORT`'s "merge" operation? What sentinel values are typically used in `MERGE_SORT`'s "merge" operation?
Back: $\infty$ or the record type's equivalent. Back: $\infty$ or the record type's equivalent.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742467141--> <!--ID: 1708742467141-->
END%% END%%
@ -147,10 +147,10 @@ Basic
What sorting algorithm does the following demonstrate? What sorting algorithm does the following demonstrate?
![[merge-sort.gif]] ![[merge-sort.gif]]
Back: `MERGE_SORT` Back: `MERGE_SORT`
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708742590435--> <!--ID: 1708742590435-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -25,7 +25,7 @@ Adaptive | No
Basic Basic
Describe `SELECTION_SORT` in a single sentence. Describe `SELECTION_SORT` in a single sentence.
Back: Repeatedly put the smallest unsorted record at the end of a sorted array. Back: Repeatedly put the smallest unsorted record at the end of a sorted array.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707589393190--> <!--ID: 1707589393190-->
END%% END%%
@ -33,7 +33,7 @@ END%%
Basic Basic
What is `SELECTION_SORT`'s best case runtime? What is `SELECTION_SORT`'s best case runtime?
Back: $\Omega(n^2)$ Back: $\Omega(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773323--> <!--ID: 1707398773323-->
END%% END%%
@ -41,7 +41,7 @@ END%%
Basic Basic
What is `SELECTION_SORT`'s worst case runtime? What is `SELECTION_SORT`'s worst case runtime?
Back: $O(n^2)$ Back: $O(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773326--> <!--ID: 1707398773326-->
END%% END%%
@ -49,7 +49,7 @@ END%%
Basic Basic
What is `SELECTION_SORT`'s average case runtime? What is `SELECTION_SORT`'s average case runtime?
Back: $O(n^2)$ Back: $O(n^2)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773327--> <!--ID: 1707398773327-->
END%% END%%
@ -57,7 +57,7 @@ END%%
Basic Basic
Is `SELECTION_SORT` in place? Is `SELECTION_SORT` in place?
Back: Yes Back: Yes
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773328--> <!--ID: 1707398773328-->
END%% END%%
@ -65,7 +65,7 @@ END%%
Basic Basic
Is `SELECTION_SORT` stable? Is `SELECTION_SORT` stable?
Back: No Back: No
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773330--> <!--ID: 1707398773330-->
END%% END%%
@ -73,7 +73,7 @@ END%%
Basic Basic
Is `SELECTION_SORT` adaptive? Is `SELECTION_SORT` adaptive?
Back: No Back: No
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707504634778--> <!--ID: 1707504634778-->
END%% END%%
@ -102,7 +102,7 @@ Basic
What sorting algorithm does the following demonstrate? What sorting algorithm does the following demonstrate?
![[selection-sort.gif]] ![[selection-sort.gif]]
Back: `SELECTION_SORT` Back: `SELECTION_SORT`
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707400943836--> <!--ID: 1707400943836-->
END%% END%%
@ -125,7 +125,7 @@ We prove $P$ maintains the requisite properties:
Basic Basic
Given array `A[0..n-1]`, what is `SELECTION_SORT`'s loop invariant? Given array `A[0..n-1]`, what is `SELECTION_SORT`'s loop invariant?
Back: `A[0..i-1]` is a sorted array of the `i` least elements of `A`. Back: `A[0..i-1]` is a sorted array of the `i` least elements of `A`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773331--> <!--ID: 1707398773331-->
END%% END%%
@ -133,7 +133,7 @@ END%%
Basic Basic
What is initialization of `SELECTION_SORT`'s loop invariant? What is initialization of `SELECTION_SORT`'s loop invariant?
Back: Sorting starts with an empty array which is trivially sorted. Back: Sorting starts with an empty array which is trivially sorted.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773333--> <!--ID: 1707398773333-->
END%% END%%
@ -141,7 +141,7 @@ END%%
Basic Basic
What is maintenance of `SELECTION_SORT`'s loop invariant? What is maintenance of `SELECTION_SORT`'s loop invariant?
Back: Each iteration puts the next least element into the sorted subarray. Back: Each iteration puts the next least element into the sorted subarray.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707398773334--> <!--ID: 1707398773334-->
END%% END%%
@ -152,7 +152,7 @@ Back:
``` ```
[ sorted | unsorted ] [ sorted | unsorted ]
``` ```
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707399790952--> <!--ID: 1707399790952-->
END%% END%%
@ -163,17 +163,17 @@ Which element will `SELECTION_SORT` move to `sorted`?
[ sorted | unsorted ] [ sorted | unsorted ]
``` ```
Back: The least element in `unsorted`. Back: The least element in `unsorted`.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1707399790955--> <!--ID: 1707399790955-->
END%% END%%
%%ANKI %%ANKI
Cloze Cloze
`SELECTION_SORT` makes fewer {swaps} than `INSERTION_SORT` in the average case. `SELECTION_SORT` makes fewer {swaps} than `INSERTION_SORT` in the average case.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).
<!--ID: 1708002177782--> <!--ID: 1708002177782-->
END%% END%%
## References ## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009). * Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022).

View File

@ -31,15 +31,6 @@ Reference: Brian W. Kernighan and Dennis M. Ritchie, *The C Programming Language
<!--ID: 1706975891810--> <!--ID: 1706975891810-->
END%% END%%
%%ANKI
Basic
What alternative does Lua provide to C's `\ooo` sequence?
Back: `\ddd`, a *decimal* escape sequence.
Reference: Roberto Ierusalimschy, _Programming in Lua_, Fourth edition (Rio de Janeiro: Lua.org, 2016).
Tags: lua
<!--ID: 1706975891813-->
END%%
%%ANKI %%ANKI
Basic Basic
How are C escape sequences exposed in bash? How are C escape sequences exposed in bash?

View File

@ -1,5 +0,0 @@
---
title: Lua
tags:
- lua
---

1048
notes/set/graphs.md Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

7
notes/set/index.md Normal file
View File

@ -0,0 +1,7 @@
---
title: Set
TARGET DECK: Obsidian::STEM
FILE TAGS: set
tags:
- set
---