diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/README.md b/level-4/discrete-mathematics/student-notes/fabio-lama/README.md new file mode 100644 index 00000000..d1ae64ac --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/README.md @@ -0,0 +1,78 @@ +# 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. + +* [Set Theory](./cheatsheet_set_theory.pdf) +* [Universal Set, Complement and Laws](./cheatsheet_universal_set_complement_laws.pdf) +* [Functions](./cheatsheet_functions.pdf) +* [Propositional & First-order Logic](/level-4/fundamentals-of-computer-science/student-notes/fabio-lama/cheatsheet_propositional_logic.pdf) + * (covered in the Authors _Fundamentals of Computer Science_ module notes) +* [Postulates of Boolean Algebra](./cheatsheet_postulates_boolean_algebra.pdf) +* [Logic Gates](./cheatsheet_logic_gates.pdf) +* [Proofs](/level-4/fundamentals-of-computer-science/student-notes/fabio-lama/cheatsheet_proofs.pdf) + * (covered in the Authors _Fundamentals of Computer Science_ module notes) +* [Graph Theory](./cheatsheet_graphs.pdf) +* [Graph Theory: Isomorphism](./cheatsheet_graphs_isomorphism.pdf) +* [Trees](./cheatsheet_trees.pdf) +* [Relations](./cheatsheet_relations.pdf) +* [Equivalence Relations & Classes](./cheatsheet_equivalence.pdf) +* [Combinatorics](/level-4/computational-mathematics/student-notes/fabio-lama/cheatsheet_probability_combinatorics.pdf) + * (covered in the Authors _Computational Mathematics_ module notes) +* [Binomial Coefficients & Identities](./cheatsheet_binomial_coefficients.pdf) + +# 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 and the material provided on the Coursera platform. + +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.** diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/build.sh b/level-4/discrete-mathematics/student-notes/fabio-lama/build.sh new file mode 100755 index 00000000..d3987601 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/build.sh @@ -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 PDF. + 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 \ No newline at end of file diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_binomial_coefficients.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_binomial_coefficients.pdf new file mode 100644 index 00000000..3cf5175a Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_binomial_coefficients.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_equivalence.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_equivalence.pdf new file mode 100644 index 00000000..3c02a235 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_equivalence.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_functions.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_functions.pdf new file mode 100644 index 00000000..72bcfe2f Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_functions.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_graphs.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_graphs.pdf new file mode 100644 index 00000000..8fb0e426 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_graphs.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_graphs_isomorphism.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_graphs_isomorphism.pdf new file mode 100644 index 00000000..eefa5f98 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_graphs_isomorphism.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_logic_gates.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_logic_gates.pdf new file mode 100644 index 00000000..3f7da976 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_logic_gates.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_postulates_boolean_algebra.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_postulates_boolean_algebra.pdf new file mode 100644 index 00000000..513c47ee Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_postulates_boolean_algebra.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_relations.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_relations.pdf new file mode 100644 index 00000000..b740993f Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_relations.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_set_theory.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_set_theory.pdf new file mode 100644 index 00000000..54fb8911 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_set_theory.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_trees.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_trees.pdf new file mode 100644 index 00000000..f112cab6 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_trees.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_universal_set_complement_laws.pdf b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_universal_set_complement_laws.pdf new file mode 100644 index 00000000..56ae22c9 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/cheatsheet_universal_set_complement_laws.pdf differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/circuit.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/circuit.png new file mode 100644 index 00000000..31b23877 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/circuit.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/full_adder.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/full_adder.png new file mode 100644 index 00000000..63ba8c77 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/full_adder.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/adjacency_list.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/adjacency_list.png new file mode 100644 index 00000000..af48bdf1 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/adjacency_list.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/adjacency_matrix.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/adjacency_matrix.png new file mode 100644 index 00000000..ce310434 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/adjacency_matrix.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/bipartite_graphs.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/bipartite_graphs.png new file mode 100644 index 00000000..ea2d5796 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/bipartite_graphs.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_in_out_vertex.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_in_out_vertex.png new file mode 100644 index 00000000..f06c2246 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_in_out_vertex.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_sequence.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_sequence.png new file mode 100644 index 00000000..677dad32 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_sequence.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_vertex.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_vertex.png new file mode 100644 index 00000000..c625e6ba Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/degree_vertex.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/edge.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/edge.png new file mode 100644 index 00000000..c2eaf7e4 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/edge.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_circuit.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_circuit.png new file mode 100644 index 00000000..0d39ff69 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_circuit.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_complete.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_complete.png new file mode 100644 index 00000000..60989be8 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_complete.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_complete_example.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_complete_example.png new file mode 100644 index 00000000..6af39849 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_complete_example.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_connectivity.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_connectivity.png new file mode 100644 index 00000000..43dc13a8 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_connectivity.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_cycle.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_cycle.png new file mode 100644 index 00000000..165a021f Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_cycle.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_euler_path.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_euler_path.png new file mode 100644 index 00000000..347eb6f0 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_euler_path.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_1.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_1.png new file mode 100644 index 00000000..6430d57f Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_1.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_2.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_2.png new file mode 100644 index 00000000..11b52573 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_2.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_3.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_3.png new file mode 100644 index 00000000..bf22b72e Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_example_3.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_hamiltonian_cycle.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_hamiltonian_cycle.png new file mode 100644 index 00000000..71a87673 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_hamiltonian_cycle.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_regular_cycles.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_regular_cycles.png new file mode 100644 index 00000000..98000571 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_regular_cycles.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_strong_connectivity.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_strong_connectivity.png new file mode 100644 index 00000000..14f13afb Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_strong_connectivity.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_trail.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_trail.png new file mode 100644 index 00000000..00f8fadc Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_trail.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_transitive_closure.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_transitive_closure.png new file mode 100644 index 00000000..2546a558 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_transitive_closure.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_walk.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_walk.png new file mode 100644 index 00000000..10261d08 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/graph_walk.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/isomorphic_graphs.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/isomorphic_graphs.png new file mode 100644 index 00000000..645f12b5 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/isomorphic_graphs.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/isomorphic_graphs_example.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/isomorphic_graphs_example.png new file mode 100644 index 00000000..01de9aa5 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/isomorphic_graphs_example.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/regular_graphs.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/regular_graphs.png new file mode 100644 index 00000000..20f2d91e Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/regular_graphs.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/regular_graphs_example.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/regular_graphs_example.png new file mode 100644 index 00000000..cf7d8332 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/regular_graphs_example.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/simple_graphs.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/simple_graphs.png new file mode 100644 index 00000000..dfeb39df Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/simple_graphs.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/vertex.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/vertex.png new file mode 100644 index 00000000..041db5f4 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/graphs/vertex.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/half_adder.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/half_adder.png new file mode 100644 index 00000000..0507508b Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/half_adder.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/injective_surjective_bijective.jpeg b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/injective_surjective_bijective.jpeg new file mode 100644 index 00000000..d88c62ff Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/injective_surjective_bijective.jpeg differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/injective_surjective_bijective.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/injective_surjective_bijective.png new file mode 100644 index 00000000..6d6c282d Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/injective_surjective_bijective.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/logic_gates.jpg b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/logic_gates.jpg new file mode 100644 index 00000000..a2650fe3 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/logic_gates.jpg differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/pascals_triangle.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/pascals_triangle.png new file mode 100644 index 00000000..c558ec7c Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/pascals_triangle.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/relation_digraph.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/relation_digraph.png new file mode 100644 index 00000000..92d08d24 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/relation_digraph.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/relation_digraph_2.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/relation_digraph_2.png new file mode 100644 index 00000000..5abbb685 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/relation_digraph_2.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/set_operations.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/set_operations.png new file mode 100644 index 00000000..b7f78071 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/set_operations.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/acyclic_graphs.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/acyclic_graphs.png new file mode 100644 index 00000000..90eb6238 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/acyclic_graphs.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/acyclic_graphs_trees.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/acyclic_graphs_trees.png new file mode 100644 index 00000000..9dee814c Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/acyclic_graphs_trees.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_1.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_1.png new file mode 100644 index 00000000..859ffa6a Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_1.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_2.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_2.png new file mode 100644 index 00000000..453a794b Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_2.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_3.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_3.png new file mode 100644 index 00000000..854a1201 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_3.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_4.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_4.png new file mode 100644 index 00000000..4341e3d3 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_4.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_5.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_5.png new file mode 100644 index 00000000..0a155cc2 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_search_example_5.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_tree.png new file mode 100644 index 00000000..d5e101ca Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/binary_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/directed_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/directed_tree.png new file mode 100644 index 00000000..4e578101 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/directed_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/forest.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/forest.png new file mode 100644 index 00000000..24a05369 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/forest.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/isomorphic_example.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/isomorphic_example.png new file mode 100644 index 00000000..b8e6bdd9 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/isomorphic_example.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/isomorphic_trees.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/isomorphic_trees.png new file mode 100644 index 00000000..28208489 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/isomorphic_trees.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/m_ary_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/m_ary_tree.png new file mode 100644 index 00000000..0fb64f77 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/m_ary_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/minimum_cost_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/minimum_cost_tree.png new file mode 100644 index 00000000..5a4187f6 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/minimum_cost_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/regular_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/regular_tree.png new file mode 100644 index 00000000..ca484281 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/regular_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/rooted_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/rooted_tree.png new file mode 100644 index 00000000..58e7c6fa Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/rooted_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/spanning_trees.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/spanning_trees.png new file mode 100644 index 00000000..5ef6fda9 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/spanning_trees.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/special_trees.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/special_trees.png new file mode 100644 index 00000000..d48e46f2 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/special_trees.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/sub_graphs.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/sub_graphs.png new file mode 100644 index 00000000..3e034048 Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/sub_graphs.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/terminology_tree.png b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/terminology_tree.png new file mode 100644 index 00000000..36b23a4e Binary files /dev/null and b/level-4/discrete-mathematics/student-notes/fabio-lama/src/assets/trees/terminology_tree.png differ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/binomial_coefficients.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/binomial_coefficients.adoc new file mode 100644 index 00000000..1386ba0b --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/binomial_coefficients.adoc @@ -0,0 +1,74 @@ += Cheatsheet - Binomial Coefficients & Identities +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Binomial Theorem + +An expression consisting of two terms, connected by a stem:[+] or stem:[-] sign, +is called a **binomial expression**. As we increase the power of binomials, +expanding them becomes more and more complicated: + +[stem] +++++ +(x+y)^1 = x + y\ +(x+y)^2 = x^2 + 2xy + y^2\ +(x+y)^3 = x^3 + 3x^2y + 3xy^2 + y^3\ +... +++++ + +The **binomial theorem** helps us to simplify this expansion. Let stem:[x] and +stem:[y] be variables, and stem:[n] a non-negative integer. The expansion of +stem:[(x+y)^n] can be formalized as: + +[stem] +++++ +(x+y)^n = sum_(k=0)^n ((n),(k)) x^k y^(n-k) +++++ + +The **binomial coefficients** are the coefficients in the binomial theorem and +denoted as: + +[stem] +++++ +((n),(k)) = (n!)/(k!(n-k)!) +++++ + +Here we say **"n choose k"**. + +For example: + +> What is the coefficient of stem:[x^8 y^7] in the expansion of stem:[(3x +-y)^15]. + +We can view the expression as stem:[(3x+ (-y))^15]. By the binomial theorem: + +[stem] +++++ +(3x+ (-y))^15 = sum_(k=0)^15 ((15),(k)) (3x)^k (-y)^(15-k) +++++ + +The coefficient of stem:[x^8 y^7] in the expansion is obtained when stem:[k=8]: + +[stem] +++++ +((15),(8)) (3)^8 (-1)^7 = -3^8 (15!)/(8!7!) +++++ + +=== Pascal's Identity + +If stem:[n] and stem:[k] are integers with stem:[n >= k >= 1], then: + +[stem] +++++ +((n),(k)) + ((n),(k-1)) = ((n+1),(k)) +++++ + +=== Pascal's Triangle + +**Pascals' triangle** is a number triangle with numbers arranged in staggered rows +such that **stem:[a_(n,r)] is the binomial coefficient stem:[((n),(r))]**. + +image::./assets/pascals_triangle.png[align=center, width=600] \ No newline at end of file diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/equivalence.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/equivalence.adoc new file mode 100644 index 00000000..d11f2687 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/equivalence.adoc @@ -0,0 +1,61 @@ += Cheatsheet - Equivalence Relations & Classes +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +NOTE: You should read the cheatsheet on _Relations_, too. + +== Definitions + +=== Equivalence Relation + +Let stem:[R] be a relation of elements on set stem:[S]. stem:[R] is an +**equivalence relation** if and only if stem:[R] is **reflexive**, **symmetric** +and **transitive**. + +=== Equivalence Classes + +Let stem:[R] be an **equivalence relation** on a set stem:[S]. Then, the +**equivalence class** of stem:[a in S] is the **subset** of stem:[S] containing +all the **elements related** to stem:[a] through stem:[R]: + +[stem] +++++ +[a] = {x: x in S " and " xRa} +++++ + +For example: + +[stem] +++++ +S = {1, 2, 3, 4, 5}\ +R = {(a, b) in S^2 | a - b " is an even number" } +++++ + +The set stem:[R] has two equivalence classes: + +[stem] +++++ +[1] = [3] = [5] = {1, 3, 5}\ +[2] = [4] = {2, 4} +++++ + +== Partial & Total Order + +Let stem:[R] be a relation on elements in a set stem:[S]. stem:[R] is a +**partial order** if and only if stem:[R] is **reflexive**, **anti-symmetric** +and **transitive**. + +Additionally, stem:[R] is a **total** order if and only if: + +* stem:[R] is a **partial order**. +* stem:[AA (a, b) in S] we have **either** stem:[aRb] **or** stem:[bRa]. + +For example, the following relation is a total order: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a <= b} +++++ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/functions.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/functions.adoc new file mode 100644 index 00000000..a4d28225 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/functions.adoc @@ -0,0 +1,270 @@ += Cheatsheet - Functions +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Intro + +A function maps one element from a set to **exactly one** element of another (or +the same) set. + +For example, we have sets: + +[stem] +++++ +A = {1, 2, 3}\ +B = {2, 4, 6, 7, 8} +++++ + +and the function: + +[stem] +++++ +f: A -> B +++++ + +defined as: + +[stem] +++++ +f(x) = 2x +++++ + +Now lets apply each element from stem:[A] to stem:[f]: + +[stem] +++++ +f(1) = 2\ +f(2) = 4\ +f(3) = 6 +++++ + +We call set stem:[A] the **domain** and set stem:[B] the **co-domain**. The set +of all possible values when mapping elements from set stem:[A] to set stem:[B], +respectively set stem:[R = {2, 4, 6}], is called the **range**. Hence stem:[R +sube B]. + +Additionally, we say that stem:[1] is the **pre-image** of stem:[2], which in +return is the **image** of stem:[1]. The element stem:[2] is the pre-image of +stem:[4], which in return is the image of stem:[2]. And so on. + +== Injective, Surjective & Bijective Functions + +.Source: https://twitter.com/JDHamkins/status/841318019397779456 +image::assets/injective_surjective_bijective.jpeg[] + +* **General function**: stem:[A] has at most one stem:[B] (not injective, not surjective). +* **Injective**: stem:[A] has exactly one stem:[B] (not surjective). +* **Surjective**: _Each and every_ stem:[B] has one or many stem:[A] (not +injective). +* **Bijective**: _Each and every_ stem:[B] has exactly one stem:[A] (injective +and surjective). +* **NOT a function**: stem:[A] has many stem:[B]. + +=== Proofs + +We can prove whether a function is injective, surjective or bijective by solving +an equation. Lets use the following function as an example: + +[stem] +++++ +f(x) = 2x + 3 +++++ + +Injective Proof:: + +Let stem:[a, b in R], show that if stem:[a != b] then stem:[f(a) != f(b)]: + +[stem] +++++ +a != b " " xx 2\ +2a != 2b " " + 3\ +2a + 3 != 2b + 3\ +=> f(a) != f(b) +++++ + +**Or:** Let stem:[a, b in R], show that if stem:[f(a) = f(b)] then stem:[a = b]: + +[stem] +++++ +f(a) = f(b) =>\ +2a + 3 = 2b + 3 " " -3\ +2a = 2b " " -: 2\ +a = b +++++ + +Hence, function stem:[f] is injective. + +Surjective Proof:: + +Let stem:[y in R], show that there exists stem:[x in R] such that stem:[f(x) = y]: + +[stem] +++++ +f(x) = y =>\ +2x + 3 = y " " -3\ +2x = y -3 " " -: 2\ +x = (y -3)/2 +++++ + +Hence, function stem:[f] is surjective. + +== Composition + +Function composition means we apply one function to the result of another. + +For example: + +[stem] +++++ +(f @ g)(x) = f(g(x)) +++++ + +which means that the result of stem:[g()] is passed on to stem:[f()]. If we +define stem:[f(x) = 2x] and stem:[g(x) = x^2], then: + +[stem] +++++ +(f @ g)(5) = f(g(x)) = 2xx(5^2) = 50 +++++ + +Do note that function composition is not commutative, meaning stem:[f @ g != g +@ f]: + +[stem] +++++ +(f @ g)(5) = f(g(x)) = 2xx(5^2) = 50\ +(g @ f)(5) = g(f(x)) = (5xx2)^2 = 100 +++++ + +== Inverse Function + +If function stem:[f] is bijective, then there exists an inverse function +stem:[f^(-1)]. + +[stem] +++++ +f: A -> B\ +f^(-1): B -> A +++++ + +For example, given stem:[f(x) = 2x], then stem:[f^(-1)(x) = x/2]. + +[stem] +++++ +f(2) = 4\ +f^(-1)(4) = 2 +++++ + +Additionally: + +[stem] +++++ +(f @ f^(-1))(x) = (f^(-1) @ f)(x) = x +++++ + +== Exponential Functions + +Properties of exponential the function: + +[stem] +++++ +y = f(x) = b^x " " (b > 0 " and " b != 1) +++++ + +* The domain is stem:[(-oo, oo)] +* The range is stem:[(0, oo)] +* It passes through the point stem:[(0, 1)] +* If stem:[b > 1] then it's increasing on stem:[(-oo, oo)] ("exponential growth") +* If stem:[b < 1] then it's decreasing on stem:[(-oo, oo)] ("exponential decay") + + +== Logarithmic Functions + +The logarithmic function with base stem:[b] where stem:[b > 0] and stem:[b != 1] +is defined as: + +[stem] +++++ +log_b x = y " if and only if " x = b^y +++++ + +Respectively: + +[stem] +++++ +x = b^y hArr log_b(x) = y +++++ + +For example: + +[stem] +++++ +81 = 3^4 hArr log_3(81) = 4 +++++ + +=== Laws + +[stem] +++++ +log_b (m xx n) = log_b m + log_b n\ +log_b (m/n) = log_b m - log_b n\ +log_b (m^n) = n xx log_b (m)\ +log_b (1) = 0\ +log_b (b) = 1 +++++ + +Conventionally, we also define **natural logarithms** as: + +[stem] +++++ +log = log_(10)\ +ln = log_e +++++ + +Where stem:[e] is the +https://en.wikipedia.org/wiki/E_(mathematical_constant)["Euler number"] +(stem:[e = 2.71828]). + +== Floor and Ceiling Functions + +We define the **floor** of the real number stem:[x] as (round **down** to the +previous integer **or equal**): + +[stem] +++++ +x = 3.6\ +|__x__| = 3 +++++ + +We define the **ceiling** of real number stem:[x] as (round **up** to the next +integer **or equal**): + +[stem] +++++ +x = 3.6\ +|~x~| = 4 +++++ + +Additionally (equal): + +[stem] +++++ +y = 5\ +|__y__| = 5\ +|~y~| = 5 +++++ + +and (negative numbers) + +[stem] +++++ +x = -3.5\ +|__x__| = -4\ +|~x~| = -3 +++++ + +Both the floor and the ceiling function convert a real number to an integer, +respectively stem:[RR -> ZZ]. diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/graphs.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/graphs.adoc new file mode 100644 index 00000000..0b1321e0 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/graphs.adoc @@ -0,0 +1,217 @@ += Cheatsheet - Graphs +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Intro + +Graphs are **discrete** structures consisting of **vertices (nodes)** and +**edges** connecting them. Graph theory is an area of discrete mathematics which +studies these types of discrete structures. + +The **graph** stem:[G] can be represented as an ordered pair stem:[G = (V, E)], +where stem:[V] is a set of nodes/vertices and stem:[E] is a set of edges, lines +or connections. A **vertex** (singular of "vertices") is a basic element of a graph, +usually drawn as a node or a dot. The set of vertices of stem:[G] is usually +denoted by stem:[V(G)] or stem:[V]. + +image::./assets/graphs/vertex.png[align=center, width=250] + +An **edge** is a link between 2 vertices, usually drawn as a line connecting two +vertices. The set of edges in a graph stem:[G] is usually denoted by stem:[E(G)] +or stem:[E]. + +image::./assets/graphs/edge.png[align=center, width=500] + +Two vertices are said to be **adjacent** if they are endpoints of the same edge. +Two edges are said to be **adjacent** if they share the same vertex. If a vertex +stem:[v] is an endpoint of an edge stem:[e], then we say that stem:[e] and +stem:[v] are **incident**. + +A **directed graph**, also called a **digraph**, is a graph in which the edges +have a direction. This is usually indicated with an arrow on the edge. + +=== Examples + +image::./assets/graphs/graph_example_1.png[align=center, width=500] + +image::./assets/graphs/graph_example_2.png[align=center, width=500] + +And an example of a directed graph: + +image::./assets/graphs/graph_example_3.png[align=center, width=500] + +== Concepts + +=== Walk + +A **walk** is a sequence of vertices and edges of a graph were vertices and +edges can be repeated. A **walk of length k** in a graph is a succession of +stem:[k] (not necessarily different) edges of the form stem:[uv, vw, wx, ..., +yz]. + +image::./assets/graphs/graph_walk.png[align=center, width=600] + +=== Trail + +A **trail** is a walk in which no edge is repeated. In a trail, vertices can be +repeated but no edge is ever repeated. For example, stem:[e1, e2, e3, e5, e6] +is a trail: + +image::./assets/graphs/graph_trail.png[align=center, width=350] + +=== Circuit + +A **circuit** is a closed trail. Circuits can have repeated vertices only. For +example, stem:[e7,e6, e8, e3, e2, e1] is a circuit: + +image::./assets/graphs/graph_circuit.png[align=center, width=350] + +=== Path + +A **path** is a trail in which neither vertices nor edges are repeated. + +=== Cycle + +A **cycle** is a closed path, consisting of edges and vertices where a vertex is +reachable from itself. + +image::./assets/graphs/graph_cycle.png[align=center, width=500] + +=== Eulerian Path + +A **Eulerian path** in a graph is a path that uses each edge precisely once. If +such a path exists, the graph is called **traversable**. + +image::./assets/graphs/graph_euler_path.png[align=center, width=550] + +=== Hamiltonian Path, Cycle & Graph + +A **Hamiltonian path** (also called a _traceable path_) is a path that visits +each vertex exactly once. A **Hamiltonian cycle** is a cycle that visits each +vertex exactly once (except for the starting vertex, which is visited once at +the start and once again at the end). + +image::./assets/graphs/graph_hamiltonian_cycle.png[align=center, width=450] + +A graph that contains a Hamiltonian cycle is called a **Hamiltonian graph**. Any +Hamiltonian cycle can be converted to a Hamiltonian path by removing one of its +edges. + +=== Connectivity + +An **undirected** graph is **connected** if you can get from **any node to any other** +by following a **sequence of edges**. Or, **any two nodes** are **connected** by a path. + +image::./assets/graphs/graph_connectivity.png[align=center, width=350] + +A directed graph is **strongly connected** if there is a **directed path** from +any node to any other node. + +image::./assets/graphs/graph_strong_connectivity.png[align=center, width=400] + +=== Transitive Close + +Given a digraph stem:[G], the transitive closure of stem:[G] is the digraph +stem:[G^**] such that stem:[G^**] has the same vertices as stem:[G]. If +stem:[G] has a directed path from stem:[u] to stem:[v] (stem:[u != v]), +stem:[G^**] has a directed edge from stem:[u] to stem:[v]. + +image::./assets/graphs/graph_transitive_closure.png[align=center, width=650] + +== Degree of a Vertex + +The degree of a vertex is the number of edges incident on stem:[v]. A loop +contributes **twice** to the degree. An **isolated vertex** has a degree of +stem:[0]. + +image::./assets/graphs/degree_vertex.png[align=center, width=400] + +In the case of directed graphs, stem:["In-deg"(v)] is the number of edges for +which stem:[v] is the terminal vertex. stem:["Out-deg"(v)] is the number of +edges for which stem:[v] is the initial vertex. + +And the degree stem:["deg"(v)] is: + +[stem] +++++ +"deg"(v) = "Out-deg"(v) + "In-deg"(v) +++++ + +A loop contributes **twice** to the degree as it contributes stem:[1] to both +in-degree and out-degree. + +image::./assets/graphs/degree_in_out_vertex.png[align=center, width=400] + +=== Degree Sequence + +Given an undirected graph stem:[G], a **degree sequence** is a **monotonic +non-increasing** sequence of the vertex degrees of all the vertices of stem:[G]. +The **sum of the degree sequence** of a graph is always **even**. + +image::./assets/graphs/degree_sequence.png[align=center, width=450] + +Given a graph stem:[G], the sum of the degree sequence of stem:[G] is twice the +number of edges in stem:[G]. + +[stem] +++++ +"Number of edges of "G = ("sum of degree sequences of " G)/2 +++++ + +== Special Graphs + +=== Simple Graphs + +A **simple graph** is a graph without **loops** and **parallel** edges. + +image::./assets/graphs/simple_graphs.png[align=center, width=500] + +Given a **simple** graph stem:[G] with stem:[n] vertices, then the degree of +each vertex of stem:[G] is at most equal to stem:[n-1]. + +=== Regular Graphs + +A graph is said to be **regular** of degree if all local degrees are the same +number. A graph stem:[G] where all the vertices are of the same degree, +stem:[r], is called an **r-regular** graph. + +image::./assets/graphs/regular_graphs.png[align=center, width=550] + +Given a **r-regular** graph stem:[G] with stem:[n] vertices, then the following +is true: + +[stem] +++++ +"Degree sequence of " G = r, r, r, ..., r " " (n " times")\ +"Sum of degree sequence of " G = r xx n\ +"Number of edges in " G = r xx n/2 +++++ + +image::./assets/graphs/regular_graphs_example.png[align=center, width=350] + +=== Special Regular Graphs: Cycles + +image::./assets/graphs/graph_regular_cycles.png[align=center, width=350] + +=== Complete Graphs + +A **complete graph** is a **simple** graph where **every pair of vertices** are +**adjacent** (linked with an edge). We represent a complete graph with stem:[n] +vertices using the symbol stem:[K_n]. + +image::./assets/graphs/graph_complete.png[align=center, width=450] + +A complete graph with stem:[n] vertices, stem:[k_n], has the following +properties: + +[stem] +++++ +"Every vertex has a degree " (n-1)\ +"Sum of degree sequence" = n(n-1)\ +"Number of edges" = (n(n-1))/n +++++ + +image::./assets/graphs/graph_complete_example.png[align=center, width=350] diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/graphs_isomorphism.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/graphs_isomorphism.adoc new file mode 100644 index 00000000..c26dcaa4 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/graphs_isomorphism.adoc @@ -0,0 +1,54 @@ += Cheatsheet - Graphs: Isomorphism +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Definition + +Two graphs stem:[G_1] and stem:[G_2] are isomorphic if there is a bijection +(invertible function) stem:[f: G_1 -> G_2] that preserves adjacency and +non-adjacency. Given two vertices stem:[u] and stem:[v], if stem:[u xx v] is in +stem:[E(G_1)] then stem:[f(u) xx f(v)] is in stem:[E(G_2)]. + +image::./assets/graphs/isomorphic_graphs.png[align=center, width=600] + +Two graphs with different degree sequences **cannot be isomorphic**. Two graphs +with the same degree sequence **are not necessarily isomorphic**. + +image::./assets/graphs/isomorphic_graphs_example.png[align=center, width=300] + +== Bipartite Graph + +A graph stem:[G(V,E)] is called a bi-partite graph if the set of vertices +stem:[V] can be partitioned in two non-empty disjoint sets stem:[V_1] and +stem:[V_2] in such a way that each edge stem:[e] in stem:[G] has one endpoint in +stem:[V_1] and another endpoint in stem:[V_2]. + +image::./assets/graphs/bipartite_graphs.png[align=center, width=400] + +=== Matching + +A **matching** is a set of pairwise non-adjacent edges, none of which are loops. +That is, no two edges share a common endpoint. A vertex is matched (or +saturated) if it is an endpoint of one of the edges in the matching. Otherwise +the vertex is unmatched. + +A **maximum** matching is a matching of maximum size such that if any edge is +added, it is no longer a matching. The **Hopcroft-Karp algorithm** is commonly +used for solving the maximum matching problem in a bipartite graph +(_the algorithm is not specified in this cheatsheet_). + +== Adjacency Matrix of Graph + +The adjacency list of a graph stem:[G] is a list of all the vertices in stem:[G] +and their corresponding individual adjacent vertices. + +image::./assets/graphs/adjacency_list.png[align=center, width=400] + +A graph can also be represented by its **adjacency matrix**. The number of edges +in an **undirected** graph is equal to half the sum of all the elements +(stem:[m_(ij)]) of it's corresponding adjacency matrix. + +image::./assets/graphs/adjacency_matrix.png[align=center, width=550] diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/logic_gates.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/logic_gates.adoc new file mode 100644 index 00000000..b9de3720 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/logic_gates.adoc @@ -0,0 +1,102 @@ += Cheatsheet - Logic Gates +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Intro + +(NOTE: Reading the _Postulates of Boolean Algebra_ cheatsheet is recommended here) + +Logic gates are basic elements of circuits implementing Boolean operations. The +most basic circuits are **OR** gates, **AND** gates and invertors (**NOT** +gates). All boolean functions can be written in terms of these three logic +operations. + +* **AND** operation is represented as stem:[f = x . y] or stem:[f = xy]. +* **OR** operation is represented as stem:[f = x + y]. +* **NOT** operation is represented as stem:[f = bar x]. + +Other gates: + +* **XOR** operation is _true_ only when the value of the inputs differ. +* **NAND** operations is equivalent to "not AND". +* **NOR** operation is equivalent to "not OR". +* **XNOR** operation is equivalent to a "not XOR". + +AND, OR, XOR and XNOR are **commutative** (e.g. stem:[a + b = b + a]) and +**associative** (e.g. stem:[a + (b + c) = (a + b) + c]). NAND and NOR are +commutative but not associative. + +.Source: http://www.exclusivearchitecture.com/?page_id=2425 +image::assets/logic_gates.jpg[align=center, width=600] + +== Circuits + +We describe the combination of logic gates as a **circuit**. + +image::assets/circuit.png[align=center, width=450] + +A circuit that's used for the **addition** of inputs is called an **adder**. A +**half adder** takes two inputs and generates a **carry** and a **sum**. A +**full adder** takes three inputs and generates a carry and a sum. + +For example, an **half adder**: + +[stem] +++++ +"sum" = xy' + x'y = x o+ y\ +"carry" = xy +++++ + +image::assets/half_adder.png[align=center, width=200] + +And a **full adder**: + +[stem] +++++ +"sum" = x o+ y " carry in"\ +"carry out" = xy + "carry in" . (x o+ y) +++++ + +image::assets/full_adder.png[align=center, width=400] + +=== Simplification of Circuits (example) + +Let's consider the following boolean expression: + +[stem] +++++ +E = ((xy)'z)'((x' + z)(y' + z'))' +++++ + +Using the **De Morgan's laws** and **involution**: + +[stem] +++++ +E = ((xy)'' + z')((x' + z)' + (y' + z')')\ += (xy + z')((x'' . z') + y'' . z'')\ += (xy + z')(xz' + yz) +++++ + +Using the **distributive laws**: + +[stem] +++++ +E = xyxz' + xyyz + z'xz' + z'yz +++++ + +Using **commutative, idempotent** and **complement** laws: + +[stem] +++++ +E = xyz' + xyz + xz' + 0 +++++ + +Using **absorption** law: + +[stem] +++++ +E = xyz + xz' +++++ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/postulates_boolean_algebra.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/postulates_boolean_algebra.adoc new file mode 100644 index 00000000..8640c1ea --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/postulates_boolean_algebra.adoc @@ -0,0 +1,155 @@ += Cheatsheet - Postulates of Boolean Algebra +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Intro + +Boolean algebra describes the field of study where the values of variables are +_true_ or _false_. The following operators are used: + +* **AND**: represented as stem:[x.y, x nn y] or stem:[x ^^ y] +* **OR**: represented as stem:[x + y, x uu y] or stem:[x vv y] +* **NOT**: represented as stem:[x', bar x] or stem:[not x] + +Order of precedence: stem:["NOT" > "AND" > "OR"] + +== Axioms + +The following axioms must be satisfied by any boolean algebra: + +* **closure**: any result of logical operations belongs to the set stem:[{0, 1}] +(_true_ or _false_). +* **identity**: elements have an identity for the applied operator: + ** stem:[x + 0 = x] + ** stem:[x . 1 = x] +* **commutativity**: the order of the applied operators does not matter. + ** stem:[x + y = y + x] + ** stem:[x . y = y . x] +* **distributivity**: + ** stem:[x(y + z) = (x . y) + (x . z)] + ** stem:[x + (y . z) = (x + y) . (x + z)] +* **complements**: exist for all the elements + ** stem:[x + x' = 1] + ** stem:[x. x' = 0] +* **distinct elements**: + ** stem:[0 != 1] + +=== Basic Theorems + +Based on those axioms, we can establish basic theorems: + +Theorem 1: Idempotent Laws + +[stem] +++++ +x + x = x\ +x. x = x +++++ + +Theorem 2: Tautology and Contradiction + +[stem] +++++ +x + 1 = 1\ +x . 0 = 0 +++++ + +Theorem 3: Involution + +[stem] +++++ +(x')' = x +++++ + +Theorem 4: Associative Laws + +[stem] +++++ +(x + y) + z = x + (y + x)\ +(x . y) . z = x . (y . z) +++++ + +Theorem 5: Absorption Laws + +[stem] +++++ +x + (x . y) = x\ +x . (x + y) = x +++++ + +Theorem 6: Uniqueness of Complement + +[stem] +++++ +"if " y + x = 1 " and " y . x = 0, " then " x = y' +++++ + +Theorem 7: Inversion Law + +[stem] +++++ +0' = 1, 1' = 0 +++++ + +=== De Morgans' Theorems + +[stem] +++++ +bar (x.y) = bar x + bar y\ +bar (x + y)= bar x . bar y +++++ + +=== Principles of Duality + +Starting with a boolean relation, we can build another equivalent boolean +relation by: + +* changing each stem:["OR"(+)] to an stem:["AND"(.)] +* changing each stem:["AND"(.)] to an stem:["OR"(+)] +* changing each _0_ to _1_ and each _1_ to _0_. + +For example: + +[stem] +++++ +(a . 1) . (0 + bar a) = 0\ +-=\ +(a + 0) + (1 . bar a) = 1 +++++ + +== Boolean Functions + +=== Standardized Forms of a Functions + +The two most common standardized forms are **sum-of-products** and +**product-of-sums**. + +The **sum-of-products form**: stem:[f(x, y, z) = xy + xz + yz] +The **product-of-sums form**: stem:[f(x, y, z) = (x + y)(x + z)(y + z)] + +For example: + +[stem] +++++ +f(x, y) = x'y + xy' + xy +++++ + +=== Useful Functions + +The **exclusive-or** function: + +[stem] +++++ +x o+ y = x'y + xy' +++++ + +The **implies** function: + +[stem] +++++ +x -> y = x' + y +++++ + diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/relations.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/relations.adoc new file mode 100644 index 00000000..e593f377 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/relations.adoc @@ -0,0 +1,294 @@ += Cheatsheet - Relations +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Intro + +**Relations** between **elements** of sets occur in many contexts. In +mathematics, we study relationships such as: + +* a relation between a **positive integer** and one that it **divides**. +* a relation between a **real number** and **one** that is **larger** than it. +* a relation between a **real number** stem:[x] and the **value f (stem:[x])** +where stem:[f] is a function, and so on. + +== Definition + +A relation can be defined between elements of a set stem:[A] and elements of +another set stem:[B]. It can also be defined between elements of the same set. +We always use the letter stem:[R] to refer to a relation. + +For example, we say that stem:[x] **is related** to stem:[y] with respect to the +relation stem:[R] and we write: + +[stem] +++++ +x R y " where " x in A, y in B +++++ + +NOTE: Relations are **defined arbitrarily**. + +=== Cartesian Product & Binary Relation + +The **Cartesian product** stem:[A xx B] is defined by a **set of pairs** +stem:[(x,y)] such that stem:[x in A] and stem:[y in B]. + +[stem] +++++ +A xx B = {(x,y): x in A " and " y in B} +++++ + +For example: + +[stem] +++++ +A = {a_1, a_2} " and " B = {b_1, b_2, b_3}\ +A xx B = {(a_1, b_1), (a_1, b_2), (a_1, b_3), (a_2, b_1), (a_2, b_2), (a_2, b_3)} +++++ + +Note that: + +[stem] +++++ +A xx A = A^2 +++++ + +A **binary relation** from stem:[A] to stem:[B] is a **subset** of a **Cartesian +product** stem:[A xx B]: + +[stem] +++++ +R sube A xx B +++++ + +which means that stem:[R] is a set of ordered pairs of the form stem:[(x, y)] +where stem:[x in A] and stem:[y in B]. + +[stem] +++++ +(x, y) in R " means " x R y " (... is related to ...)" +++++ + +==== Relation on a Set + +When stem:[A = B], a relation stem:[R] **on the set stem:[A]** is a relation +from stem:[A] to stem:[A]: + +[stem] +++++ +R sube A xx A +++++ + +For example: + +[stem] +++++ +A = {1, 2, 3, 4}\ +R = {x, y in A, xRy | "if and only if " x < y}\ +"We have " 1R2, 1R3, 1R4, 2R3, 2R4, 3R4 " respectively:"\ +R = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)} +++++ + +== Representation + +=== Matrices + +Given a **relation** stem:[R] from a set stem:[A] to set stem:[B]. We can list +the elements of sets stem:[A] and stem:[B] in a particular order. + +Let stem:[n_a = |A|] and stem:[n_b = |B|]. The **matrix of stem:[R]** is stem:[n_a xx n_b]: + +[stem] +++++ +M_r = [m_(ij)] n_a xx n_b\ +m_(ij) = {(1 " if " (a_i, bj) in R),(0 " if " (a_i, bj) !in R):} +++++ + +Example: + +[stem] +++++ +A = {a, b, c}\ +B = {1, 2, 3}\ +R = {(a, 1), (a, 2), (b, 2), (b, 3), (c, 1), (c, 3)}\ +M_r = [[1, 1, 0],[0, 1, 1],[1, 0, 1]] +++++ + +==== Combining Relations + +The **union** of two relations is a new set that contains all of the pairs of +elements that are in at least one of the two relations. The union is written as +stem:[R uu S] or **"R or S"**. + +[stem] +++++ +R uu S = {(a, b): (a, b) in R " or " (a, b) in S} +++++ + +The **intersection** of two relations is a new set that contains all of the +pairs that are in both sets. The intersection is written as stem:[R nn S] or **"R +and S"**. + +[stem] +++++ +R nn S = {(a, b): (a, b) in R " and " (a, b) in S} +++++ + +For example, given: + +[stem] +++++ +M_R = [[1, 0, 1],[1, 0, 0],[0, 1, 0]] " " M_S = [[1, 0, 1],[0, 1, 1],[1, 0, 0]] +++++ + +To **join** (union): + +[stem] +++++ +M_(R uu S) = M_R vv M_S = [[1, 0, 1],[1, 1, 1],[1, 1, 0]] +++++ + +To **meet** (intersection): + +[stem] +++++ +M_(R nn S) = M_R ^^ M_S = [[1, 0, 1],[0, 0, 0],[0, 0, 0]] +++++ + +=== Graphs + +When a relation is defined on a set, it can be represented by a digraph. First, +the elements of stem:[A] are written down, then stem:[(a, b) in R] arrows are +drawn from stem:[a] to stem:[b]. + +For example: + +[stem] +++++ +A = {1, 2, 3, 4, 5}\ +R = {x, y in A, xRy | "if and only if " x <= y} +++++ + +Then the graph is: + +image::./assets/relation_digraph.png[align=center, width=250] + +And if (_strictly less_): + +[stem] +++++ +R = {x, y in A, xRy | "if and only if " x < y} +++++ + +Then the graph is: + +image::./assets/relation_digraph_2.png[align=center, width=250] + +== Properties + +=== Reflexivity + +A relation stem:[R] in a set stem:[S] is said to be **reflexive** if and only +if: + +[stem] +++++ +x R x, AA x in S\ +-=\ +(x, x) in R, AA x in S +++++ + +For example, the following is reflexive: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a <= b}\ +1 <= 1 " "("i.e. " a <= a)\ +1 <= 2\ +... +++++ + +While this example is **not** reflexive: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a < b}\ +1 < 2\ +"but not " 1 < 1 " " ("i.e. " a < a)\ +... +++++ + +=== Symmetry + +A relation stem:[R] on a set stem:[S] is said to be **symmetric** if and only +if: + +[stem] +++++ +AA (a, b) in S, " if " aRb " then " bRa +++++ + +For example, the following is symmetric: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a + b = b + a}\ +1 + 2 = 2 + 1\ +2 + 1 = 1 + 2\ +... +++++ + +While this example is **not** symmetric: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a <= b}\ +1 <= 2\ +" but not " 2 <= 1\ +... +++++ + +=== Anti-Symmetry + +NOTE: The symmetric and anti-symmetric properties are not necessarily mutually +exclusive, meaning a relation can be both. + +A relation stem:[R] on a set stem:[S] is said to be **anti-symmetric** if and +only if: + +[stem] +++++ +AA (a, b) in S, " if " (aRb " and " bRa) " then " a = b +++++ + +For example, the following is anti-symmetric: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a <= b}\ +1 <= 1 " and " 1 <=1\ +"implies " 1 = 1\ +... +++++ + +=== Transitivity + +A relation stem:[R] on set stem:[S] is called **transitive** if and only if: + +[stem] +++++ +AA (a, b, c) in S, " if " (aRb " and " bRc) " then " aRc +++++ + +For example, the following is transitive: + +[stem] +++++ +R = {(a, b) in ZZ^2 | a <= b }\ +2 <= 3 " and " 3 <= 4\ +"implies " 2 <= 4\ +... +++++ diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/set_theory.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/set_theory.adoc new file mode 100644 index 00000000..dbef2d22 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/set_theory.adoc @@ -0,0 +1,282 @@ += Cheatsheet - Set Theory +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Definition + +A set refers to an **unordered** collection of any kind of (abstract) **unique** +objects, so called "elements", such as numbers, figures, things, etc. + +=== Basic Notation + +We have the set stem:[E] containing four elements: + +[stem] +++++ +E = {1, 2, 3, 4} +++++ + +or set stem:[V]: + +[stem] +++++ +V = {a, b, c, d, e, f} +++++ + +We can see that the element stem:[2] _is in_ stem:[E], respectively: + +[stem] +++++ +2 in E +++++ + +but _not in_ stem:[V] + +[stem] +++++ +2 !in V +++++ + +== Cardinality + +Given the set stem:[S], the **cardinality** of stem:[S] is the number of +elements contained in stem:[S]. We write the cardinality of stem:[S] as +stem:[|S|]. + +[stem] +++++ +S = {a, b, c}\ +|S| = 3 +++++ + +and the following **empty** set: + +[stem] +++++ +S = O/ = {}\ +|S| = 0 +++++ + +== Subset and Superset + +We have set stem:[E] and stem:[{1, 2}] is a **subset** (stem:[sube]) of stem:[E]. +We can also say that stem:[E] is a **superset** (stem:[supe]) of stem:[{1, 2}]. +The set stem:[{a, b}] is **not** a subset (latexmath:[\not \subseteq]) of stem:[E], +however. + +[latexmath] +++++ +E = \{1, 2, 3, 4\}\\ +E \subseteq E\\ +E \supseteq E\\ +\{1, 2\} \subseteq E\\ +E \supseteq \{1, 2\}\\ +\{a, b\} \not \subseteq E\\ +E \not \supseteq \{a, b\}\\ +E \not \supseteq \{1, 2, 3, 4, 5\} +++++ + +Importantly, we distinguish between a subset (stem:[sube]) and a **proper +subset** (stem:[sub]): + +[latexmath] +++++ +\{1, 2, 3\} \subset E\\ +\{1, 2, 3, 4\} \not \subset E\\ +\{1, 2, 3, 4\} \subseteq E +++++ + +Do note that any set also contains an empty subset: + +[stem] +++++ +({} = O/) sube E +++++ + +== Special Sets + +Commonly defined and used sets in mathematics: + +[stem] +++++ +NN = {1, 2, 3, 4, ...} " natural numbers"\ +bbb W = {0, 1, 2, 3, ...} " whole numbers"\ +ZZ = {..., -1, 0, 1, 2, ...} " integers (no fractions)"\ +QQ = {..., -1, -(1/2), 0, 2/3, 1, ...} " rational numbers"\ +RR = " real numbers (non complex-numbers)" +++++ + +Note that infinite numbers are _irrational numbers_ and are not part of +stem:[QQ], such as stem:[pi !in QQ]. + +Additionally: + +[stem] +++++ +NN sub ZZ sub QQ sub RR +++++ + +== Set Builder + +We define: + +[stem] +++++ +E = {1, 2, 3, 4} +++++ + +and use the set builder to create a new set, for example: + +[stem] +++++ +V = {2n | n in E}\ +V = {2, 4, 6, 8} +++++ + +Read as "each element set stem:[V] is two times stem:[n] for each stem:[n] in +set stem:[E]". + +We now define the set stem:[J]: + +[stem] +++++ +J = {2n | n in E " and " n < 3}\ +J = {2, 4} +++++ + +== Powerset + +Given a set stem:[S], the powerset of that set is denoted as stem:[P(S)] and +contains all subsets of stem:[S]: + +[stem] +++++ +S = {a, b}\ +P(S) = {O/, {a}, {b}, {a, b}} +++++ + +since + +[stem] +++++ +O/ sube S\ +{a} sube S\ +{b} sube S\ +{a, b} sube S +++++ + +=== Cardinality of a powerset + +We define: + +[stem] +++++ +|P(S)| = 2^(|S|) +++++ + +For example: + +[stem] +++++ +S = {1, 2, 3}\ +|S| = 3\ +P(S) = {O/, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}\ +|P(S)| = 2^3 = 8 +++++ + +== Set Operations + +.Venn Diagram, source: https://www.embibe.com/exams/set-theoretic-approach/ +image::assets/set_operations.png[width=400, align="center"] + +=== Union + +Given two sets stem:[A] and stem:[B], the union of stem:[A] and stem:[B], +stem:[A uu B], contains all the element in **either** stem:[A] and stem:[B]. + +[stem] +++++ +A uu B = {x | x in A " or " x in B} +++++ + +For example: + +[stem] +++++ +A = {1, 2, 3}\ +B = {4, 5, 6}\ +A uu B = {1, 2, 3, 4, 5, 6} +++++ + +and + +[stem] +++++ +A = {1, 2, 3}\ +C = {2, 3, 4}\ +A uu C = {1, 2, 3, 4} +++++ + +=== Intersection + +Given two sets stem:[A] and stem:[B], the intersection of stem:[A] and stem:[B], +stem:[A nn B], contains all the elements in both stem:[A] **and** stem:[B]. + +[stem] +++++ +A nn B = {x | x in A " and " x in B} +++++ + +For example: + +[stem] +++++ +A = {1, 2, 3}\ +B = {2, 3, 4}\ +A nn B = {2, 3} +++++ + +=== Set Difference + +Given two sets stem:[A] and stem:[B], the set difference, stem:[A - B], contains +the elements that are in stem:[A] but not in stem:[B]. + +[stem] +++++ +A - B = {x | x in A " and " x !in B} +++++ + +For example: + +[stem] +++++ +A = {1, 2, 3}\ +B = {2, 3, 4}\ +A - B = {1} +++++ + +NOTE: stem:[A - B = A \\ B] + +=== Symmetric Difference + +Given two sets stem:[A] and stem:[B], the symmetric difference, stem:[A o+ B], +contains the elements that are in stem:[A] or in stem:[B] but **not in both**. + +[stem] +++++ +A o+ B = {x | (x in A " or " x in B) " and " x !in A nn B} +++++ + +For example + +[stem] +++++ +A = {1, 2, 3}\ +B = {2, 3, 4}\ +A o+ B = {1, 4} +++++ + +NOTE: stem:[A o+ B = A Delta B] diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/trees.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/trees.adoc new file mode 100644 index 00000000..c7302fb0 --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/trees.adoc @@ -0,0 +1,244 @@ += Cheatsheet - Trees +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +NOTE: It's recommended to read the cheatsheets on Graphs, first. + +== Definition + +In computer science, **trees** are used in a wide range of algorithms, such as +data structures for efficient lookups or making decisions. A tree is a +**connected acyclic undirected graph**. + +=== Acyclic Graphs + +A graph stem:[G] is called an **acyclic** graph if and only if stem:[G] has **no +cycles**. + +.stem:[G_1] is NOT an acyclic graph, while stem:[G_2] is. +image::./assets/trees/acyclic_graphs.png[align=center, width=500] + +Not all acyclic graphs are trees. + +image::./assets/trees/acyclic_graphs_trees.png[align=center, width=500] + +=== Forest + +A **forest** is a **disconnected graph** containing no cycles. + +image::./assets/trees/forest.png[align=center, width=500] + +Theorem 1:: + +An undirected graph is a **tree** if and only if there is a **unique simple +path** between **any two** of its vertices. + +Theorem 2:: +A tree with **stem:[n] vertices** has **stem:[n-1] edges**. + +=== Rooted Tree + +A **rooted tree** is when one vertex has been **designated as the root** and +every edge is **directed away from the root**. + +== Spanning Tree + +A **spanning tree** of a graph stem:[G] is a **connected** sub graph of stem:[G] +which **contains all vertices of stem:[G]**, but with **no cycles**. + +.All stem:[T_n] are spanning sub graphs of graph stem:[G]. +image::./assets/trees/spanning_trees.png[align=center, width=450] + +=== Constructing a Spanning Tree + +To get a spanning tree of a graph stem:[G]: + +. Keep all vertices of stem:[G] +. Break all the cycles but keep the tree connected. + +image::./assets/trees/sub_graphs.png[align=center, width=500] + +Two spanning trees are said **isomorphic** if there is a **bijection preserving +adjacency** between the two trees. + +.stem:[T_1], stem:[T_3] and stem:[T_4] are all **isomorphic** to each others. stem:[T_1], stem:[T_3] and stem:[T_4] are all **non-isomorphic** to stem:[T_2]. +image::./assets/trees/isomorphic_trees.png[align=center, width=500] + +=== Minimum-cost Spanning Tree + +The **cost** (or **weight**) of a spanning tree is the **sum of the costs** of +its edges. A **minimum-cost** spanning tree is a spanning tree that has the +**lowest weight** (lowest cost). + +.The weight of stem:[T_2] is stem:[w = 6+4+1+2+7 = 20]. +image::./assets/trees/minimum_cost_tree.png[align=center, width=500] + +There are two basic algorithms for finding minimum-cost spanning trees: + +Kruskal's algorithm:: + +Start with the cheapest edges in the spanning tree, then repeatedly add the +cheapest edge that does not create a cycle. + +Prim's algorithm:: + +Start with any one node in the spanning tree, then repeatedly add the cheapest +edge, and the node it leads to, for which the node is not already in the +spanning tree. + +== Rooted Tree + +A rooted tree is a **directed tree** having one **distinguished** vertex +stem:[r], called the root, such that for every vertex stem:[v] there is a +**directed path** from stem:[r] to stem:[v] + +image::./assets/trees/rooted_tree.png[align=center, width=350] + +A directed tree is represented as a rooted tree **if and only if one vertex** +has in-degree stem:[0] whereas **all** other **vertices** have in-degree +stem:[1]. + +image::./assets/trees/directed_tree.png[align=center, width=450] + +=== Terminology + +image::./assets/trees/terminology_tree.png[align=center, width=450] + +The **depth** or **path length** of a node in a tree is the number of edges from +the root to that node. The **height** of a node in a tree is the longest path +from that node to a leaf. The **depth or the height** of a tree is the maximum +path length across all its nodes. + +=== Special Trees + +image::./assets/trees/special_trees.png[align=center, width=450] + +=== Regular Rooted Trees + +An stem:[m]-ary tree is **regular** if every one of its **internal** notes **has +exactly** stem:[m] children. + +image::./assets/trees/regular_tree.png[align=center, width=550] + +An **stem:[m]-ary tree** has at most stem:[m^h] vertices at level stem:[h]. + +image::./assets/trees/m_ary_tree.png[align=center, width=550] + +== Isomorphic Trees + +Two trees stem:[T_1] and stem:[T_2] are isomorphic if there is a **bijection**: + +[stem] +++++ +f: V(T_1) -> V(T_2) +++++ + +which **preserves adjacency** and **non-adjacency**. That is, if stem:[uv] is in +stem:[E(T_1)] and stem:[f(u)f(v)] is in stem:[E(T_2)]. + +Respectively: + +[stem] +++++ +T_1 ~= T_2 +++++ + +Two trees with **different degree sequences** are **not isomorphic**. Two trees +with the **same degree** sequence **are not necessarily isomorphic**. + +=== Example + +image::./assets/trees/isomorphic_example.png[align=center, width=450] + +=== Isomorphic Rooted Trees + +Two isomorphic trees are **isomorphic as rooted trees** if and only if there is +a **bijection** that maps the **root** of one tree to the root of the other. +Isomorphic trees **may** or **may not** be isomorphic as **rooted trees**. + +== Binary Search Trees + +A binary search tree is a **binary tree** in which the vertices are **labelled** +with items so that a **label of a vertex is greater than** the labels of all +vertices in the **left subtree** of this vertex and **is less than** the labels +of all vertices in the **right subtree** of this vertex. + +image::./assets/trees/binary_tree.png[align=center, width=450] + +=== Application + +The usage of binary search trees apply in the case where we want to **store a +modifiable collection** in a **computer's memory** and be able to **search, +insert** or **remove** elements from the collection in an efficient way. + +=== Height of the Binary Search Tree + +There are two methods that one can use to find the height of a binary search +tree, where stem:[N] is number of nodes in the tree and stem:[h] is the height +(the following formula must be satisfied): + +[stem] +++++ +2^(h-1) < N + 1 <= 2^h\ +-=\ +h-1 < log_2 (N + 1) <= h +++++ + +or the second method (hint: stem:[|~ ... ~|] means _ceiling_, i.e round up): + +[stem] +++++ +...\ +-=\ +h = |~ log_2(N+1) ~| +++++ + +For example, if stem:[N=15], then stem:[h = 4]. + +[stem] +++++ +h = |~ log_2(15+1) = |~ log_2(16) ~| = 4 +++++ + +=== Binary Search Algorithm + +The algorithm starts by comparing the searched element to the middle term of the +list. The list is then split into two smaller sub-lists of the same size, or +where one of these smaller lists has one fewer term than the other. The search +continues by restricting the search to the appropriate sub-list based on the +comparison of the searched element and term in the middle. + +For example, when searching for stem:[21] in the list of: + +image::./assets/trees/binary_search_example_1.png[align=center, width=450] + +[stem] +++++ +darr +++++ + +image::./assets/trees/binary_search_example_2.png[align=center, width=450] + +[stem] +++++ +darr +++++ + +image::./assets/trees/binary_search_example_3.png[align=center, width=450] + +[stem] +++++ +darr +++++ + +image::./assets/trees/binary_search_example_4.png[align=center, width=450] + +[stem] +++++ +darr +++++ + +image::./assets/trees/binary_search_example_5.png[align=center, width=450] diff --git a/level-4/discrete-mathematics/student-notes/fabio-lama/src/universal_set_complement_laws.adoc b/level-4/discrete-mathematics/student-notes/fabio-lama/src/universal_set_complement_laws.adoc new file mode 100644 index 00000000..5840ad4d --- /dev/null +++ b/level-4/discrete-mathematics/student-notes/fabio-lama/src/universal_set_complement_laws.adoc @@ -0,0 +1,211 @@ += Cheatsheet - Universal Set, Complement and Laws +Fabio Lama +:description: Module: CM1020- Discrete Mathematics, started 25. October 2022 +:doctype: article +:sectnums: 4 +:stem: + +== Intro + +A universal set is a set that contains everything. We note the universal set +with the letter stem:[U]. + +[stem] +++++ +A sube U +++++ + +== Complement of a Set + +The complement of set stem:[A] contains all elements of stem:[U] but not +stem:[A]. + +[stem] +++++ +bar A = U-A +++++ + +and therefore: + +[stem] +++++ +bar A uu A = U +++++ + +For example: + +[stem] +++++ +U = {1, 2, 3, 4}\ +A = {1, 2}\ +bar A = {3, 4}\ +A uu bar A = {1, 2, 3, 4} = U +++++ + +== De Morgan's Law + +The complement of the **union** of two sets stem:[A] and stem:[B] is equal to the +**intersection** of their complements. + +[stem] +++++ +bar (A uu B) = bar A nn bar B +++++ + +The complement of the **intersection** of two sets stem:[A] and stem:[B] is equal to +the **union** of their complements. + +[stem] +++++ +bar (A nn B) = bar A uu bar B +++++ + +For example: + +[stem] +++++ +U = {1, 2, 3, 4, 5, 6, 7, 8}\ +A = {1, 2, 3, 4} " and " B = {4, 5, 6}\ +A uu B = {1, 2, 3, 4, 5, 6} " and " A nn B = {4}\ +bar (A uu B) = {7, 8} " and " bar (A nn B) = {1, 2, 3, 5, 6, 7, 8}\ +bar A = {5, 6, 7, 8} " and " bar B = {1, 2, 3, 7, 8} +++++ + +We conclude: + +[stem] +++++ +bar (A uu B) = {7, 8} = bar A nn bar B\ +bar (A nn B) = {1, 2, 3, 5, 6, 7, 8} = bar A uu bar B +++++ + +== Laws of Sets + +=== Commutativity + +Unions, intersections and symmetric differences are commutative. + +[stem] +++++ +A uu B = B uu A\ +A nn B = B nn A\ +A o+ B = B o+ A +++++ + +Set difference is **not** commutative. + +[stem] +++++ +A - B != B -A +++++ + +For example: + +[stem] +++++ +A = {1, 2, 3}\ +B = {3, 4, 5}\ +A - B = {1, 2}\ +B -A = {4 , 5} +++++ + +=== Associativity + +Unions, intersections and symmetric differences are associative. + +[stem] +++++ +A uu (B uu C) = (A uu B) uu C\ +A nn (B nn C) = (A nn B) nn C\ +A o+ (B o+ C) = (A o+ B) o+ C +++++ + +Set difference is **not** associative: + +[stem] +++++ +A - (B - C) != (A - B - C) +++++ + +For example: + +[stem] +++++ +A = {1, 2, 3}\ +B = {3, 4, 5}\ +C = {3}\ +A - (B - C) = {1, 2, 3}\ +(A - B) - C = {1, 2} +++++ + +=== Distributive + +Unions and intersections are distributive. + +[stem] +++++ +A uu (B nn C) = (A uu B) nn (A uu C)\ +A nn (B uu C) = (A nn B) uu (A nn C) +++++ + +== Set Identities + +=== Unions + +[stem] +++++ +A uu B = B uu A\ +(A uu B) uu C = A uu (B uu C)\ +A uu (B nn C) = (A uu B) nn (A uu C)\ +bar (A uu B) = bar A nn bar B\ +A uu O/ = A\ +A uu U = U\ +A uu bar A = U\ +bar U = O/\ +bar bar A = A\ +A uu (A nn B) = A\ +A - B = A nn bar B +++++ + +=== Intersections + +[stem] +++++ +A nn B = B nn A\ +(A nn B) nn C = A nn (B nn C)\ +A nn (B uu C) = (A nn B) uu (A nn C)\ +bar (A nn B) = bar A uu bar B\ +A nn O/ = O/\ +A nn U = A\ +A nn bar A = O/\ +bar O/ = U\ +A nn (A uu B) = A +++++ + +== Partition Set + +The two sets stem:[A] and stem:[B] are **disjoint** if and only if stem:[A nn B = O/]. + +For example: + +[stem] +++++ +A = {1, 2, 3}\ +B = {4, 5, 6}\ +A nn B = O/ " (disjoint)" +++++ + +The set stem:[A] consists of subsets stem:[A_1, A_2] and stem:[A_3] such that those +subsets are disjoint and the union of all those subsets is equal to stem:[A]: + +[stem] +++++ +A = {1, 2, 3, 4, 5, 6, 7, 8}\ +A_1 = {1, 2, 3}\ +A_2 = {4, 5, 6}\ +A_3 = {7, 8}\ +A_1 nn A_2 nn A_3 = O/\ +A = A_1 uu A_2 uu A_3 +++++ + +Hence, stem:[A_1, A_2] and stem:[A_3] are **partitions** of set stem:[A].