Add notes on next lexicographic ordering.
parent
ec45aad8c3
commit
1651c9d6c3
|
@ -96,7 +96,7 @@
|
||||||
"File Hashes": {
|
"File Hashes": {
|
||||||
"algorithms/index.md": "cd7c7ba91fb2f961c9f2437777e8e2ac",
|
"algorithms/index.md": "cd7c7ba91fb2f961c9f2437777e8e2ac",
|
||||||
"algorithms/sorting/index.md": "2d5a18a3079d96fa9e3d4289181a8b6c",
|
"algorithms/sorting/index.md": "2d5a18a3079d96fa9e3d4289181a8b6c",
|
||||||
"algorithms/sorting/insertion-sort.md": "00e4edb132d473b0516fde3307ebae30",
|
"algorithms/sorting/insertion-sort.md": "10525c1e013a341ef51656bedf41a61b",
|
||||||
"bash/index.md": "3e4738d8d3531bb7a5afc53a2d73036c",
|
"bash/index.md": "3e4738d8d3531bb7a5afc53a2d73036c",
|
||||||
"bash/prompts.md": "61cb877e68da040a15b85af76b1f68ba",
|
"bash/prompts.md": "61cb877e68da040a15b85af76b1f68ba",
|
||||||
"bash/quoting.md": "b1d8869a91001f8b22f0cdc54d806f61",
|
"bash/quoting.md": "b1d8869a91001f8b22f0cdc54d806f61",
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
"nix/callPackage.md": "140a02e57cd01d646483e3c21d72243d",
|
"nix/callPackage.md": "140a02e57cd01d646483e3c21d72243d",
|
||||||
"nix/index.md": "4efc7fcc4ea22834ba595497e5fb715c",
|
"nix/index.md": "4efc7fcc4ea22834ba595497e5fb715c",
|
||||||
"posix/index.md": "97b1b8ecb9a953e855a9acf0ab25b8c8",
|
"posix/index.md": "97b1b8ecb9a953e855a9acf0ab25b8c8",
|
||||||
"posix/signals.md": "51b7399fa84a9528e319a758017013f9",
|
"posix/signals.md": "e8a62cbece8a6bfc54a4e67bbdf3be7c",
|
||||||
"templates/daily.md": "7866014e730e85683155207a02e367d8",
|
"templates/daily.md": "7866014e730e85683155207a02e367d8",
|
||||||
"posix/regexp.md": "f5fb177c7356faf1bf768023c2563c54",
|
"posix/regexp.md": "f5fb177c7356faf1bf768023c2563c54",
|
||||||
"journal/2024-02-04.md": "e2b5678fc53d7284b71ed6820c02b954",
|
"journal/2024-02-04.md": "e2b5678fc53d7284b71ed6820c02b954",
|
||||||
|
@ -135,9 +135,9 @@
|
||||||
"algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2",
|
"algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2",
|
||||||
"algorithms/loop-invariant.md": "29f9f9090a3109890d333a78acc18b50",
|
"algorithms/loop-invariant.md": "29f9f9090a3109890d333a78acc18b50",
|
||||||
"algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65",
|
"algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65",
|
||||||
"algorithms/order-growth.md": "a4e6620e785f7d677236948182e831cc",
|
"algorithms/order-growth.md": "80801ebb1a9142150699b05b0b41d819",
|
||||||
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
|
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
|
||||||
"algorithms/sorting/selection-sort.md": "fcd0dc2ebaabd0a4db1baf7e7ef9f7a9",
|
"algorithms/sorting/selection-sort.md": "3e4f059f01210d050ec6e7279e93e43c",
|
||||||
"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",
|
||||||
|
@ -145,7 +145,7 @@
|
||||||
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
|
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
|
||||||
"logic/quantification.md": "5d7579a511e9ff683edeec62bcc291b8",
|
"logic/quantification.md": "5d7579a511e9ff683edeec62bcc291b8",
|
||||||
"c/declarations.md": "2de27f565d1020819008ae80593af435",
|
"c/declarations.md": "2de27f565d1020819008ae80593af435",
|
||||||
"algorithms/sorting/bubble-sort.md": "16dad1016dc6555163e42ba20f1d152d",
|
"algorithms/sorting/bubble-sort.md": "96c4b9426bcb4284de60b9144ba09b9e",
|
||||||
"_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",
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
"_journal/2024-02/2024-02-15.md": "16cb7563d404cb543719b7bb5037aeed",
|
"_journal/2024-02/2024-02-15.md": "16cb7563d404cb543719b7bb5037aeed",
|
||||||
"algebra/floor-ceiling.md": "828b11e642d6803a740b58f27ff047cf",
|
"algebra/floor-ceiling.md": "828b11e642d6803a740b58f27ff047cf",
|
||||||
"algebra/index.md": "90b842eb694938d87c7c68779a5cacd1",
|
"algebra/index.md": "90b842eb694938d87c7c68779a5cacd1",
|
||||||
"algorithms/binary-search.md": "dbbaf8d4be7aabef1ed232c1906b4c99",
|
"algorithms/binary-search.md": "27189885f0bc1e8b8b9049da3ed92f98",
|
||||||
"_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",
|
||||||
|
@ -191,11 +191,11 @@
|
||||||
"combinatorics/additive-principle.md": "e968028670f95ee9a7c5499ff7cb6792",
|
"combinatorics/additive-principle.md": "e968028670f95ee9a7c5499ff7cb6792",
|
||||||
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
|
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
|
||||||
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
|
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
|
||||||
"combinatorics/permutations.md": "7ff83dd8784eb08fc9389d38adc8862c",
|
"combinatorics/permutations.md": "d257cab50c2767419b0cc3f7b86bd528",
|
||||||
"combinatorics/combinations.md": "b53ac22d03941b697597377c7c8da346",
|
"combinatorics/combinations.md": "5ae0152180a1af7187c43606a4002202",
|
||||||
"_journal/2024-02-20.md": "b85ba0eeeb16e30a602ccefabcc9763e",
|
"_journal/2024-02-20.md": "b85ba0eeeb16e30a602ccefabcc9763e",
|
||||||
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
|
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
|
||||||
"combinatorics/inclusion-exclusion.md": "ca5c967be774ce204f1ca47cc8df14b8",
|
"combinatorics/inclusion-exclusion.md": "202a60120d451676d44df4d0be30a45a",
|
||||||
"_journal/2024-02-21.md": "b9d944ecebe625da5dd72aeea6a916a2",
|
"_journal/2024-02-21.md": "b9d944ecebe625da5dd72aeea6a916a2",
|
||||||
"_journal/2024-02/2024-02-20.md": "af2ef10727726200c4defe2eafc7d841",
|
"_journal/2024-02/2024-02-20.md": "af2ef10727726200c4defe2eafc7d841",
|
||||||
"algebra/radices.md": "4ffc8525f2b877c0d17e3359870797fe",
|
"algebra/radices.md": "4ffc8525f2b877c0d17e3359870797fe",
|
||||||
|
@ -207,7 +207,7 @@
|
||||||
"c17/index.md": "78576ee41d0185df82c59999142f4edb",
|
"c17/index.md": "78576ee41d0185df82c59999142f4edb",
|
||||||
"c17/escape-sequences.md": "ebc63c6cdfbe60bbc2708c1b0c8da8bb",
|
"c17/escape-sequences.md": "ebc63c6cdfbe60bbc2708c1b0c8da8bb",
|
||||||
"c17/declarations.md": "20e200f2b7abcab8f873cd080f4c9770",
|
"c17/declarations.md": "20e200f2b7abcab8f873cd080f4c9770",
|
||||||
"algorithms/sorting/merge-sort.md": "0a204db7441c761c6ee13689113760dd",
|
"algorithms/sorting/merge-sort.md": "fdc6311b0f9e7d85899fc77a95872a2f",
|
||||||
"_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",
|
||||||
|
@ -222,7 +222,7 @@
|
||||||
"filesystems/cas.md": "34906013a2a60fe5ee0e31809b4838aa",
|
"filesystems/cas.md": "34906013a2a60fe5ee0e31809b4838aa",
|
||||||
"git/objects.md": "1c867853b080700a73de55b7be185f8d",
|
"git/objects.md": "1c867853b080700a73de55b7be185f8d",
|
||||||
"git/index.md": "83d2d95fc549d9e8436946c7bd058d15",
|
"git/index.md": "83d2d95fc549d9e8436946c7bd058d15",
|
||||||
"encoding/integer.md": "84b2ce080e0e756f265257e57467f0e6",
|
"encoding/integer.md": "052dce2f39b72cc8d46bea58bfdb1b97",
|
||||||
"_journal/2024-02-29.md": "f610f3caed659c1de3eed5f226cab508",
|
"_journal/2024-02-29.md": "f610f3caed659c1de3eed5f226cab508",
|
||||||
"_journal/2024-02/2024-02-28.md": "7489377c014a2ff3c535d581961b5b82",
|
"_journal/2024-02/2024-02-28.md": "7489377c014a2ff3c535d581961b5b82",
|
||||||
"_journal/2024-03-01.md": "a532486279190b0c12954966cbf8c3fe",
|
"_journal/2024-03-01.md": "a532486279190b0c12954966cbf8c3fe",
|
||||||
|
@ -240,7 +240,9 @@
|
||||||
"_journal/2024-03-05.md": "e9a911c19bb4c0ff451db793248cb4bb",
|
"_journal/2024-03-05.md": "e9a911c19bb4c0ff451db793248cb4bb",
|
||||||
"_journal/2024-03/2024-03-04.md": "4948d90a08af2cff58c629c9a2e11ee4",
|
"_journal/2024-03/2024-03-04.md": "4948d90a08af2cff58c629c9a2e11ee4",
|
||||||
"algebra/sequences/geometric.md": "53936ec392b3b714bd4a9bdb4554b582",
|
"algebra/sequences/geometric.md": "53936ec392b3b714bd4a9bdb4554b582",
|
||||||
"algebra/sequences/arithmetic.md": "80381ca0f2b3b9a1c155c597a7dea75a"
|
"algebra/sequences/arithmetic.md": "80381ca0f2b3b9a1c155c597a7dea75a",
|
||||||
|
"_journal/2024-03-06.md": "ac7a3d764934f49b2be7aa76e402d853",
|
||||||
|
"_journal/2024-03/2024-03-05.md": "94b28d0b9bc62cc0bd99d315fb7c6d30"
|
||||||
},
|
},
|
||||||
"fields_dict": {
|
"fields_dict": {
|
||||||
"Basic": [
|
"Basic": [
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
title: "2024-03-06"
|
||||||
|
---
|
||||||
|
|
||||||
|
- [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)
|
||||||
|
|
||||||
|
* Added notes on how asymptotic notation relates to one another.
|
|
@ -25,4 +25,5 @@ title: "2024-03-05"
|
||||||
* Q-114783
|
* Q-114783
|
||||||
* Q-26296
|
* Q-26296
|
||||||
* Leetcode Problems
|
* Leetcode Problems
|
||||||
* [Next Permutation](https://leetcode.com/problems/next-permutation/)
|
* [Next Permutation](https://leetcode.com/problems/next-permutation/)
|
||||||
|
* Purged all blockchain-related flashcards from Anki.
|
|
@ -16,7 +16,7 @@ Aux. Memory | $O(1)$
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708781334247-->
|
<!--ID: 1708781334247-->
|
||||||
|
@ -24,7 +24,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708117310004-->
|
<!--ID: 1708117310004-->
|
||||||
|
@ -32,7 +32,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708117310011-->
|
<!--ID: 1708117310011-->
|
||||||
|
@ -40,7 +40,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708117310015-->
|
<!--ID: 1708117310015-->
|
||||||
|
@ -48,7 +48,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708117310018-->
|
<!--ID: 1708117310018-->
|
||||||
|
@ -56,7 +56,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708117310021-->
|
<!--ID: 1708117310021-->
|
||||||
|
@ -106,7 +106,7 @@ int binary_search(const int needle, const int n, int A[static n]) {
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708174545522-->
|
<!--ID: 1708174545522-->
|
||||||
|
@ -114,8 +114,8 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708174545527-->
|
<!--ID: 1708174545527-->
|
||||||
END%%
|
END%%
|
||||||
|
|
|
@ -332,7 +332,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
What condition must $g(n)$ satisfy such that otherwise $\Theta(g(n))$ is empty?
|
What condition must $g(n)$ satisfy such that $\Theta(g(n))$ is nonempty?
|
||||||
Back: $g(n)$ must be asymptotically nonnegative.
|
Back: $g(n)$ must be asymptotically nonnegative.
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708974221876-->
|
<!--ID: 1708974221876-->
|
||||||
|
@ -397,6 +397,62 @@ Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambri
|
||||||
<!--ID: 1709053894064-->
|
<!--ID: 1709053894064-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transitive property of $\Theta$-notation?
|
||||||
|
Back: $f(n) = \Theta(g(n))$ and $g(n) = \Theta(h(n))$ implies $f(n) = \Theta(h(n))$.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223294-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the reflexive property of $\Theta$-notation?
|
||||||
|
Back: $f(n) = \Theta(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223298-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What condition must $f(n)$ satisfy for equality $f(n) = \Theta(f(n))$ to hold?
|
||||||
|
Back: $f(n)$ must be nonnegatively asymptotic.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223303-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
*Why* must $f(n)$ be nonnegatively asymptotic for $f(n) = \Theta(f(n))$ to hold?
|
||||||
|
Back: Otherwise $\Theta(f(n))$ is the empty set.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223309-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the symmetric property of $\Theta$-notation?
|
||||||
|
Back: $f(n) = \Theta(g(n))$ iff $g(n) = \Theta(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223316-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transpose symmetric property of $\Theta$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223322-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
$\Theta$-notation is likened to what comparison operator of real numbers?
|
||||||
|
Back: $=$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223329-->
|
||||||
|
END%%
|
||||||
|
|
||||||
## $O$-notation
|
## $O$-notation
|
||||||
|
|
||||||
![[big-o-notation.png]]
|
![[big-o-notation.png]]
|
||||||
|
@ -471,6 +527,7 @@ Basic
|
||||||
Using typical identifiers, what is the upper bound of $f(n)$ in $O(g(n))$?
|
Using typical identifiers, what is the upper bound of $f(n)$ in $O(g(n))$?
|
||||||
Back: $cg(n)$
|
Back: $cg(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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709750359817-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
|
@ -498,7 +555,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
What condition must $g(n)$ satisfy such that otherwise $O(g(n))$ is empty?
|
What condition must $g(n)$ satisfy such that $O(g(n))$ is nonempty?
|
||||||
Back: $g(n)$ must be asymptotically nonnegative.
|
Back: $g(n)$ must be asymptotically nonnegative.
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1709053894093-->
|
<!--ID: 1709053894093-->
|
||||||
|
@ -554,6 +611,62 @@ Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambri
|
||||||
<!--ID: 1709053894105-->
|
<!--ID: 1709053894105-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transitive property of $O$-notation?
|
||||||
|
Back: $f(n) = O(g(n))$ and $g(n) = O(h(n))$ implies $f(n) = O(h(n))$.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223338-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the reflexive property of $O$-notation?
|
||||||
|
Back: $f(n) = O(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223346-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What condition must $f(n)$ satisfy for equality $f(n) = O(f(n))$ to hold?
|
||||||
|
Back: $f(n)$ must be nonnegatively asymptotic.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223352-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
*Why* must $f(n)$ be nonnegatively asymptotic for $f(n) = O(f(n))$ to hold?
|
||||||
|
Back: Otherwise $O(f(n))$ is the empty set.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223358-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the symmetric property of $O$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223365-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transpose symmetric property of $O$-notation?
|
||||||
|
Back: $f(n) = O(g(n))$ iff $g(n) = \Omega(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223372-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
$O$-notation is likened to what comparison operator of real numbers?
|
||||||
|
Back: $\leq$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223381-->
|
||||||
|
END%%
|
||||||
|
|
||||||
## $o$-notation
|
## $o$-notation
|
||||||
|
|
||||||
$o$-notation refers to an upper bound that is not asymptotically tight. It is defined as set $$o(g(n)) = \{ f(n) \mid \forall c > 0, \exists n_0 > 0, \forall n \geq n_0, 0 \leq f(n) < cg(n) \}$$
|
$o$-notation refers to an upper bound that is not asymptotically tight. It is defined as set $$o(g(n)) = \{ f(n) \mid \forall c > 0, \exists n_0 > 0, \forall n \geq n_0, 0 \leq f(n) < cg(n) \}$$
|
||||||
|
@ -660,6 +773,77 @@ Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambri
|
||||||
<!--ID: 1709519002364-->
|
<!--ID: 1709519002364-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What condition must $g(n)$ satisfy such that $o(g(n))$ is nonempty?
|
||||||
|
Back: $g(n)$ must be asymptotically positive.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709750359822-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transitive property of $o$-notation?
|
||||||
|
Back: $f(n) = o(g(n))$ and $g(n) = o(h(n))$ implies $f(n) = o(h(n))$.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223391-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the reflexive property of $o$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223399-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
*Why* is there no reflexive property of $o$-notation?
|
||||||
|
Back: A function cannot be asymptotically smaller than itself.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223407-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the symmetric property of $o$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223417-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transpose symmetric property of $o$-notation?
|
||||||
|
Back: $f(n) = o(g(n))$ iff $g(n) = \omega(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223426-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
$o$-notation is likened to what comparison operator of real numbers?
|
||||||
|
Back: $<$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223435-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Cloze
|
||||||
|
{1:$\Omega$}-notation is to {2:$\geq$} whereas {2:$o$}-notation is to {1:$<$}.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223442-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How do we set theoretically say $f(n)$ is asymptotically smaller than $g(n)$?
|
||||||
|
Back: $f(n) = o(g(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223449-->
|
||||||
|
END%%
|
||||||
|
|
||||||
## $\Omega$-notation
|
## $\Omega$-notation
|
||||||
|
|
||||||
![[big-omega-notation.png]]
|
![[big-omega-notation.png]]
|
||||||
|
@ -762,7 +946,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
What condition must $g(n)$ satisfy such that otherwise $\Omega(g(n))$ is empty?
|
What condition must $g(n)$ satisfy such that $\Omega(g(n))$ is nonempty?
|
||||||
Back: $g(n)$ must be asymptotically nonnegative.
|
Back: $g(n)$ must be asymptotically nonnegative.
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1709055157396-->
|
<!--ID: 1709055157396-->
|
||||||
|
@ -816,6 +1000,76 @@ Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambri
|
||||||
<!--ID: 1709055157406-->
|
<!--ID: 1709055157406-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transitive property of $\Omega$-notation?
|
||||||
|
Back: $f(n) = \Omega(g(n))$ and $g(n) = \Omega(h(n))$ implies $f(n) = \Omega(h(n))$.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223456-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the reflexive property of $\Omega$-notation?
|
||||||
|
Back: $f(n) = \Omega(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223462-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What condition must $f(n)$ satisfy for equality $f(n) = \Omega(f(n))$ to hold?
|
||||||
|
Back: $f(n)$ must be nonnegatively asymptotic.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223468-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
*Why* must $f(n)$ be nonnegatively asymptotic for $f(n) = \Omega(f(n))$ to hold?
|
||||||
|
Back: Otherwise $\Omega(f(n))$ is the empty set.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223477-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the symmetric property of $\Omega$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223486-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transpose symmetric property of $\Omega$-notation?
|
||||||
|
Back: $f(n) = \Omega(g(n))$ iff $g(n) = O(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223496-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
$\Omega$-notation is likened to what comparison operator of real numbers?
|
||||||
|
Back: $\geq$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223503-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Cloze
|
||||||
|
{1:$\Theta$}-notation is to {2:$=$} whereas {2:$\Omega$}-notation is to {1:$\geq$}.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223511-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Cloze
|
||||||
|
{1:$O$}-notation is to {2:$\leq$} whereas {2:$\Omega$}-notation is to {1:$\geq$}.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223522-->
|
||||||
|
END%%
|
||||||
|
|
||||||
## $\omega$-notation
|
## $\omega$-notation
|
||||||
|
|
||||||
$\omega$-notation refers to a lower bound that is not asymptotically tight. It is defined as set $$\omega(g(n)) = \{ f(n) \mid \forall c > 0, \exists n_0 > 0, \forall n \geq n_0, 0 \leq cg(n) < f(n) \}$$
|
$\omega$-notation refers to a lower bound that is not asymptotically tight. It is defined as set $$\omega(g(n)) = \{ f(n) \mid \forall c > 0, \exists n_0 > 0, \forall n \geq n_0, 0 \leq cg(n) < f(n) \}$$
|
||||||
|
@ -922,6 +1176,77 @@ Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambri
|
||||||
<!--ID: 1709519002425-->
|
<!--ID: 1709519002425-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What condition must $g(n)$ satisfy such that $\omega(g(n))$ is nonempty?
|
||||||
|
Back: $g(n)$ must be asymptotically positive.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709750359826-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transitive property of $\omega$-notation?
|
||||||
|
Back: $f(n) = \omega(g(n))$ and $g(n) = \omega(h(n))$ implies $f(n) = \omega(h(n))$.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223531-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the reflexive property of $\omega$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223537-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
*Why* is there no reflexive property of $\omega$-notation?
|
||||||
|
Back: A function cannot be asymptotically larger than itself.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223544-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the symmetric property of $\omega$-notation?
|
||||||
|
Back: N/A
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223553-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the transpose symmetric property of $\omega$-notation?
|
||||||
|
Back: $f(n) = \omega(g(n))$ iff $g(n) = o(f(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223563-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
$\omega$-notation is likened to what comparison operator of real numbers?
|
||||||
|
Back: $>$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223570-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Cloze
|
||||||
|
{1:$O$}-notation is to {2:$\leq$} whereas {2:$\omega$}-notation is to {1:$>$}.
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223577-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How do we set theoretically say $f(n)$ is asymptotically larger than $g(n)$?
|
||||||
|
Back: $f(n) = \omega(g(n))$
|
||||||
|
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
|
<!--ID: 1709752223586-->
|
||||||
|
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
|
@ -22,7 +22,7 @@ Adaptive | Yes
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707589393196-->
|
<!--ID: 1707589393196-->
|
||||||
|
@ -30,7 +30,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634781-->
|
<!--ID: 1707504634781-->
|
||||||
|
@ -38,7 +38,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634782-->
|
<!--ID: 1707504634782-->
|
||||||
|
@ -46,7 +46,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634784-->
|
<!--ID: 1707504634784-->
|
||||||
|
@ -54,7 +54,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634785-->
|
<!--ID: 1707504634785-->
|
||||||
|
@ -62,7 +62,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634787-->
|
<!--ID: 1707504634787-->
|
||||||
|
@ -70,7 +70,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634788-->
|
<!--ID: 1707504634788-->
|
||||||
|
@ -78,7 +78,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634789-->
|
<!--ID: 1707504634789-->
|
||||||
|
@ -86,7 +86,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634791-->
|
<!--ID: 1707504634791-->
|
||||||
|
@ -94,7 +94,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634792-->
|
<!--ID: 1707504634792-->
|
||||||
|
@ -125,7 +125,7 @@ void bubble_sort(const int n, int A[static n]) {
|
||||||
Basic
|
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634794-->
|
<!--ID: 1707504634794-->
|
||||||
END%%
|
END%%
|
||||||
|
@ -147,7 +147,7 @@ We prove $P$ maintains the requisite properties:
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634796-->
|
<!--ID: 1707504634796-->
|
||||||
|
@ -155,7 +155,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634797-->
|
<!--ID: 1707504634797-->
|
||||||
|
@ -163,7 +163,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634798-->
|
<!--ID: 1707504634798-->
|
||||||
|
@ -171,7 +171,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
How does bubble sort partition its input array?
|
How does `BUBBLE_SORT` partition its input array?
|
||||||
Back:
|
Back:
|
||||||
```
|
```
|
||||||
[ sorted | unsorted ]
|
[ sorted | unsorted ]
|
||||||
|
@ -182,7 +182,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
Which element will bubble sort move to `sorted`?
|
Which element will `BUBBLE_SORT` move to `sorted`?
|
||||||
```
|
```
|
||||||
[ sorted | unsorted ]
|
[ sorted | unsorted ]
|
||||||
```
|
```
|
||||||
|
@ -193,7 +193,7 @@ 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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634803-->
|
<!--ID: 1707504634803-->
|
||||||
END%%
|
END%%
|
||||||
|
|
|
@ -22,7 +22,7 @@ Adaptive | Yes
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707589393194-->
|
<!--ID: 1707589393194-->
|
||||||
|
@ -30,7 +30,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706925879541-->
|
<!--ID: 1706925879541-->
|
||||||
|
@ -38,7 +38,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706925921544-->
|
<!--ID: 1706925921544-->
|
||||||
|
@ -46,7 +46,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706926586947-->
|
<!--ID: 1706926586947-->
|
||||||
|
@ -54,7 +54,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706926586951-->
|
<!--ID: 1706926586951-->
|
||||||
|
@ -62,7 +62,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707329732933-->
|
<!--ID: 1707329732933-->
|
||||||
|
@ -70,7 +70,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706926586955-->
|
<!--ID: 1706926586955-->
|
||||||
|
@ -78,7 +78,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706926586959-->
|
<!--ID: 1706926586959-->
|
||||||
|
@ -86,7 +86,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634779-->
|
<!--ID: 1707504634779-->
|
||||||
|
@ -109,7 +109,7 @@ void insertion_sort(const int n, int A[static n]) {
|
||||||
Basic
|
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707400559085-->
|
<!--ID: 1707400559085-->
|
||||||
END%%
|
END%%
|
||||||
|
@ -131,14 +131,14 @@ We prove $P$ maintains the requisite properties:
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
Given array `A[0..n-1]`, what is insertion sort's loop invariant?
|
Given array `A[0..n-1]`, what is `INSERTION_SORT`'s loop invariant?
|
||||||
Back: `A[0..i-1]` consists of the original `A[0..i-1]` elements but in sorted order.
|
Back: `A[0..i-1]` consists of the original `A[0..i-1]` elements but in sorted order.
|
||||||
<!--ID: 1707332638371-->
|
<!--ID: 1707332638371-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707332638373-->
|
<!--ID: 1707332638373-->
|
||||||
|
@ -146,7 +146,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707332638375-->
|
<!--ID: 1707332638375-->
|
||||||
|
@ -154,7 +154,7 @@ 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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708002185982-->
|
<!--ID: 1708002185982-->
|
||||||
END%%
|
END%%
|
||||||
|
@ -167,7 +167,7 @@ If you repeat this process for every card in the deck, your left hand will event
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706927594729-->
|
<!--ID: 1706927594729-->
|
||||||
|
@ -175,7 +175,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1706927594732-->
|
<!--ID: 1706927594732-->
|
||||||
|
@ -183,7 +183,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
How does insertion sort partition its input array?
|
How does `INSERTION_SORT` partition its input array?
|
||||||
Back:
|
Back:
|
||||||
```
|
```
|
||||||
[ sorted | unsorted ]
|
[ sorted | unsorted ]
|
||||||
|
@ -194,7 +194,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
How many comparisons does insertion sort typically perform with `x`?
|
How many comparisons does `INSERTION_SORT` typically perform with `x`?
|
||||||
```
|
```
|
||||||
[ sorted | x : unsorted ]
|
[ sorted | x : unsorted ]
|
||||||
```
|
```
|
||||||
|
@ -205,7 +205,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
Which element will insertion sort move to `sorted`?
|
Which element will `INSERTION_SORT` move to `sorted`?
|
||||||
```
|
```
|
||||||
[ sorted | unsorted ]
|
[ sorted | unsorted ]
|
||||||
```
|
```
|
||||||
|
|
|
@ -22,7 +22,7 @@ Adaptive | -
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467101-->
|
<!--ID: 1708742467101-->
|
||||||
|
@ -30,7 +30,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467109-->
|
<!--ID: 1708742467109-->
|
||||||
|
@ -38,7 +38,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467112-->
|
<!--ID: 1708742467112-->
|
||||||
|
@ -46,7 +46,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467115-->
|
<!--ID: 1708742467115-->
|
||||||
|
@ -54,7 +54,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467118-->
|
<!--ID: 1708742467118-->
|
||||||
|
@ -62,15 +62,15 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467121-->
|
<!--ID: 1708742467121-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467125-->
|
<!--ID: 1708742467125-->
|
||||||
|
@ -78,7 +78,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467133-->
|
<!--ID: 1708742467133-->
|
||||||
|
@ -128,7 +128,7 @@ void merge_sort(int i, int j, int *A) {
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467137-->
|
<!--ID: 1708742467137-->
|
||||||
|
@ -136,7 +136,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742467141-->
|
<!--ID: 1708742467141-->
|
||||||
|
@ -146,7 +146,7 @@ END%%
|
||||||
Basic
|
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708742590435-->
|
<!--ID: 1708742590435-->
|
||||||
END%%
|
END%%
|
||||||
|
|
|
@ -23,7 +23,7 @@ Adaptive | No
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707589393190-->
|
<!--ID: 1707589393190-->
|
||||||
|
@ -31,7 +31,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773323-->
|
<!--ID: 1707398773323-->
|
||||||
|
@ -39,7 +39,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773326-->
|
<!--ID: 1707398773326-->
|
||||||
|
@ -47,7 +47,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773327-->
|
<!--ID: 1707398773327-->
|
||||||
|
@ -55,7 +55,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773328-->
|
<!--ID: 1707398773328-->
|
||||||
|
@ -63,7 +63,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773330-->
|
<!--ID: 1707398773330-->
|
||||||
|
@ -71,7 +71,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707504634778-->
|
<!--ID: 1707504634778-->
|
||||||
|
@ -101,7 +101,7 @@ void selection_sort(const int n, int A[static n]) {
|
||||||
Basic
|
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707400943836-->
|
<!--ID: 1707400943836-->
|
||||||
END%%
|
END%%
|
||||||
|
@ -123,7 +123,7 @@ We prove $P$ maintains the requisite properties:
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773331-->
|
<!--ID: 1707398773331-->
|
||||||
|
@ -131,7 +131,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773333-->
|
<!--ID: 1707398773333-->
|
||||||
|
@ -139,7 +139,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1707398773334-->
|
<!--ID: 1707398773334-->
|
||||||
|
@ -147,7 +147,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
How does selection sort partition its input array?
|
How does `SELECTION_SORT` partition its input array?
|
||||||
Back:
|
Back:
|
||||||
```
|
```
|
||||||
[ sorted | unsorted ]
|
[ sorted | unsorted ]
|
||||||
|
@ -158,7 +158,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
Which element will selection sort move to `sorted`?
|
Which element will `SELECTION_SORT` move to `sorted`?
|
||||||
```
|
```
|
||||||
[ sorted | unsorted ]
|
[ sorted | unsorted ]
|
||||||
```
|
```
|
||||||
|
@ -169,7 +169,7 @@ 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*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
|
||||||
<!--ID: 1708002177782-->
|
<!--ID: 1708002177782-->
|
||||||
END%%
|
END%%
|
||||||
|
|
|
@ -13,29 +13,26 @@ A $k$-**combination** of $n$ objects is an unordered "choice" of $k$ objects fro
|
||||||
|
|
||||||
```c
|
```c
|
||||||
void combinations_aux(
|
void combinations_aux(
|
||||||
const int i, const int n,
|
const size_t n, int A[static n],
|
||||||
const int j, const int k,
|
const size_t k, int stack[static k],
|
||||||
int A[static n],
|
const size_t i
|
||||||
int res[static k]
|
|
||||||
) {
|
) {
|
||||||
if (j == k) {
|
if (n < k) {
|
||||||
for (int m = 0; m < k; ++m) {
|
|
||||||
printf("%d ", A[res[m]]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
return
|
|
||||||
} else if (n - i < k - j) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res[j] = A[i];
|
if (k == 0) {
|
||||||
combinations_aux(i + 1, n, j + 1, k, A, res);
|
print_array(i, stack);
|
||||||
combinations_aux(i + 1, n, j, k, A, res);
|
return;
|
||||||
|
}
|
||||||
|
stack[i] = A[0];
|
||||||
|
combinations_aux(n - 1, A + 1, k - 1, stack, i + 1);
|
||||||
|
combinations_aux(n - 1, A + 1, k, stack, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void combinations(const int n, const int k, int A[static n]) {
|
void combinations(const size_t n, const size_t k, int A[static n]) {
|
||||||
int *res = malloc(sizeof(int) * k);
|
int *stack = calloc(k, sizeof(int));
|
||||||
combinations_aux(0, n, 0, k, A, res);
|
combinations_aux(n, A, k, stack, 0);
|
||||||
free(res);
|
free(stack);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
Given finite sets $A$ and $B$, what is $|A \cup B \cup C|$?
|
Given finite sets $A$, $B$, and $C$, what is $|A \cup B \cup C|$?
|
||||||
Back: $|A| + |B| + |C| - |AB| - |AC| - |BC| + |ABC|$
|
Back: $|A| + |B| + |C| - |AB| - |AC| - |BC| + |ABC|$
|
||||||
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
|
||||||
<!--ID: 1708438356480-->
|
<!--ID: 1708438356480-->
|
||||||
|
|
|
@ -43,7 +43,7 @@ void permutations(const size_t n, int A[static n]) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The above approach prints out all permutations of an array.
|
The above approach prints out all permutations of an array (assuming distinct values).
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
|
@ -166,6 +166,250 @@ Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n
|
||||||
<!--ID: 1708366788613-->
|
<!--ID: 1708366788613-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
### Lexicographic Ordering
|
||||||
|
|
||||||
|
We can find the next lexicographic ordering of an array via a procedure of "pivot", "swap", and "reverse". The function `void next(const size_t n, int A[static n])` defined in [[#Overview]] shows the details, taking in a permutation and producing the next, lexicographically speaking. To prove correctness, consider the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aᵢ | aᵢ₊₁ aᵢ₊₂ ... aₙ ]
|
||||||
|
```
|
||||||
|
|
||||||
|
Here the RHS side is the longest increasing sequence we could find, from right to left. That is, $a_{i+1} > a_{i+2} > \cdots > a_n$. Denote $a_i$ as the pivot. Next, swap the smallest element in the RHS greater than $a_i$, say $a_j$, with $a_i$. This produces
|
||||||
|
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aⱼ | aᵢ₊₁ aᵢ₊₂ ... aᵢ ... aₙ ]
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice the RHS remains in sorted order. Since $a_j$ was the next smallest element, reversing the reverse-sorted RHS produces the next permutation, lexicographically speaking:
|
||||||
|
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aⱼ | aₙ ... aᵢ ... aᵢ₊₂ aᵢ₊₁ ]
|
||||||
|
```
|
||||||
|
|
||||||
|
Eventually the swapped $a_j$ will be the largest in the RHS ensuring that the breakpoint will eventually move one more position leftward.
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What algorithm does `NEXT_LEXICO_ARRAY` refer to?
|
||||||
|
Back: The finding of the next lexicographic ordering of an array.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610310-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What does array `A`'s next lexicographic ordering refer to?
|
||||||
|
Back: The permutation that follows `A` in a sorted list of all distinct permutations of `A`.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610316-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How does lexicographic ordering of arrays relate to permutations of an array?
|
||||||
|
Back: Each lexicographic ordering corresponds to a permutation.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610319-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: How many invocations guarantee all permutations of `A[1:n]`?
|
||||||
|
Back: $n!$
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610322-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: When does `< n!` iterations yield all permutations of `A[1:n]`?
|
||||||
|
Back: When `A` contains duplicates.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610326-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is `NEXT_LEXICO_ARRAY`'s worst-case running time?
|
||||||
|
Back: $O(n)$
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610329-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is `NEXT_LEXICO_ARRAY`'s best-case running time?
|
||||||
|
Back: $\Omega(n)$
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610332-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is `NEXT_LEXICO_ARRAY`'s auxiliary memory usage?
|
||||||
|
Back: $O(1)$
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610335-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the next lexicographic ordering of `[ 1 3 2 4 ]`?
|
||||||
|
Back: `[ 1 3 4 2 ]`
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610344-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the next lexicographic ordering of `[ 2 1 4 3 ]`?
|
||||||
|
Back: `[ 2 3 1 4 ]`
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610349-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the next lexicographic ordering of `[ 4 3 2 1 ]`?
|
||||||
|
Back: N/A
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610357-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the output of `NEXT_LEXICO_ARRAY([ 1 2 3 4 ])`?
|
||||||
|
Back: `[ 1 2 4 3 ]`
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610364-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the output of `NEXT_LEXICO_ARRAY([ 4 3 2 1 ])`?
|
||||||
|
Back: `[ 1 2 3 4 ]`
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610371-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: Which element will be the pivot of `[ 1 2 3 4 ]`?
|
||||||
|
Back: `3`
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610377-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: Which element will be the pivot of `[ 4 3 2 1 ]`?
|
||||||
|
Back: N/A
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756677668-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What property does the RHS of `A[1:n]` exhibit before swapping?
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aᵢ | aᵢ₊₁ aᵢ₊₂ ... aₙ ]
|
||||||
|
```
|
||||||
|
Back: Values are in decreasing order.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610384-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What property does the LHS of `A[1:n]` exhibit before swapping?
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aᵢ | aᵢ₊₁ aᵢ₊₂ ... aₙ ]
|
||||||
|
```
|
||||||
|
Back: N/A
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610393-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What property does the RHS of `A[1:n]` exhibit after swapping?
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aⱼ | aₙ ... aᵢ ... aᵢ₊₂ aᵢ₊₁ ]
|
||||||
|
```
|
||||||
|
Back: Values are in decreasing order.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610399-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What property does the LHS of `A[1:n]` exhibit after swapping?
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aⱼ | aₙ ... aᵢ ... aᵢ₊₂ aᵢ₊₁ ]
|
||||||
|
```
|
||||||
|
Back: N/A
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610403-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is the first step taken in the `NEXT_LEXICO_ARRAY` algorithm?
|
||||||
|
Back: Finding the pivot element.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610408-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What does the "pivot" refer to?
|
||||||
|
Back: The element preceding the longest increasing subarray from right-to-left.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610412-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Cloze
|
||||||
|
The `NEXT_LEXICO_ARRAY` algorithm can be summed up as "{pivot}", "{swap}", and "{reverse}".
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610416-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: *Which* element is swapped with the pivot?
|
||||||
|
Back: The smallest element to its right that is greater than it.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610421-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What is done after swapping the pivot element?
|
||||||
|
Back: Reverse the subarray to the right of where the pivot element was originally located.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610425-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What step follows swapping `A[1:n]`'s pivot element?
|
||||||
|
```
|
||||||
|
[ a₁ a₂ ... aⱼ | aₙ ... aᵢ ... aᵢ₊₂ aᵢ₊₁ ]
|
||||||
|
```
|
||||||
|
Back: Reverse the elements to the right of $a_j$.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610429-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
`NEXT_LEXICO_ARRAY`: What invariant is maintained after swapping the pivot?
|
||||||
|
Back: The elements to the right of the original pivot remain in non-increasing order.
|
||||||
|
Reference: [https://leetcode.com/problems/next-permutation/description/](https://leetcode.com/problems/next-permutation/description/)
|
||||||
|
<!--ID: 1709756610432-->
|
||||||
|
END%%
|
||||||
|
|
||||||
## Falling Factorials
|
## Falling Factorials
|
||||||
|
|
||||||
If we generalize to choosing $k \leq n$ elements of $k$ objects, we can calculate the $k$-permutation of $n$. This is denoted as $(n)_k$, sometimes called the **falling factorial**. $$(n)_k = \frac{n!}{(n - k)!}$$
|
If we generalize to choosing $k \leq n$ elements of $k$ objects, we can calculate the $k$-permutation of $n$. This is denoted as $(n)_k$, sometimes called the **falling factorial**. $$(n)_k = \frac{n!}{(n - k)!}$$
|
||||||
|
|
|
@ -549,7 +549,7 @@ END%%
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
Let $x$ be a $w$-bit two's-complement number. What is it's complement?
|
Let $x$ be a $w$-bit two's-complement number. What is it's complement?
|
||||||
Back: The number $y$ such that $x + y = 2^w$.
|
Back: $2^w - x$
|
||||||
Reference: “Two’s-Complement.” In *Wikipedia*, January 9, 2024. [https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561](https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561).
|
Reference: “Two’s-Complement.” In *Wikipedia*, January 9, 2024. [https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561](https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561).
|
||||||
<!--ID: 1709060837141-->
|
<!--ID: 1709060837141-->
|
||||||
END%%
|
END%%
|
||||||
|
@ -634,10 +634,11 @@ Reference: Finley, Thomas. “Two’s Complement,” April 2000. [https://www.cs
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Cloze
|
Basic
|
||||||
Subtracting $x$ from {a number of all `1` bits} is equivalent to {`~x`}.
|
Subtracting `x` from all `1` bits is equivalent to what bitwise operation?.
|
||||||
|
Back: `~x`
|
||||||
Reference: Finley, Thomas. “Two’s Complement,” April 2000. [https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html](https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html).
|
Reference: Finley, Thomas. “Two’s Complement,” April 2000. [https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html](https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html).
|
||||||
<!--ID: 1709061032778-->
|
<!--ID: 1709750498315-->
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
## Casting
|
## Casting
|
||||||
|
@ -964,7 +965,7 @@ END%%
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
What hardware-level advantage does two's-complement introduce over other signed encodings?
|
What hardware-level advantage does two's-complement introduce over other signed encodings?
|
||||||
Back: The same circuits can be used for unsigned and two's-complement addition.
|
Back: The same circuits can be used for unsigned and two's-complement arithmetic.
|
||||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
<!--ID: 1708799678732-->
|
<!--ID: 1708799678732-->
|
||||||
END%%
|
END%%
|
||||||
|
|
|
@ -239,7 +239,7 @@ END%%
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Basic
|
Basic
|
||||||
What distinguishes `abort()` from `exit()`?
|
What distinguishes `abort()` from `exit()`?
|
||||||
Back: The former sends a `SIGABRT` signal. The latter closes the application normally.
|
Back: The latter gracefully closes the application.
|
||||||
Reference: N/A
|
Reference: N/A
|
||||||
Tags: c17
|
Tags: c17
|
||||||
<!--ID: 1709131892349-->
|
<!--ID: 1709131892349-->
|
||||||
|
|
Loading…
Reference in New Issue