From 464512dc386d2906bb68bad606b6748ca1f0959e Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Thu, 2 May 2024 13:23:10 -0600 Subject: [PATCH] ADTs, data structures, and additional notes on MOV instructions. --- .../plugins/obsidian-to-anki-plugin/data.json | 11 +- notes/_journal/2024-05-02.md | 5 +- notes/abstract-data-types/index.md | 46 +++++++ notes/abstract-data-types/priority-queues.md | 122 ++++++++++++++++++ notes/c17/declarations.md | 67 ++++++++++ .../{algorithms => data-structures}/heaps.md | 0 notes/data-structures/index.md | 37 ++++++ notes/x86-64/instructions.md | 17 +++ 8 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 notes/abstract-data-types/index.md create mode 100644 notes/abstract-data-types/priority-queues.md rename notes/{algorithms => data-structures}/heaps.md (100%) create mode 100644 notes/data-structures/index.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index 964e2c3..3bf4797 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -234,7 +234,7 @@ "c17/strings.md": "8f23005c9f8e25c72e2ac6b74b6afd7e", "c17/index.md": "78576ee41d0185df82c59999142f4edb", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500", - "c17/declarations.md": "7d45d1b415b66916dbb908f51d034b72", + "c17/declarations.md": "155c5472e56e87c54a563cfaaa1dbd7e", "algorithms/sorting/merge-sort.md": "6506483f7df6507cee0407bd205dbedd", "_journal/2024-02-24.md": "9bb319d5014caf962a9ce3141076cff4", "_journal/2024-02/2024-02-23.md": "0aad297148e8cc4058b48b7e45787ca7", @@ -318,7 +318,7 @@ "_journal/2024-03-22.md": "8da8cda07d3de74f7130981a05dce254", "_journal/2024-03/2024-03-21.md": "cd465f71800b080afa5c6bdc75bf9cd3", "x86-64/declarations.md": "75bc7857cf2207a40cd7f0ee056af2f2", - "x86-64/instructions.md": "d783bad8dd77748fb412715541cb844d", + "x86-64/instructions.md": "b34217258f8dd5a738fb3296d0ac744c", "git/refs.md": "954fc69004aa65b358ec5ce07c1435ce", "set/trees.md": "0d21b947917498f107da140cc9fb93a7", "_journal/2024-03-24.md": "1974cdb9fc42c3a8bebb8ac76d4b1fd6", @@ -394,7 +394,12 @@ "proofs/induction.md": "ab9e939efe32a4fb7ef2a0808eeb569f", "proofs/index.md": "51a7bc4e30b7a6cc0d4c5712ad603448", "_journal/2024-05-01.md": "959ff67fe3db585ba6a7b121d853bbac", - "_journal/2024-05-02.md": "962e63ca2f80179253aaf52e6b2aeaad" + "_journal/2024-05-02.md": "d7d6ba7e065d807986f0bd77281c0bb1", + "data-structures/priority-queues.md": "8c5c6bf62b1a39d8f1f72b800fcb17ff", + "data-structures/heaps.md": "0cba4acb7667dcab80fa4e7778e86cc8", + "data-structures/index.md": "2605977fad54956b5dc2d8dda9be2b10", + "abstract-data-types/priority-queues.md": "d3dad736cb05c47bdc93c52a3a4af083", + "abstract-data-types/index.md": "d07dd52473c7bfeb9eabdcc16f4c7e30" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-05-02.md b/notes/_journal/2024-05-02.md index 603a7b6..6e9e7bf 100644 --- a/notes/_journal/2024-05-02.md +++ b/notes/_journal/2024-05-02.md @@ -8,4 +8,7 @@ title: "2024-05-02" - [ ] Go (1 Life & Death Problem) - [ ] Korean (Read 1 Story) - [ ] Interview Prep (1 Practice Problem) -- [ ] Log Work Hours (Max 3 hours) \ No newline at end of file +- [ ] Log Work Hours (Max 3 hours) + +* Notes on priority queues and distinction between ADTs and data structures. +* Further notes on MOV instructions and C/x86 parallels. \ No newline at end of file diff --git a/notes/abstract-data-types/index.md b/notes/abstract-data-types/index.md new file mode 100644 index 0000000..e84420c --- /dev/null +++ b/notes/abstract-data-types/index.md @@ -0,0 +1,46 @@ +--- +title: ADTs +TARGET DECK: Obsidian::STEM +FILE TAGS: adt +tags: + - adt +--- + +## Overview + +An **abstract data type** (ADT) is a mathematical model for data types, defined in terms of its behavior (semantics). An ADT's implementation often takes the form of a [[data-structures/index|data structure]]. + +%%ANKI +Basic +What is an ADT an acronym for? +Back: **A**bstract **D**ata **T**type. +Reference: “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). + +END%% + +%%ANKI +Basic +What is an ADT (abstract data type)? +Back: A mathematical model for data types, defined in terms of its behavior. +Reference: “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). + +END%% + +%%ANKI +Cloze +An {1:ADT} is to an {2:ISA} as a {2:data structure} is to a {1:uarch}. +Reference: “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). + +END%% + +%%ANKI +Basic +What term describes the concrete implementation of an ADT? +Back: A data structure. +Reference: “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). + +END%% + +## Bibliography + +* “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). \ No newline at end of file diff --git a/notes/abstract-data-types/priority-queues.md b/notes/abstract-data-types/priority-queues.md new file mode 100644 index 0000000..6c53f17 --- /dev/null +++ b/notes/abstract-data-types/priority-queues.md @@ -0,0 +1,122 @@ +--- +title: Priority Queues +TARGET DECK: Obsidian::STEM +FILE TAGS: adt::priority_queue data_structure::heap +tags: + - adt + - heap + - priority_queue +--- + +## Overview + +A **priority queue** is a set that allows efficiently removing a maximum or minimum element. A max priority queue is usually implemented with a [[heaps|max-heap]] and a min priority queue is usually implemented with a [[heaps|min-heap]]. + +%%ANKI +Basic +What is a max-priority queue? +Back: A set that allows efficiently examining/extracting its maximum element. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +What is a min-priority queue? +Back: A set that allows efficiently examining/extracting its minimum element. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Priority queues are usually implemented with what data structure? +Back: Heaps. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +What are the two kinds of priority queues? +Back: Max-priority queues and min-priority queues. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Where is the maximum element of a heap-backed max-priority queue located? +Back: At the root. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Where is the minimum element of a heap-backed max-priority queue located? +Back: In one of the leaves. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +For a max-priority queue, what are the high-level steps of `MAX_HEAP_EXTRACT_MAX`? +Back: Swap the first and last elements, decrease the size, and heapify the new root. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +For a max-priority queue, what are the high-level steps of `MAX_HEAP_INSERT`? +Back: Increase the size, place element at the end, and repeatedly swap with parent until the max-heap property is fulfilled. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Where is the minimum element of a heap-backed min-priority queue located? +Back: At the root. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +Where is the maximum element of a heap-backed min-priority queue located? +Back: In one of the leaves. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +For a min-priority queue, what are the high-level steps of `MIN_HEAP_EXTRACT_MIN`? +Back: Swap the first and last elements, decrease the size, and heapify the new root. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +For a min-priority queue, what are the high-level steps of `MIN_HEAP_INSERT`? +Back: Increase the size, place element at the end, and repeatedly swap with parent until the min-heap property is fulfilled. +Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). + +END%% + +%%ANKI +Basic +What distinguishes priority queues from heaps? +Back: A priority queue is an ADT. A heap is a data structure. +Reference: “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). + +END%% + +## Bibliography + +* “Abstract Data Type.” In _Wikipedia_, March 18, 2024. [https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576](https://en.wikipedia.org/w/index.php?title=Abstract_data_type&oldid=1214359576). +* Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). \ No newline at end of file diff --git a/notes/c17/declarations.md b/notes/c17/declarations.md index 1f6221a..106950a 100644 --- a/notes/c17/declarations.md +++ b/notes/c17/declarations.md @@ -341,6 +341,73 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program END%% +%%ANKI +Basic +In what order does C cast size and "signedness"? +Back: C casts size then signedness. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +In what order does C cast "signedness" and size? +Back: C casts size then signedness. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Given `short sx`, cast `(unsigned) sx` is more explicitly written as what other sequence of casts? +Back: `(unsigned) (int) sx` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Given `short sx`, are the following two lines equivalent? +```c +(unsigned) sx +(unsigned) (int) sx +``` +Back: Yes. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Given `short sx`, are the following two lines equivalent? +```c +(unsigned) sx +(unsigned) (unsigned short) sx +``` +Back: No. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Given `short sx`, why is the following not an identity? +```c +(unsigned) sx = (unsigned) (unsigned short) sx +``` +Back: `(unsigned) sx` is equivalent to casting size before "signedness". +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What does "signedness" of a variable refer to? +Back: Whether the variable was declared `signed` or `unsigned`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + ## Pointers Pointers have the same size as the machine's word size since it should be able to refer to any virtual address. diff --git a/notes/algorithms/heaps.md b/notes/data-structures/heaps.md similarity index 100% rename from notes/algorithms/heaps.md rename to notes/data-structures/heaps.md diff --git a/notes/data-structures/index.md b/notes/data-structures/index.md new file mode 100644 index 0000000..60e07a8 --- /dev/null +++ b/notes/data-structures/index.md @@ -0,0 +1,37 @@ +--- +title: Data Structures +TARGET DECK: Obsidian::STEM +FILE TAGS: data_structure +tags: + - data_structure +--- + +## Overview + +A **data structure** is a collection of data values, the relationships among them, and the functions/operations that can be applied to the data. + +%%ANKI +Basic +What is a data structure? +Back: A collection of data values and the functions that can be applied to them. +Reference: “Data Structure.” In _Wikipedia_, April 13, 2024. [https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731](https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731). + +END%% + +%%ANKI +Cloze +A {data structure} serves as the basis of an {ADT}. +Reference: “Data Structure.” In _Wikipedia_, April 13, 2024. [https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731](https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731). + +END%% + +%%ANKI +Cloze +An {1:ADT} is to the {2:logical} whereas a {2:data structure} is to the {1:physical}. +Reference: “Data Structure.” In _Wikipedia_, April 13, 2024. [https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731](https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731). + +END%% + +## Bibliography + +* “Data Structure.” In _Wikipedia_, April 13, 2024. [https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731](https://en.wikipedia.org/w/index.php?title=Data_structure&oldid=1218671731). \ No newline at end of file diff --git a/notes/x86-64/instructions.md b/notes/x86-64/instructions.md index ea3316a..1337832 100644 --- a/notes/x86-64/instructions.md +++ b/notes/x86-64/instructions.md @@ -630,6 +630,23 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program END%% +%%ANKI +Cloze +A {pointer} in C is a {memory address} in x86. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + +%%ANKI +Basic +Dereferencing a pointer in C equates to what two operations in x86? +Back: Copying the pointer into a register and then using the register in a memory reference. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 + +END%% + ## Bibliography * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.