-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Cheatsheets for CM1025 Fundamentals of Computer Science (#23)
Fantastic! Thanks a lot for sharing all this knowledge with us in a useful format like this!
- Loading branch information
Showing
19 changed files
with
1,257 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
level-4/fundamentals-of-computer-science/student-notes/fabio-lama/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# About | ||
|
||
Listed here is a collection of cheatsheet by topic. Those cheatsheets do not | ||
explain the topics in depth, but rather serve as quick lookup documents. | ||
Therefore, the course material provided by the lecturer should still be studied | ||
and understood. Not everything that is tested at the mid-terms or final exams is | ||
covered and the Author does not guarantee that the cheatsheets are free of | ||
errors. | ||
|
||
* [(First-order) Predicate & Propositional Logic](./cheatsheet_predicate_propositional_logic.pdf) | ||
* [Proofs](./cheatsheet_proofs.pdf) | ||
* [Permutations & Combinatorics](/level-4/computational-mathematics/student-notes/fabio-lama/cheatsheet_probability_combinatorics.pdf) | ||
* (covered in the Authors _Computational Mathematics_ module notes). | ||
* [Automata Theory](./cheatsheet_automata_theory.pdf) | ||
* [Formal Languages & Regular Expressions](./cheatsheet_formal_languages_regular_expressions.pdf) | ||
* [Context-Free Languages](./cheatsheet_context_free_languages.pdf) | ||
* [Turing Machines](./cheatsheet_turing_machines.pdf) | ||
* [Recursion](./cheatsheet_recursion.pdf) | ||
* NOTE: some topics discussed in the _Algorithms I/II_ weeks were | ||
skipped given that those were somewhat redundant with the _Algorithms and | ||
Data Structures I_ module. Some of the algorithms are worth it to be studied | ||
independently, however, such as the Gale-Shapely algorithm for stable | ||
matching, etc. | ||
* NOTE: Complexity theory is not covered by the cheatsheets. | ||
|
||
# Building | ||
|
||
_NOTE_: This step is only necessary if you chose to modify the base documents. | ||
|
||
The base documents are written in [AsciiDoc](https://asciidoc.org/) and can be | ||
found in the `src/` directory. | ||
|
||
The following dependencies must be installed (Ubuntu): | ||
|
||
```console | ||
$ apt install -y ruby-dev wkhtmltopdf | ||
$ gem install asciidoctor | ||
$ chmod +x build.sh | ||
``` | ||
|
||
To build the documents (PDF version): | ||
|
||
```console | ||
$ ./build.sh pdf | ||
``` | ||
|
||
Optionally, for the HTML version: | ||
|
||
```console | ||
$ ./build.sh html | ||
``` | ||
|
||
and for the PNG version: | ||
|
||
```console | ||
$ ./build.sh png | ||
``` | ||
|
||
The generated output can be deleted with `./build.sh clean`. | ||
|
||
# Disclaimer | ||
|
||
The Presented Documents ("cheatsheets") by the Author ("Fabio Lama") are | ||
summaries of specific topics. The term "cheatsheet" implies that the Presented | ||
Documents are intended to be used as learning aids or as references for | ||
practicing and does not imply that the Presented Documents should be used for | ||
inappropriate practices during exams such as cheating or other offenses. | ||
|
||
The Presented Documents are heavily based on the learning material provided by | ||
the University of London, respectively the VLeBooks Collection database in the | ||
Online Library. | ||
|
||
The Presented Documents may incorporate direct or indirect definitions, | ||
examples, descriptions, graphs, sentences and/or other content used in those | ||
provided materials. **At no point does the Author present the work or ideas | ||
incorporated in the Presented Documents as their own.** |
77 changes: 77 additions & 0 deletions
77
level-4/fundamentals-of-computer-science/student-notes/fabio-lama/build.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/bash | ||
|
||
# Because `make` sucks. | ||
|
||
gen_html() { | ||
# Remove suffix and prefix | ||
FILE=$1 | ||
OUT=${FILE%.adoc} | ||
HTML_OUT="cheatsheet_${OUT}.html" | ||
|
||
asciidoctor $FILE -o ${HTML_OUT} | ||
} | ||
|
||
# Change directory to src/ in order to have images included correctly. | ||
cd "$(dirname "$0")/src/" | ||
|
||
case $1 in | ||
html) | ||
for FILE in *.adoc | ||
do | ||
# Generate HTML file. | ||
gen_html ${FILE} | ||
done | ||
|
||
# Move up from src/ | ||
mv *.html ../ | ||
;; | ||
pdf) | ||
for FILE in *.adoc | ||
do | ||
# Generate HTML file. | ||
gen_html ${FILE} | ||
|
||
# Convert HTML to PNG. | ||
PDF_OUT="cheatsheet_${OUT}.pdf" | ||
wkhtmltopdf \ | ||
--enable-local-file-access \ | ||
--javascript-delay 2000\ | ||
$HTML_OUT $PDF_OUT | ||
done | ||
|
||
# Move up from src/ | ||
mv *.pdf ../ | ||
|
||
# Cleanup temporarily generated HTML files. | ||
rm *.html > /dev/null 2>&1 | ||
;; | ||
png | img) | ||
for FILE in *.adoc | ||
do | ||
# Generate HTML file. | ||
gen_html ${FILE} | ||
|
||
# Convert HTML to PNG. | ||
IMG_OUT="cheatsheet_${OUT}.png" | ||
wkhtmltopdf \ | ||
--enable-local-file-access \ | ||
--javascript-delay 2000\ | ||
$HTML_OUT $IMG_OUT | ||
done | ||
|
||
# Move up from src/ | ||
mv *.png ../ | ||
|
||
# Cleanup temporarily generated HTML files. | ||
rm *.html > /dev/null 2>&1 | ||
;; | ||
clean) | ||
rm *.html > /dev/null 2>&1 | ||
rm *.png > /dev/null 2>&1 | ||
rm ../*.html > /dev/null 2>&1 | ||
rm ../*.png > /dev/null 2>&1 | ||
;; | ||
*) | ||
echo "Unrecognized command" | ||
;; | ||
esac |
Binary file added
BIN
+1.39 MB
.../fundamentals-of-computer-science/student-notes/fabio-lama/cheatsheet_automata_theory.pdf
Binary file not shown.
Binary file added
BIN
+1.72 MB
...entals-of-computer-science/student-notes/fabio-lama/cheatsheet_context_free_languages.pdf
Binary file not shown.
Binary file added
BIN
+1.74 MB
...uter-science/student-notes/fabio-lama/cheatsheet_formal_languages_regular_expressions.pdf
Binary file not shown.
Binary file added
BIN
+2.5 MB
...of-computer-science/student-notes/fabio-lama/cheatsheet_predicate_propositional_logic.pdf
Binary file not shown.
Binary file added
BIN
+1.49 MB
level-4/fundamentals-of-computer-science/student-notes/fabio-lama/cheatsheet_proofs.pdf
Binary file not shown.
Binary file added
BIN
+1.2 MB
level-4/fundamentals-of-computer-science/student-notes/fabio-lama/cheatsheet_recursion.pdf
Binary file not shown.
Binary file added
BIN
+1.98 MB
.../fundamentals-of-computer-science/student-notes/fabio-lama/cheatsheet_turing_machines.pdf
Binary file not shown.
Binary file added
BIN
+105 KB
...s-of-computer-science/student-notes/fabio-lama/src/assets/automaton_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+69 KB
...tals-of-computer-science/student-notes/fabio-lama/src/assets/turing_machine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+64 KB
...computer-science/student-notes/fabio-lama/src/assets/turing_machine_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions
91
...damentals-of-computer-science/student-notes/fabio-lama/src/automata_theory.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
= Cheatsheet - Automata Theory | ||
Fabio Lama <fabio.lama@pm.me> | ||
:description: Module: CM1025 Fundamentals to Computer Science, started 25. October 2022 | ||
:doctype: article | ||
:sectnums: 4 | ||
:stem: | ||
|
||
== Basics of (finite) Automata | ||
|
||
An **alphabet**, stem:[Sigma], is a non-empty set of symbols. | ||
|
||
[stem] | ||
++++ | ||
Sigma = {0, 1} " binary alphabet"\ | ||
Sigma = {a, b, ..., z} " collection of lowercase letters" | ||
++++ | ||
|
||
A **string** or word is a finite sequence of letters drawn from an alphabet. | ||
**Empty strings**, stem:[epsilon], are strings with zero occurrences of letters. | ||
Empty strings can be from any alphabet. | ||
|
||
The **length** of a string stem:[x] is denoted as stem:[|x|]: | ||
|
||
[stem] | ||
++++ | ||
x = '"hello"'\ | ||
|x| = 5 | ||
++++ | ||
|
||
Other string related notations: | ||
|
||
* The set of **all strings** composed from the letters in stem:[Sigma] is denoted | ||
by stem:[Sigma^**]. | ||
* The set of **all non-empty strings** composed from letters | ||
in stem:[Sigma] is denoted by stem:[Sigma^+] | ||
* The set of **all strings of length stem:[k]** composed from letters in stem:[Sigma] is denoted by stem:[Sigma^k]. | ||
|
||
[stem] | ||
++++ | ||
Sigma = {0, 1}\ | ||
Sigma^** = {epsilon, 0, 1, 00, 01, 10, 11, ...}\ | ||
Sigma^+ = {0, 1, 00, 01, 10, 11, ...}\ | ||
Sigma^2 = {00, 01, 10, 11} | ||
++++ | ||
|
||
Note that the size of stem:[Sigma^k] is denoted as stem:[|Sigma|^k]. | ||
|
||
== Automaton | ||
|
||
A **finite automaton** is a simple mathematical machine; it is a representation | ||
of how computations are performed with _limited memory_ space. It is a model of | ||
computation, which consists of a set of states that are connected by | ||
transitions. It has an input and it has an output. | ||
|
||
An automaton stem:[M] is a 5-tuple (stem:[Q, Sigma, delta, q_0, F]) where: | ||
|
||
* stem:[Q] is a finite set called the **states**. | ||
* stem:[Sigma] is a finite set called **the alphabet**. | ||
* stem:[delta: Q xx E -> Q] is the **transition function**. | ||
* stem:[q_0 in Q] is the **start state**. | ||
* stem:[F sube Q] is the set of **accepted states**. | ||
|
||
.Note: Bottom right is the transition table. D is the only accepted state. | ||
image::assets/automaton_example.png[width=550, align="center"] | ||
|
||
For example, based on the automaton in the picture above: | ||
|
||
* Input stem:[0010] results in state stem:[D]; the input is **accepted** (stem:[D in F]). | ||
* Input stem:[0011] results in state stem:[A]; the input is **rejected** | ||
(stem:[A !in F]). | ||
|
||
=== Language of Automaton | ||
|
||
The set of all strings accepted by an automaton is called the **language** of | ||
that automaton. If stem:[M] is an automaton on alphabet stem:[Sigma], then | ||
stem:[cc L(M)] is the language of stem:[M]: | ||
|
||
[stem] | ||
++++ | ||
cc L(M) = {x in Sigma^** | M " accepts " x} | ||
++++ | ||
|
||
== Determinism | ||
|
||
The difference between Deterministic Finite Automata (DFA) and Nondeterministic | ||
Finite Automata (NFA) is that DFA has exactly one transition and there is a | ||
unique starting state, which is not the case in NFA (hence, | ||
**nondeterministic**). Generally, in NFA there are many choices at one | ||
particular point and an input is accepted if at least one sequence of choices | ||
leads to an accepting state. | ||
|
Oops, something went wrong.