ADTs, data structures, and additional notes on MOV instructions.

c-declarations
Joshua Potter 2024-05-02 13:23:10 -06:00
parent fc098cdaf2
commit 464512dc38
8 changed files with 301 additions and 4 deletions

View File

@ -234,7 +234,7 @@
"c17/strings.md": "8f23005c9f8e25c72e2ac6b74b6afd7e", "c17/strings.md": "8f23005c9f8e25c72e2ac6b74b6afd7e",
"c17/index.md": "78576ee41d0185df82c59999142f4edb", "c17/index.md": "78576ee41d0185df82c59999142f4edb",
"c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500",
"c17/declarations.md": "7d45d1b415b66916dbb908f51d034b72", "c17/declarations.md": "155c5472e56e87c54a563cfaaa1dbd7e",
"algorithms/sorting/merge-sort.md": "6506483f7df6507cee0407bd205dbedd", "algorithms/sorting/merge-sort.md": "6506483f7df6507cee0407bd205dbedd",
"_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",
@ -318,7 +318,7 @@
"_journal/2024-03-22.md": "8da8cda07d3de74f7130981a05dce254", "_journal/2024-03-22.md": "8da8cda07d3de74f7130981a05dce254",
"_journal/2024-03/2024-03-21.md": "cd465f71800b080afa5c6bdc75bf9cd3", "_journal/2024-03/2024-03-21.md": "cd465f71800b080afa5c6bdc75bf9cd3",
"x86-64/declarations.md": "75bc7857cf2207a40cd7f0ee056af2f2", "x86-64/declarations.md": "75bc7857cf2207a40cd7f0ee056af2f2",
"x86-64/instructions.md": "d783bad8dd77748fb412715541cb844d", "x86-64/instructions.md": "b34217258f8dd5a738fb3296d0ac744c",
"git/refs.md": "954fc69004aa65b358ec5ce07c1435ce", "git/refs.md": "954fc69004aa65b358ec5ce07c1435ce",
"set/trees.md": "0d21b947917498f107da140cc9fb93a7", "set/trees.md": "0d21b947917498f107da140cc9fb93a7",
"_journal/2024-03-24.md": "1974cdb9fc42c3a8bebb8ac76d4b1fd6", "_journal/2024-03-24.md": "1974cdb9fc42c3a8bebb8ac76d4b1fd6",
@ -394,7 +394,12 @@
"proofs/induction.md": "ab9e939efe32a4fb7ef2a0808eeb569f", "proofs/induction.md": "ab9e939efe32a4fb7ef2a0808eeb569f",
"proofs/index.md": "51a7bc4e30b7a6cc0d4c5712ad603448", "proofs/index.md": "51a7bc4e30b7a6cc0d4c5712ad603448",
"_journal/2024-05-01.md": "959ff67fe3db585ba6a7b121d853bbac", "_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": { "fields_dict": {
"Basic": [ "Basic": [

View File

@ -9,3 +9,6 @@ title: "2024-05-02"
- [ ] Korean (Read 1 Story) - [ ] Korean (Read 1 Story)
- [ ] Interview Prep (1 Practice Problem) - [ ] Interview Prep (1 Practice Problem)
- [ ] Log Work Hours (Max 3 hours) - [ ] 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.

View File

@ -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).
<!--ID: 1714669011569-->
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).
<!--ID: 1714669011571-->
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).
<!--ID: 1714669011572-->
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).
<!--ID: 1714677608770-->
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).

View File

@ -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).
<!--ID: 1714664647320-->
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).
<!--ID: 1714664647326-->
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).
<!--ID: 1714664647322-->
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).
<!--ID: 1714664647324-->
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).
<!--ID: 1714666339569-->
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).
<!--ID: 1714666339572-->
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).
<!--ID: 1714666339573-->
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).
<!--ID: 1714666339575-->
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).
<!--ID: 1714666339576-->
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).
<!--ID: 1714666339578-->
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).
<!--ID: 1714666339579-->
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).
<!--ID: 1714666339581-->
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).
<!--ID: 1714669011566-->
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).

View File

@ -341,6 +341,73 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1708631820856--> <!--ID: 1708631820856-->
END%% 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.
<!--ID: 1714677608760-->
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.
<!--ID: 1714677626482-->
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.
<!--ID: 1714677608762-->
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.
<!--ID: 1714677608764-->
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.
<!--ID: 1714677608766-->
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.
<!--ID: 1714677608767-->
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.
<!--ID: 1714677608769-->
END%%
## Pointers ## Pointers
Pointers have the same size as the machine's word size since it should be able to refer to any virtual address. Pointers have the same size as the machine's word size since it should be able to refer to any virtual address.

View File

@ -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).
<!--ID: 1714669011575-->
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).
<!--ID: 1714669011577-->
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).
<!--ID: 1714669011579-->
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).

View File

@ -630,6 +630,23 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1713625933491--> <!--ID: 1713625933491-->
END%% 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
<!--ID: 1714677608754-->
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
<!--ID: 1714677608758-->
END%%
## Bibliography ## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.