Skip to content

Commit 27fe20d

Browse files
authored
[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!
1 parent cd1ac5d commit 27fe20d

19 files changed

+1257
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# About
2+
3+
Listed here is a collection of cheatsheet by topic. Those cheatsheets do not
4+
explain the topics in depth, but rather serve as quick lookup documents.
5+
Therefore, the course material provided by the lecturer should still be studied
6+
and understood. Not everything that is tested at the mid-terms or final exams is
7+
covered and the Author does not guarantee that the cheatsheets are free of
8+
errors.
9+
10+
* [(First-order) Predicate & Propositional Logic](./cheatsheet_predicate_propositional_logic.pdf)
11+
* [Proofs](./cheatsheet_proofs.pdf)
12+
* [Permutations & Combinatorics](/level-4/computational-mathematics/student-notes/fabio-lama/cheatsheet_probability_combinatorics.pdf)
13+
* (covered in the Authors _Computational Mathematics_ module notes).
14+
* [Automata Theory](./cheatsheet_automata_theory.pdf)
15+
* [Formal Languages & Regular Expressions](./cheatsheet_formal_languages_regular_expressions.pdf)
16+
* [Context-Free Languages](./cheatsheet_context_free_languages.pdf)
17+
* [Turing Machines](./cheatsheet_turing_machines.pdf)
18+
* [Recursion](./cheatsheet_recursion.pdf)
19+
* NOTE: some topics discussed in the _Algorithms I/II_ weeks were
20+
skipped given that those were somewhat redundant with the _Algorithms and
21+
Data Structures I_ module. Some of the algorithms are worth it to be studied
22+
independently, however, such as the Gale-Shapely algorithm for stable
23+
matching, etc.
24+
* NOTE: Complexity theory is not covered by the cheatsheets.
25+
26+
# Building
27+
28+
_NOTE_: This step is only necessary if you chose to modify the base documents.
29+
30+
The base documents are written in [AsciiDoc](https://asciidoc.org/) and can be
31+
found in the `src/` directory.
32+
33+
The following dependencies must be installed (Ubuntu):
34+
35+
```console
36+
$ apt install -y ruby-dev wkhtmltopdf
37+
$ gem install asciidoctor
38+
$ chmod +x build.sh
39+
```
40+
41+
To build the documents (PDF version):
42+
43+
```console
44+
$ ./build.sh pdf
45+
```
46+
47+
Optionally, for the HTML version:
48+
49+
```console
50+
$ ./build.sh html
51+
```
52+
53+
and for the PNG version:
54+
55+
```console
56+
$ ./build.sh png
57+
```
58+
59+
The generated output can be deleted with `./build.sh clean`.
60+
61+
# Disclaimer
62+
63+
The Presented Documents ("cheatsheets") by the Author ("Fabio Lama") are
64+
summaries of specific topics. The term "cheatsheet" implies that the Presented
65+
Documents are intended to be used as learning aids or as references for
66+
practicing and does not imply that the Presented Documents should be used for
67+
inappropriate practices during exams such as cheating or other offenses.
68+
69+
The Presented Documents are heavily based on the learning material provided by
70+
the University of London, respectively the VLeBooks Collection database in the
71+
Online Library.
72+
73+
The Presented Documents may incorporate direct or indirect definitions,
74+
examples, descriptions, graphs, sentences and/or other content used in those
75+
provided materials. **At no point does the Author present the work or ideas
76+
incorporated in the Presented Documents as their own.**
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# Because `make` sucks.
4+
5+
gen_html() {
6+
# Remove suffix and prefix
7+
FILE=$1
8+
OUT=${FILE%.adoc}
9+
HTML_OUT="cheatsheet_${OUT}.html"
10+
11+
asciidoctor $FILE -o ${HTML_OUT}
12+
}
13+
14+
# Change directory to src/ in order to have images included correctly.
15+
cd "$(dirname "$0")/src/"
16+
17+
case $1 in
18+
html)
19+
for FILE in *.adoc
20+
do
21+
# Generate HTML file.
22+
gen_html ${FILE}
23+
done
24+
25+
# Move up from src/
26+
mv *.html ../
27+
;;
28+
pdf)
29+
for FILE in *.adoc
30+
do
31+
# Generate HTML file.
32+
gen_html ${FILE}
33+
34+
# Convert HTML to PNG.
35+
PDF_OUT="cheatsheet_${OUT}.pdf"
36+
wkhtmltopdf \
37+
--enable-local-file-access \
38+
--javascript-delay 2000\
39+
$HTML_OUT $PDF_OUT
40+
done
41+
42+
# Move up from src/
43+
mv *.pdf ../
44+
45+
# Cleanup temporarily generated HTML files.
46+
rm *.html > /dev/null 2>&1
47+
;;
48+
png | img)
49+
for FILE in *.adoc
50+
do
51+
# Generate HTML file.
52+
gen_html ${FILE}
53+
54+
# Convert HTML to PNG.
55+
IMG_OUT="cheatsheet_${OUT}.png"
56+
wkhtmltopdf \
57+
--enable-local-file-access \
58+
--javascript-delay 2000\
59+
$HTML_OUT $IMG_OUT
60+
done
61+
62+
# Move up from src/
63+
mv *.png ../
64+
65+
# Cleanup temporarily generated HTML files.
66+
rm *.html > /dev/null 2>&1
67+
;;
68+
clean)
69+
rm *.html > /dev/null 2>&1
70+
rm *.png > /dev/null 2>&1
71+
rm ../*.html > /dev/null 2>&1
72+
rm ../*.png > /dev/null 2>&1
73+
;;
74+
*)
75+
echo "Unrecognized command"
76+
;;
77+
esac
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
= Cheatsheet - Automata Theory
2+
Fabio Lama <fabio.lama@pm.me>
3+
:description: Module: CM1025 Fundamentals to Computer Science, started 25. October 2022
4+
:doctype: article
5+
:sectnums: 4
6+
:stem:
7+
8+
== Basics of (finite) Automata
9+
10+
An **alphabet**, stem:[Sigma], is a non-empty set of symbols.
11+
12+
[stem]
13+
++++
14+
Sigma = {0, 1} " binary alphabet"\
15+
Sigma = {a, b, ..., z} " collection of lowercase letters"
16+
++++
17+
18+
A **string** or word is a finite sequence of letters drawn from an alphabet.
19+
**Empty strings**, stem:[epsilon], are strings with zero occurrences of letters.
20+
Empty strings can be from any alphabet.
21+
22+
The **length** of a string stem:[x] is denoted as stem:[|x|]:
23+
24+
[stem]
25+
++++
26+
x = '"hello"'\
27+
|x| = 5
28+
++++
29+
30+
Other string related notations:
31+
32+
* The set of **all strings** composed from the letters in stem:[Sigma] is denoted
33+
by stem:[Sigma^**].
34+
* The set of **all non-empty strings** composed from letters
35+
in stem:[Sigma] is denoted by stem:[Sigma^+]
36+
* The set of **all strings of length stem:[k]** composed from letters in stem:[Sigma] is denoted by stem:[Sigma^k].
37+
38+
[stem]
39+
++++
40+
Sigma = {0, 1}\
41+
Sigma^** = {epsilon, 0, 1, 00, 01, 10, 11, ...}\
42+
Sigma^+ = {0, 1, 00, 01, 10, 11, ...}\
43+
Sigma^2 = {00, 01, 10, 11}
44+
++++
45+
46+
Note that the size of stem:[Sigma^k] is denoted as stem:[|Sigma|^k].
47+
48+
== Automaton
49+
50+
A **finite automaton** is a simple mathematical machine; it is a representation
51+
of how computations are performed with _limited memory_ space. It is a model of
52+
computation, which consists of a set of states that are connected by
53+
transitions. It has an input and it has an output.
54+
55+
An automaton stem:[M] is a 5-tuple (stem:[Q, Sigma, delta, q_0, F]) where:
56+
57+
* stem:[Q] is a finite set called the **states**.
58+
* stem:[Sigma] is a finite set called **the alphabet**.
59+
* stem:[delta: Q xx E -> Q] is the **transition function**.
60+
* stem:[q_0 in Q] is the **start state**.
61+
* stem:[F sube Q] is the set of **accepted states**.
62+
63+
.Note: Bottom right is the transition table. D is the only accepted state.
64+
image::assets/automaton_example.png[width=550, align="center"]
65+
66+
For example, based on the automaton in the picture above:
67+
68+
* Input stem:[0010] results in state stem:[D]; the input is **accepted** (stem:[D in F]).
69+
* Input stem:[0011] results in state stem:[A]; the input is **rejected**
70+
(stem:[A !in F]).
71+
72+
=== Language of Automaton
73+
74+
The set of all strings accepted by an automaton is called the **language** of
75+
that automaton. If stem:[M] is an automaton on alphabet stem:[Sigma], then
76+
stem:[cc L(M)] is the language of stem:[M]:
77+
78+
[stem]
79+
++++
80+
cc L(M) = {x in Sigma^** | M " accepts " x}
81+
++++
82+
83+
== Determinism
84+
85+
The difference between Deterministic Finite Automata (DFA) and Nondeterministic
86+
Finite Automata (NFA) is that DFA has exactly one transition and there is a
87+
unique starting state, which is not the case in NFA (hence,
88+
**nondeterministic**). Generally, in NFA there are many choices at one
89+
particular point and an input is accepted if at least one sequence of choices
90+
leads to an accepting state.
91+

0 commit comments

Comments
 (0)