Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cheatsheets for CM1025 Fundamentals of Computer Science #23

Merged
merged 61 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
89f5747
init fabio-lama notes
lamafab Oct 25, 2022
6ef3967
start section on propositional logic and syntax
lamafab Oct 25, 2022
500a0ad
add translation on connectives section
lamafab Oct 25, 2022
040bd78
add truth tables section and operator precedence
lamafab Oct 25, 2022
f8cc7e5
reference stackexchange link for implication
lamafab Oct 26, 2022
b8a21d8
add chapter on tautology and consistency
lamafab Oct 26, 2022
00c2772
add first-order logic document
lamafab Oct 29, 2022
6d9ae3f
add section on Quantifiers to Connectives
lamafab Oct 29, 2022
16dd9ad
add chapter on proofs
lamafab Oct 29, 2022
3a90691
expand proof by contrapositive
lamafab Oct 29, 2022
6caaae1
fix typos, generate PDFs
lamafab Oct 29, 2022
342673f
update README
lamafab Oct 29, 2022
b089fa9
add section for Proof by Induction
lamafab Nov 2, 2022
f22c220
add example to Proof by Induction
lamafab Nov 2, 2022
420ada4
update PDF for proofs
lamafab Nov 2, 2022
cbab8ff
init Combinatorial Principles
lamafab Nov 12, 2022
e2b8bdc
update vocabulariy in implications
lamafab Nov 19, 2022
a473d8a
update propositional logic pdf
lamafab Nov 19, 2022
ff9dc7c
merge first order logic with propositional logic
lamafab Nov 19, 2022
4d6bf32
restruct sections slightly
lamafab Nov 19, 2022
89be26b
add Laws of Porpositional Logic
lamafab Nov 19, 2022
9f81993
complete laws of propositional logic
lamafab Nov 19, 2022
8ff63e5
merge files
lamafab Nov 19, 2022
809b6cf
reference Permutations & Combinatorics to CM notes
lamafab Nov 19, 2022
6dd9069
adjust sentence
lamafab Nov 19, 2022
7e29928
add De Morgans law for negation
lamafab Dec 3, 2022
f9973cd
rename files
lamafab Dec 3, 2022
4dd61bd
add intro to Automata theory
lamafab Dec 3, 2022
904f0b7
add section on Automaton
lamafab Dec 3, 2022
8d0afe6
add language of automaton
lamafab Dec 3, 2022
d0d4634
track assets
lamafab Dec 3, 2022
a08b787
update PDFs
lamafab Dec 3, 2022
1adacc0
update size and alignment of image
lamafab Dec 3, 2022
6bde0cf
add DFA and NFA section
lamafab Dec 3, 2022
5f5a05f
update chapter on determinism
lamafab Dec 23, 2022
6c0e0dd
update Automata pdf
lamafab Dec 23, 2022
a8affa4
init Formal Language doc
lamafab Dec 23, 2022
852b277
add section on concatenation and union
lamafab Dec 23, 2022
3901aea
add atomic expressions
lamafab Jan 2, 2023
31a4e44
update formal regular expressions and Pumping Lemma sections
lamafab Jan 2, 2023
2c28947
update README
lamafab Jan 2, 2023
b9367fb
delete deprecated doc
lamafab Jan 2, 2023
16e4b8f
add chapter on Context-Free Languages
lamafab Jan 12, 2023
3e9f1ad
add TODO in CFL
lamafab Jan 12, 2023
40166c9
add section on converting from regular expressions to CFL
lamafab Jan 21, 2023
bd57558
generate PDF for CFL cheatsheet
lamafab Jan 21, 2023
9e15ba5
update README
lamafab Jan 21, 2023
a453496
add chapter on Turing Machines
lamafab Jan 21, 2023
57d4d0a
update NOTE
lamafab Jan 21, 2023
44fc059
add example to Turing Machine chapter
lamafab Jan 21, 2023
8878101
expand languague of TM
lamafab Jan 21, 2023
5ef5e7d
generate PDF for TM
lamafab Jan 21, 2023
9653343
update README
lamafab Jan 21, 2023
23ca11b
update TM chapter
lamafab Jan 21, 2023
6bc4cd4
add chapter on recursion, add example
lamafab Feb 17, 2023
d22c70a
add section on Euclids algorithm
lamafab Feb 17, 2023
036c4c1
update README
lamafab Feb 17, 2023
40ed4a2
generate PDF for Recursion
lamafab Feb 17, 2023
e8c86fd
adjust sentencing in README
lamafab Feb 17, 2023
70cb494
init chapter on time complexity
lamafab Feb 17, 2023
c151ce8
remove complexity theory chapter, cleanup, regenerate all PDFs
lamafab Mar 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.**
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.

Loading