Okay, let's dive into the first topic of Discrete Structures: Functions, relations, and
sets1.
These three concepts are the fundamental building blocks for many other areas of
computer science. They are the "nouns, verbs, and grammar" used to describe
computation.
1. Sets 🧺
A set is simply a collection of distinct, unordered items.
• Key Concepts:
◦
Notation: We use curly braces, e.g., Set A = {1, 3, 5} or Set B = {apple,
orange}.
◦
Element: An item in a set. We use the symbol $\in$ to say "is an element of,"
e.g., $3 \in A$.
◦
Cardinality: The size of a set, written as $|A|$. For our Set A, $|A| = 3$.
◦
Empty Set: The set with no elements, written as $\emptyset$ or {}.
◦
Subset: A is a subset of B, written $A \subseteq B$, if every element of A is
also in B.
◦
Power Set: The set of all possible subsets of a set. For A = {1, 2}, the Power
Set P(A) = { \emptyset, {1}, {2}, {1, 2} }. The cardinality is $2^{|A|}$.
• Key Operations:
◦
Union ($\cup$): All elements that are in either set. $A \cup B$.
◦
Intersection ($\cap$): All elements that are in both sets. $A \cap B$.
◦
Difference ($-$): Elements in the first set but not the second. $A - B$.
◦
Complement ($\overline{A}$ or $A^c$): All elements in the universal set
($U$) that are not in A.
◦
Cartesian Product ($\times$): Creates a set of all possible ordered pairs. This
is the foundation for relations.
▪
Example: If A = {1, 2} and B = {a, b}, then A $\times$ B = { (1, a), (1, b),
(2, a), (2, b) }.
2. Relations 🤝
A relation describes a relationship between elements, often from different sets.
Formally, a relation is any subset of a Cartesian product.
• Example: Using A $\times$ B from above, a relation R could be R = { (1, a), (2, b) }.
We would say "1 is related to a" and "2 is related to b".
• Relations on a single set (e.g., A $\times$ A) are very common. Example: The "less
than" relation $<$ on the set A = {1, 2, 3} would be the set R = { (1, 2), (1, 3), (2,
3) }.
• Key Properties of Relations (Very important!): For a relation R on a set A:
1
▪
2
▪
Reflexive: Every element is related to itself. ($(a, a) \in R$ for all $a \in A$).
Example: The $\le$ ("less than or equal to") relation.
Symmetric: If a is related to b, then b is related to a. (If $(a, b) \in R$, then $(b,
a) \in R$).
Example: The $= ("equals") relation.
3
Antisymmetric: If a is related to b and b is related to a, then a and b must be
the same. (If $(a, b) \in R$ and $(b, a) \in R$, then $a = b$).
▪
Example: The $\le$ relation. (If $a \le b$ and $b \le a$, then $a$ must
equal $b$).
4
▪
Transitive: If a is related to b and b is related to c, then a is related to c. (If $(a,
b) \in R$ and $(b, c) \in R$, then $(a, c) \in R$).
Example: The $<$ ("less than") relation.
• Equivalence Relation: A relation that is Reflexive, Symmetric, and Transitive. This
is a classic concept. The relation "is equal to" ($=$) is the simplest example.
3. Functions ➡️
A function is a special, well-behaved relation. It maps each element from one set (the
domain) to exactly one element in another set (the codomain).
• Notation: We write $f: A \rightarrow B$, meaning $f$ is a function that maps elements
from set $A$ (the Domain) to set $B$ (the Codomain).
• Key Rule: Every element in the domain A must have one and only one arrow pointing
from it.
• Range: The set of actual outputs in $B$ that are mapped to. The range is always a
subset of the codomain.
• Types of Functions (The MFT Big Three):
1
▪
Injective (One-to-One): Every element in the domain maps to a unique
element in the codomain. No two inputs share the same output.
Test: If $f(a) = f(b)$, it must be that $a = b$.
2
Surjective (Onto): Every element in the codomain $B$ is mapped to by at
least one element from $A$. The range is equal to the codomain.
3
Bijective (One-to-One Correspondence): The function is both injective and
surjective. This means there is a perfect, reversible pairing between the
elements of the two sets.
How This Applies to the MFT & CS
• Direct Questions: You can expect questions like:
◦
"Given sets A and B, what is the cardinality of $A \cup (B \cap C)$?"
◦
"Is the 'divides' relation on the set of integers reflexive? Symmetric?
Transitive?"
◦
"Consider the function $f(x) = x^2$ from the set of Integers to the set of
Integers. Is this function injective? Surjective?"
• Foundational Knowledge: These concepts are the language for other topics on the
exam:
◦
Databases: Relational Algebra is built entirely on set theory. A database table
is literally a relation. A key is a concept based on functional
dependency.
◦
Graphs & Trees: A graph $G = (V, E)$ is defined as a set of Vertices ($V$)
and a set of Edges ($E$), where $E$ is a relation on the set $V$2.
◦
Logic: The set operations $\cup$ (union) and $\cap$ (intersection) are
directly analogous to the logical operations $\vee$ (OR) and $\wedge$
(AND), as seen in sample question 8 3.
Let's move on to the next topic, B. Basic Logic.
This is one of the most critical parts of discrete structures, as it's the foundation for
reasoning, proof techniques, algorithm design, and even hardware.
B. Basic Logic 🧠
Basic logic is the study of formal reasoning. In computer science, we primarily focus on
two types:
• Propositional Logic (and Boolean Algebra)
• Predicate (First-Order) Logic
1. Propositional Logic
This is the logic of simple statements (propositions) that can be either true or false.
• Proposition: A declarative sentence that is definitively True or False.
1
Example: "The MFT has 66 questions." (True, based on your doc 1)
2
Not a Proposition: "Study for the test." (This is a command)
• Logical Connectives (Operators): We combine propositions using operators.
1
NOT ($\neg$): Negation. $\neg P$ ("not P")
2
AND ($\wedge$): Conjunction. $P \wedge Q$ ("P and Q")
3
OR ($\vee$): Disjunction (inclusive OR). $P \vee Q$ ("P or Q")
4
Implies ($\rightarrow$): Conditional. $P \rightarrow Q$ ("if P, then Q")
5
If and Only If ($\leftrightarrow$): Biconditional. $P \leftrightarrow Q$ ("P if
and only if Q")
• Truth Tables: These are the primary tool to determine the truth value of a complex
logical expression. The "Implies" ($\rightarrow$) operator is the most tricky:
1
$P \rightarrow Q$ is only False when $P$ is True and $Q$ is False. In all other
cases, it's True. (This is called a "vacuously true" statement when P is
false).
• Logical Equivalence: Two statements are logically equivalent if they have the exact
same truth table.
1
De Morgan's Laws (Essential!):
▪
$\neg(P \wedge Q) \equiv (\neg P \vee \neg Q)$
▪
$\neg(P \vee Q) \equiv (\neg P \wedge \neg Q)$
2
Contrapositive: $P \rightarrow Q \equiv \neg Q \rightarrow \neg P$ (This is a
very common tool in proofs).
2. Predicate Logic
Propositional logic can't handle variables (like "x > 3"). Predicate logic solves this by
introducing quantifiers.
• Predicate: A statement with a variable, e.g., $P(x)$ = "x is a prime number".
• Universal Quantifier ($\forall$): "For all".
1
Example: $\forall x [ \text{Even}(x) \rightarrow \text{NotPrime}(x+1) ]$ ("For all
x, if x is even, then x+1 is not prime" - this is false, but it's a valid
statement).
• Existential Quantifier ($\exists$): "There exists".
1
Example: $\exists x [ \text{Student}(x) \wedge \text{TakingMFT}(x) ]$ ("There
exists at least one person who is a student and is taking the MFT").
How This Applies to the MFT & CS
This entire topic is central to CS, and the MFT sample questions show this directly.
• Boolean Algebra (Sample Question 8): Propositional logic is the basis for Boolean
algebra, which governs digital circuits (logic gates) and if statements. Sample
question 8 tests your knowledge of the distributive and commutative properties of
Boolean logic 2.
◦
$A \wedge (B \vee C) = (A \wedge B) \vee (A \wedge C)$ (Distributive Law)
3
◦
$A \vee (B \wedge C) = (A \vee B) \wedge (A \vee C)$ (Distributive Law) 4
◦
These laws are fundamental for simplifying code and hardware logic.
•
Translating Logic (Sample Question 15): This question is a classic example of
Predicate Logic5. It asks you to translate a complex formal logic statement into
the best English equivalent6.
◦
The Statement: $\forall x[F(x)\rightarrow\forall y(E(y,x)\rightarrow B(y))]$ 7
◦
Breakdown:
$\forall x[...]$: "For any x..."
$F(x) \rightarrow ...$: "...if x is a fish, then..."
$\forall y(...)$: "...for any y..."
$E(y,x) \rightarrow B(y)$: "...if y eats x, then y is a bear."
◦
Putting it together: "For any x, if x is a fish, then for any y, if y eats that fish
(x), then y must be a bear."
◦
Best Translation: The correct answer, (E) "Only bears eat fish"8888, is the
most concise human-readable equivalent of that statement.
This topic directly flows into the next one: Proof Techniques. You use the rules of logic
to build your arguments.
Here's our study guide for the next topic: C. Proof Techniques.
Proof techniques are the formal methods we use to demonstrate that a statement
(about logic, algorithms, or programs) is always true. They rely heavily on the rules of
basic logic we just covered.
1. Direct Proof ➡️
This is the most straightforward technique. To prove a statement in the form "If $P$,
then $Q$" ($P \rightarrow Q$), you:
• Assume $P$ is true.
• Use definitions, logic, and known facts to show that $Q$ must also be true.
• Example: "Prove that if $n$ is an odd integer, then $n^2$ is an odd integer."
1
Assume $P$: $n$ is odd.
2
Logic: By definition, $n = 2k + 1$ for some integer $k$.
3
Show $Q$: $n^2 = (2k + 1)^2 = 4k^2 + 4k + 1 = 2(2k^2 + 2k) + 1$.
4
Since $(2k^2 + 2k)$ is an integer, $n^2$ is of the form $2(\text{integer}) + 1$,
which is the definition of an odd integer. Proof complete.
2. Proof by Contraposition ↩️
Sometimes, proving $P \rightarrow Q$ directly is hard. Instead, we can prove its logical
equivalent, the contrapositive: "If $\neg Q$, then $\neg P$" ($\neg Q \rightarrow \neg
P$).
• Assume $\neg Q$ is true (that the "then" part is false).
• Show that $\neg P$ must be true (that the "if" part must also be false).
• Example: "Prove that if $n^2$ is even, then $n$ is even."
◦
Direct proof is tricky. Let's try contraposition.
◦
Contrapositive: "If $n$ is not even (i.e., $n$ is odd), then $n^2$ is not even
(i.e., $n^2$ is odd)."
◦
...Hey, that's exactly what we proved in the "Direct Proof" example! Since we
proved the contrapositive is true, the original statement must also be true.
3. Proof by Contradiction 💥
This is a powerful and common technique. To prove a statement $P$ is true:
1 Assume $P$ is false (assume $\neg P$).
2 Show that this assumption leads to a logical contradiction (e.g., $1 = 0$, $N$ is both
even and odd, $A \cap \overline{A} \neq \emptyset$).
3 Since your assumption led to an impossibility, the assumption must be false.
4 Therefore, $P$ (the original statement) must be true.
• Example: "Prove that $\sqrt{2}$ is irrational."
◦
Assume $\neg P$: $\sqrt{2}$ is rational.
◦
Logic: By definition, $\sqrt{2} = \frac{a}{b}$ where $a$ and $b$ are integers
with no common factors.
◦
... (algebra) ... $2 = \frac{a^2}{b^2} \implies 2b^2 = a^2$. This means $a^2$ is
even, so $a$ must be even.
◦
Let $a = 2k$. Then $2b^2 = (2k)^2 = 4k^2$, so $b^2 = 2k^2$. This means
$b^2$ is even, so $b$ must be even.
◦
Contradiction: If both $a$ and $b$ are even, they have a common factor of 2.
This contradicts our assumption that they have no common factors.
◦
Conclusion: The initial assumption is false. $\sqrt{2}$ must be irrational.
4. Proof by Induction (Mathematical Induction) 🪜
This is essential for computer science, especially for proving things about loops
(correctness) and recursion (complexity). It's used to prove a statement $P(n)$ is true
for all integers $n \ge n_0$.
It's a two-step process:
1 Base Case: Prove the statement is true for the very first value, $P(n_0)$ (e.g., $n=0$
or $n=1$).
2 Inductive Step:
◦
Assume $P(k)$ is true for some arbitrary $k \ge n_0$. (This is the Inductive
Hypothesis).
◦
Prove that this assumption implies $P(k+1)$ is also true. (i.e., show $P(k)
\rightarrow P(k+1)$).
• Example: "Prove $1 + 2 + \dots + n = \frac{n(n+1)}{2}$ for all $n \ge 1$."
◦
Base Case (n=1): Is $1 = \frac{1(1+1)}{2}$? Yes, $1 = \frac{2}{2} = 1$. True.
◦
Inductive Step:
▪
Assume $P(k)$: $1 + \dots + k = \frac{k(k+1)}{2}$.
▪
Prove $P(k+1)$: We need to show $1 + \dots + k + (k+1) =
\frac{(k+1)((k+1)+1)}{2}$.
▪
Start with the left side: $(1 + \dots + k) + (k+1)$ ... use the assumption
for the first part ... $= \left[\frac{k(k+1)}{2}\right] + (k+1)$ ... find
common denominator ... $= \frac{k(k+1) + 2(k+1)}{2}$ ... factor out
(k+1) ... $= \frac{(k+1)(k+2)}{2}$ $= \frac{(k+1)((k+1)+1)}{2}$.
▪
This is the right-hand side. The Inductive Step is complete.
◦
Conclusion: The statement is true for all $n \ge 1$.
5. Disproof by Counterexample ❌
This is the opposite of a proof. To prove a statement is false, you only need to find one
single case where it fails. This is especially used to disprove universal ("for all...")
statements.
•
MFT Example: This is exactly what Sample Question 10 is asking for1.
◦
Statement: "Every connected graph has one or more vertices of degree 2."
◦
Task: Find a counterexample from the five options.
◦
You must look for a graph that is (1) connected and (2) has zero vertices of
degree 2.
◦
The correct answer (C) is a connected graph where every vertex has a degree
of 4, thus disproving the statement.
Let's move on to the next topic: D. Basics of Counting and Number Theory.
This section covers two related areas. "Counting" (or combinatorics) is about figuring
out how many ways there are to do something, while "Number Theory" is about the
properties of integers.
1. Basics of Counting 🔢
This is fundamental for analyzing algorithm complexity (how many operations?),
probability (how many possible outcomes?), and data structures.
• The Sum Rule: If you have $A$ ways to do one thing and $B$ ways to do another
thing (and you can't do both at the same time), then there are $A + B$ total
choices.
◦
Example: You can choose a project from a list of 10 (algorithms) or a list of 5
(AI). Your total choice is $10 + 5 = 15$ projects.
• The Product Rule: If a procedure has two steps, with $A$ ways to do the first step
and $B$ ways to do the second step for each first step, then there are $A \times
B$ total ways.
◦
Example: You are making a password. You have 26 choices for the first letter
and 10 choices for the second digit. Total combinations: $26 \times 10 =
260$.
• Permutations (Order Matters): How many ways can you arrange $k$ items selected
from a set of $n$?
◦
The formula is $P(n, k) = \frac{n!}{(n-k)!}$.
◦
MFT Example (Question 9): This is a perfect example of a permutation 1.
▪
Problem: Find the number of PINs with 3 different digits from 0-9.
▪
"Order Matters": Yes, "123" is a different PIN from "321".
▪
"Different Digits": This means no repetition (like "222").
▪
Solution (using Product Rule):
Choice for 1st digit: 10 (0-9)
Choice for 2nd digit: 9 (since it must be different from the first)
Choice for 3rd digit: 8 (different from the first two)
▪
Total: $10 \times 9 \times 8 = 720$. This is $P(10, 3)$.
• Combinations (Order Doesn't Matter): How many ways can you choose a group of
$k$ items from a set of $n$?
◦
The formula is $C(n, k) = \binom{n}{k} = \frac{n!}{k!(n-k)!}$.
◦
Example: How many ways to choose a 3-person committee from 10 people?
Order doesn't matter (a committee of A, B, C is the same as C, B, A).
◦
Total: $C(10, 3) = \frac{10!}{3!7!} = \frac{10 \times 9 \times 8}{3 \times 2 \times
1} = 120$.
2. Number Theory 🧮
This is the study of integers and their properties. It's the basis for modern cryptography
(like RSA) and hashing algorithms.
• Divisibility: $a \mid b$ means "$a$ divides $b$" (or $b$ is a multiple of $a$).
• Prime Numbers: An integer $p > 1$ whose only positive divisors are 1 and itself.
• Prime Factorization: Every integer $n > 1$ can be written uniquely as a product of
prime numbers (e.g., $12 = 2 \times 2 \times 3 = 2^2 \times 3$).
• Modular Arithmetic: The arithmetic of "remainders".
1
We write $a \equiv b \pmod{m}$ ("$a$ is congruent to $b$ modulo $m$").
2
This means $a$ and $b$ have the same remainder when divided by $m$.
3
Example: $10 \equiv 3 \pmod{7}$ (because 10/7 has remainder 3, and 3/7 has
remainder 3).
4
Application: Used everywhere in CS, from hash tables (h(key) = key %
table_size) to cryptography.
• Greatest Common Divisor (GCD): The largest integer that divides two numbers, $a$
and $b$.
1
Example: $\text{gcd}(12, 18) = 6$.
2
Euclidean Algorithm: The classic, efficient method for finding the GCD.
This knowledge is essential for understanding cryptographic principles and for the
"analysis of algorithms" part of the exam, where you might analyze an algorithm based
on number-theoretic properties.
Here is the study guide for the next topic: E. Graphs and Trees.
These concepts are critical, forming the basis for modeling networks, solving pathfinding
problems, and organizing hierarchical data.
1. Graphs G = (V, E) 🌐
A graph is a set of vertices (or nodes) $V$ and a set of edges $E$ that connect pairs
of vertices.
• Key Terminology:
◦
Directed vs. Undirected: Edges in an undirected graph are two-way (like a
friendship on Facebook). Edges in a directed graph are one-way (like
"following" on Twitter).
◦
Degree of a Vertex: In an undirected graph, it's the number of edges
connected to it. In a directed graph, you have indegree (edges pointing in)
and outdegree (edges pointing out).
◦
Path: A sequence of vertices connected by edges.
◦
Cycle: A path that starts and ends at the same vertex. A graph with no cycles
is acyclic.
◦
Connected Graph: In an undirected graph, there is a path from every vertex to
every other vertex. Sample Question 10 specifically deals with this
concept1.
• Common Graph Representations:
◦
Adjacency Matrix: An $N \times N$ matrix (where $N$ is the number of
vertices) where Matrix[i][j] = 1 if there's an edge from $i$ to $j$, and 0
otherwise. Good for dense graphs.
◦
Adjacency List: An array where each index $i$ stores a linked list of the
vertices that $i$ has an edge to. Good for sparse graphs.
2. Trees 🌳
A tree is a special type of graph. It is undirected, connected, and acyclic (it has no
cycles).
• Key Terminology:
1
Root: The top-most node of the tree.
2
Parent/Child: Each node (except the root) has exactly one parent. A node can
have zero or more children.
3
Leaf: A node with no children.
4
Height/Depth: The length of the longest path from the root to a leaf.
• Important Types of Trees:
1
Binary Tree: A tree where each node has at most two children (a left child and
a right child).
2
Binary Search Tree (BST): A binary tree with a special property: for any node,
all values in its left subtree are less than the node's value, and all values in
its right subtree are greater than the node's value.
3
MFT Example (Question 2): This question requires you to analyze a Binary
Search Tree to find the expected number of comparisons, demonstrating
you need to understand its structure2.
• Tree Traversal Algorithms: Common ways to "visit" every node in a tree.
1
In-order: Visit Left Child $\rightarrow$ Visit Root $\rightarrow$ Visit Right
Child. (For a BST, this visits nodes in sorted order!)
2
Pre-order: Visit Root $\rightarrow$ Visit Left Child $\rightarrow$ Visit Right
Child.
3
Post-order: Visit Left Child $\rightarrow$ Visit Right Child $\rightarrow$ Visit
Root.
How This Applies to the MFT & CS
• Data Structures: Trees (especially BSTs, heaps, and B-trees) are fundamental data
structures.
• Algorithms: Many key algorithms are graph-based:
1
BFS (Breadth-First Search) & DFS (Depth-First Search): Standard ways to
traverse a graph.
2
Dijkstra's Algorithm: Finds the shortest path in a weighted graph.
3
Minimum Spanning Tree (MST): (e.g., Prim's or Kruskal's algorithm) Finds
the cheapest set of edges to connect all vertices in a weighted graph.
•
Modeling: Graphs are used to model computer networks, social networks, state
transitions (like in Sample Question 14's finite automaton 3), and
dependencies.
Here's the study guide for the final topic in the "Discrete Structures" section: F. Discrete
Probability.
This area applies the "Basics of Counting" to determine the likelihood of different
outcomes.
F. Discrete Probability 🎲
Discrete probability deals with experiments that have a finite or countable number of
outcomes.
• Key Concepts:
◦
▪
◦
▪
◦
Sample Space (S): The set of all possible outcomes.
Example: Rolling a 6-sided die. $S = \{1, 2, 3, 4, 5, 6\}$.
Event (E): A subset of the sample space (a specific outcome you're interested
in).
Example: Rolling an even number. $E = \{2, 4, 6\}$.
Probability of an Event (P(E)): When all outcomes are equally likely, the
probability of an event is: $$P(E) = \frac{\text{Number of favorable
outcomes}}{\text{Total number of outcomes}} = \frac{|E|}{|S|}$$
▪
Example: The probability of rolling an even number is $\frac{|\{2, 4,
6\}|}{|\{1, 2, 3, 4, 5, 6\}|} = \frac{3}{6} = 0.5$.
◦
Complementary Event ($\overline{E}$): The probability of an event not
happening. $P(\overline{E}) = 1 - P(E)$.
• Combining Probabilities:
◦
Union (Addition Rule): The probability of event A or event B happening. $P(A
\cup B) = P(A) + P(B) - P(A \cap B)$
▪
(Note: $P(A \cap B)$ is the probability of both happening at the same
time).
◦
Independent Events: Two events are independent if one happening doesn't
affect the other.
▪
If A and B are independent, $P(A \cap B) = P(A) \times P(B)$.
◦
Conditional Probability: The probability of A happening, given that B has
already happened. $$P(A|B) = \frac{P(A \cap B)}{P(B)}$$
• Expected Value (Expectation): This is the "average" outcome of an experiment if you
repeated it many times. It's a weighted average.
◦
Formula: $E[X] = \sum (x \times P(x))$ (Sum of (each value x $\times$ the
probability of that value happening))
◦
MFT Example (Question 2): This question is a perfect example of expected
value1.
▪
Problem: What is the expected number of comparisons to find a node
chosen at random?
▪
Sample Space: All 8 nodes {A, B, C, D, E, F, G, H}. The probability of
picking any one is $\frac{1}{8}$.
▪
Values & Probabilities:
1 comparison (Node E): 1 node. $P(1) = \frac{1}{8}$
2 comparisons (Nodes C, H): 2 nodes. $P(2) = \frac{2}{8}$
3 comparisons (Nodes B, D, F): 3 nodes. $P(3) = \frac{3}{8}$
4 comparisons (Nodes A, G): 2 nodes. $P(4) = \frac{2}{8}$
▪
Calculation: $E[X] = (1 \times \frac{1}{8}) + (2 \times \frac{2}{8}) + (3
\times \frac{3}{8}) + (4 \times \frac{2}{8})$ $E[X] = \frac{1 + 4 + 9 +
8}{8} = \frac{22}{8} = 2.75$
▪
This matches the correct answer, (C)2.
This concludes all the topics under I. Discrete Structures.
Would you like to move on to the next main section, II. Programming, or would you like
to review any of the Discrete Structures topics in more detail?
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )