Migrated
This commit is contained in:
120
Discrete Structures/Counting.md
Normal file
120
Discrete Structures/Counting.md
Normal file
@ -0,0 +1,120 @@
|
||||
---
|
||||
type: theoretical
|
||||
---
|
||||
|
||||
# Key Concepts
|
||||
|
||||
## Permutations
|
||||
|
||||
A permutation is an arrangement of objects in a specific order.
|
||||
|
||||
- Without Repetition[^1]: The number of permutations of $n$ distinct objects taken $r$ at a time is denoted by $nP_r$ and calculated as:
|
||||
$$
|
||||
nP_r = \frac{n!}{(n - r)!}
|
||||
$$
|
||||
|
||||
|
||||
- With Repetition (Unlimited Repeats)[^2]: If objects can repeat, the number of permutations of $n$ objects taken $r$ at a time is:
|
||||
$$
|
||||
n^r
|
||||
$$
|
||||
|
||||
- With Repetition (Limited Repeats) [^3]: If there are $k_1$ objects of one type, $k_2$ of another, ..., and $k_t$ of type $t$, the number of permutations is:
|
||||
$$
|
||||
\frac{n!}{k_1! \cdot k_2! \cdot \ldots \cdot k_t!}
|
||||
$$
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Combinations
|
||||
|
||||
A combination is a selection of objects where the order does not matter.
|
||||
|
||||
- Without Repetition: The number of combinations of $n$ distinct objects taken $r$ at a time is denoted by $nC_r$ or $\binom{n}{r}$, and is calculated as:
|
||||
$$
|
||||
nC_r = \binom{n}{r} = \frac{n!}{r!(n - r)!}
|
||||
$$
|
||||
|
||||
- With Repetition: If repetition is allowed, the number of combinations of $n$ objects taken $r$ at a time is:
|
||||
$$
|
||||
\binom{n + r - 1}{r}
|
||||
$$
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
### Counting Strings Over an Alphabet
|
||||
How many strings of length 3 can we form with the alphabet $\Sigma = \{a, b, c, d, e\}$?
|
||||
|
||||
- Since there are 5 choices for each position, the total number of strings is:
|
||||
$$
|
||||
5 \cdot 5 \cdot 5 = 5^3 = 125
|
||||
$$
|
||||
|
||||
### Combinations Without Repetition
|
||||
How many subsets of size 3 can we form from $A = \{a, b, c, d, e\}$?
|
||||
|
||||
- First, calculate the number of permutations:
|
||||
$$
|
||||
\frac{5!}{(5-3)!} = 5 \cdot 4 \cdot 3
|
||||
$$
|
||||
Divide by $3!$ to account for order:
|
||||
$$
|
||||
\frac{5 \cdot 4 \cdot 3}{3!} = 10
|
||||
$$
|
||||
|
||||
### Combinations With Repetition
|
||||
In a restaurant offering 12 desserts, how many ways can you choose 4 desserts (allowing repeats)?
|
||||
|
||||
- Using the formula for combinations with repetition:
|
||||
$$
|
||||
\binom{12 + 4 - 1}{4} = \binom{15}{4} = 1365
|
||||
$$
|
||||
|
||||
---
|
||||
|
||||
## The Pigeonhole Principle
|
||||
|
||||
If $n$ items are placed into $m$ containers and $n > m$, at least one container must hold more than one item.
|
||||
|
||||
- If there are 13 pigeons and 12 pigeonholes[^6], at least one hole must contain more than one pigeon.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Recurrence Relations
|
||||
|
||||
A recurrence relation defines a sequence by relating each term to previous terms.
|
||||
|
||||
- The Fibonacci sequence is defined by:
|
||||
$$
|
||||
F(n) = F(n - 1) + F(n - 2)
|
||||
$$
|
||||
with initial conditions $F(0) = 0$ and $F(1) = 1$.
|
||||
|
||||
### Solving Recurrence Relations
|
||||
|
||||
1. Backtracking[^7]: Repeatedly substitute the recurrence relation to find a pattern.
|
||||
|
||||
|
||||
2. Linear Homogeneous[^8] Recurrence Relations:
|
||||
These have the form:
|
||||
$$
|
||||
a_n = c_1 a_{n-1} + c_2 a_{n-2} + \ldots + c_k a_{n-k}
|
||||
$$
|
||||
"Homogeneous" means there is no constant term (e.g., no $+ b$ at the end).
|
||||
|
||||
- Solution: Solve the characteristic equation:
|
||||
$$
|
||||
r^k - c_1 r^{k-1} - c_2 r^{k-2} - \ldots - c_k = 0
|
||||
$$
|
||||
The roots $r$ determine the general form of the sequence.
|
||||
|
||||
[^1]: Permutations without repetition mean that each object can be used only once in the arrangement.
|
||||
[^2]: Permutations with unlimited repetition mean objects can repeat any number of times.
|
||||
[^3]: Limited repetition adjusts for identical items that are indistinguishable.
|
||||
[^6]: The pigeonhole principle is a basic observation about "fitting" items into containers.
|
||||
[^7]: Backtracking solves recurrences by substituting values until a pattern emerges.
|
||||
[^8]: Linear homogeneous recurrence relations depend only on earlier terms, without constants.
|
163
Discrete Structures/Mathematical Data Structures.md
Normal file
163
Discrete Structures/Mathematical Data Structures.md
Normal file
@ -0,0 +1,163 @@
|
||||
---
|
||||
type: theoretical
|
||||
---
|
||||
|
||||
## Sets
|
||||
|
||||
A **set** is an unordered collection of unique objects (elements) with no duplicates.
|
||||
|
||||
### Notation
|
||||
- $x \in A$: "x is an element of set A."
|
||||
- $x \notin A$: "x is not an element of set A."
|
||||
|
||||
### Intervals of $\mathbb{R}$
|
||||
An **interval** is a subset of $\mathbb{R}$ (the real numbers) defined by two endpoints $a$ and $b$. Any real number between $a$ and $b$ belongs to the interval.
|
||||
|
||||
### Cardinality
|
||||
The **cardinality** of a set $S$ is the number of elements it contains, denoted $|S|$.
|
||||
- **Finite Set**: A set with a finite number of elements. Example: $S = \{a, b, c\}$, $|S| = 3$.
|
||||
- **Infinite Set**: A set that is not finite. Example: $\mathbb{N}, \mathbb{Z}, \mathbb{R}$.
|
||||
- **Power Set**: For a finite set $S$, the cardinality of its power set $P(S)$ (set of all subsets of $S$) is $2^{|S|}$.
|
||||
|
||||
**Example**: For $S = \{a, b, c\}$, $P(S)$ contains $8 = 2^3$ subsets.
|
||||
|
||||
---
|
||||
|
||||
## Set Operations
|
||||
|
||||
Let $U$ be the universal set, and let $A$ and $B$ be subsets of $U$:
|
||||
|
||||
- **Union**: $A \cup B = \{x \mid x \in A \lor x \in B\}$
|
||||
- **Intersection**: $A \cap B = \{x \mid x \in A \land x \in B\}$
|
||||
- **Set Difference**: $A \setminus B = \{x \mid x \in A \land x \notin B\}$
|
||||
- **Complement**: $\bar{A} = U \setminus A$, the set of all elements not in $A$.
|
||||
|
||||
---
|
||||
|
||||
## Proof Styles for Set Properties
|
||||
|
||||
### Annotated Linear Proof (ALP)
|
||||
A **chain-of-equivalences proof** involves showing the equivalence of two sets step by step.
|
||||
|
||||
**Example**: Prove $A \cup (B \cup C) = (A \cup B) \cup C$.
|
||||
|
||||
- Start from $x \in A \cup (B \cup C)$ and simplify:
|
||||
$$
|
||||
x \in A \cup (B \cup C) \iff x \in A \lor (x \in B \lor x \in C) \iff (x \in A \lor x \in B) \lor x \in C \iff x \in (A \cup B) \cup C.
|
||||
$$
|
||||
|
||||
- Conclude that the left-hand side equals the right-hand side.
|
||||
|
||||
---
|
||||
|
||||
## Sequences
|
||||
|
||||
A **sequence** is an ordered list of objects where repetition is allowed, and the order matters.
|
||||
|
||||
### Examples
|
||||
1. Finite sequence: $1, 2, 3, 5, 7$ (length 5).
|
||||
2. Infinite sequence: $0, 2, 4, 6, \ldots$ (continues indefinitely).
|
||||
3. A sequence differs from a set: $1, 2, 3$ is not the same as $3, 2, 1$.
|
||||
|
||||
### Specifying Sequences
|
||||
1. **Recursive Definition**:
|
||||
- Example: $s_0 = 3$, $s_n = 2 \cdot s_{n-1} + 7$, defines $3, 13, 33, \ldots$.
|
||||
2. **Explicit Definition**:
|
||||
- Example: $s_n = n^2$ defines $0, 1, 4, 9, 16, \ldots$.
|
||||
|
||||
---
|
||||
|
||||
## Characteristic Function
|
||||
|
||||
The **characteristic function** of a set $A \subseteq U$ is a function $f_A : U \to \{0, 1\}$:
|
||||
$$
|
||||
f_A(x) =
|
||||
\begin{cases}
|
||||
1, & \text{if } x \in A, \\
|
||||
0, & \text{if } x \notin A.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
### Purpose
|
||||
Characteristic functions represent sets mathematically and are useful for computations.
|
||||
|
||||
**Example**:
|
||||
- $U = \{a, b, c, d, e\}$, $A = \{b, d\}$.
|
||||
- Representation of $U$: $(1, 1, 1, 1, 1)$.
|
||||
- Representation of $A$: $(0, 1, 0, 1, 0)$.
|
||||
|
||||
---
|
||||
|
||||
## Strings and Languages
|
||||
|
||||
### Formal Languages
|
||||
1. **Alphabet ($\Sigma$)**: A non-empty set of symbols (letters).
|
||||
2. **Word (String)**: A finite sequence of symbols from $\Sigma$.
|
||||
- Example: $\Sigma = \{a, b\}$, string: $babab$.
|
||||
3. **Empty String ($\epsilon$)**: A string with no symbols ($|\epsilon| = 0$).
|
||||
4. **Language ($L$)**: A subset of $\Sigma^*$, the set of all possible strings over $\Sigma$.
|
||||
Regex. Used for [Pattern matching](Pattern%20matching.md)
|
||||
### Regular Sets and Expressions
|
||||
1. $\alpha \cdot \beta$ (concatenation): Combine two sets of strings.
|
||||
2. $\alpha | \beta$ (union): Combine strings from either set.
|
||||
3. $\alpha^*$ (Kleene star): All strings formed by repeatedly concatenating elements of $\alpha$.
|
||||
|
||||
**Example**:
|
||||
- Let $L$ correspond to $(a | b)^*(c | \epsilon)$.
|
||||
- True/False:
|
||||
- $abbac \in L$: True.
|
||||
- $abccc \in L$: False.
|
||||
- $abaa \in L$: False.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Integers
|
||||
|
||||
### Primes
|
||||
- **Prime Number**: A positive integer greater than 1 with only two divisors: 1 and itself.
|
||||
- Examples: $2, 3, 5, 7$.
|
||||
- **Euclid's Theorem**: There are infinitely many primes.
|
||||
|
||||
**Proof Sketch**:
|
||||
1. Assume a finite list of primes $p_1, p_2, \ldots, p_n$.
|
||||
2. Let $q = (p_1 \cdot p_2 \cdot \ldots \cdot p_n) + 1$.
|
||||
3. If $q$ is prime, it’s not in the list.
|
||||
4. If $q$ is not prime, it must be divisible by some prime not in the list.
|
||||
|
||||
### Prime Factorization
|
||||
Every integer $n > 1$ can be uniquely expressed as a product of primes:
|
||||
$$
|
||||
n = p_1^{k_1} \cdot p_2^{k_2} \cdot \ldots \cdot p_s^{k_s}.
|
||||
$$
|
||||
|
||||
**Examples**:
|
||||
1. $60 = 2^2 \cdot 3 \cdot 5$.
|
||||
2. $168 = 2^3 \cdot 3 \cdot 7$.
|
||||
|
||||
---
|
||||
|
||||
## Matrices and Boolean Operations
|
||||
|
||||
### Boolean Operations
|
||||
- **OR ($\lor$)**: $a \lor b = \max(a, b)$.
|
||||
- **AND ($\land$)**: $a \land b = \min(a, b)$.
|
||||
|
||||
**Example**: For $a, b \in \{0, 1\}$:
|
||||
- $1 \lor 0 = 1$.
|
||||
- $1 \land 0 = 0$.
|
||||
|
||||
---
|
||||
|
||||
## Mathematical Structures
|
||||
|
||||
### Arity and Notation
|
||||
- **Arity**: The number of arguments an operation takes.
|
||||
- **Unary**: Takes one argument (e.g., complement of a set).
|
||||
- **Binary**: Takes two arguments (e.g., addition: $x + y$).
|
||||
- **Nullary**: Takes no arguments (e.g., constant: $1$).
|
||||
|
||||
**Prefix/Infix/Postfix Notation**:
|
||||
- **Prefix**: Operator first (e.g., $+ x y$).
|
||||
- **Infix**: Operator between arguments (e.g., $x + y$).
|
||||
- **Postfix**: Operator last (e.g., $x y +$).
|
159
Discrete Structures/Mathematical Proofs (Induction).md
Normal file
159
Discrete Structures/Mathematical Proofs (Induction).md
Normal file
@ -0,0 +1,159 @@
|
||||
---
|
||||
type: theoretical
|
||||
---
|
||||
## Proving Equivalences
|
||||
|
||||
To prove that two statements $P$ and $Q$ are equivalent ($P \iff Q$):
|
||||
|
||||
1. ***Chain of Equivalences***:
|
||||
Show that $P(x_1, \ldots, x_n) \iff \ldots \iff Q(x_1, \ldots, x_n)$, transforming $P$ into $Q$ step by step.
|
||||
|
||||
2. ***Bi-conditional***[^10] ***Decomposition***[^1]:
|
||||
Use the fact that:
|
||||
$$
|
||||
(P \iff Q) \iff ((P \implies Q) \land (Q \implies P)).
|
||||
$$
|
||||
- Prove $P \implies Q$ (first direction).
|
||||
- Prove $Q \implies P$ (second direction).
|
||||
|
||||
---
|
||||
|
||||
## Proving Universal Statements
|
||||
|
||||
To prove a statement of the form $\forall x\, P(x)$:
|
||||
|
||||
1. Proof by Exhaustion[^5]:
|
||||
- If the domain of $x$ is finite, verify $P(x)$ for each possible value.
|
||||
|
||||
2. Proof by Universal Generalization[^6]:
|
||||
- Let $c$ be an arbitrary element of the domain.
|
||||
- Prove $P(c)$.
|
||||
- Conclude that $\forall x\, P(x)$ holds.
|
||||
|
||||
**Example**:
|
||||
- For all integers $n$, if $n$ is even, then $n^2$ is even.
|
||||
- ***Proof***:
|
||||
1. Let $n$ be an arbitrary integer.
|
||||
2. Assume $n$ is even. Then $n = 2k$ for some integer $k$.
|
||||
3. Compute $n^2 = (2k)^2 = 4k^2 = 2(2k^2)$, which is even.
|
||||
|
||||
---
|
||||
|
||||
## Proving Existential Statements
|
||||
|
||||
To prove a statement of the form $\exists x\, P(x)$:
|
||||
|
||||
1. Constructive Proof[^7]:
|
||||
Find a specific $c$ such that $P(c)$ is true.
|
||||
|
||||
2. Non-constructive Proof[^8]:
|
||||
- Assume $\forall x\, \neg P(x)$ (negation of existence).
|
||||
- Derive a contradiction.
|
||||
- Conclude that $\exists x\, P(x)$ must be true.
|
||||
|
||||
---
|
||||
|
||||
## Proof by Contraposition
|
||||
|
||||
Instead of proving $P \implies Q$, prove its contrapositive[^3]:
|
||||
$$
|
||||
\neg Q \implies \neg P
|
||||
$$
|
||||
**Example**:
|
||||
- For all $n \in \mathbb{N}$, if $n^2$ is odd, then $n$ is odd.
|
||||
- ***Proof***:
|
||||
1. Prove the contrapositive: If $n$ is even, then $n^2$ is even.
|
||||
2. Assume $n = 2k$. Then $n^2 = (2k)^2 = 4k^2 = 2(2k^2)$, which is even.
|
||||
|
||||
---
|
||||
|
||||
## Proof by Contradiction
|
||||
|
||||
To prove $P$:
|
||||
1. Assume $\neg P$.
|
||||
2. Derive a contradiction[^4].
|
||||
3. Conclude that $P$ must be true.
|
||||
|
||||
**Example**:
|
||||
- $\sqrt{2}$ is irrational.
|
||||
- **Proof**:
|
||||
1. Assume $\sqrt{2}$ is rational, so $\sqrt{2} = \frac{p}{q}$, where $p, q \in \mathbb{Z}$, $q \neq 0$, and $\frac{p}{q}$ is in lowest terms.
|
||||
2. Square both sides: $2 = \frac{p^2}{q^2}$, so $2q^2 = p^2$.
|
||||
3. $p^2$ is even, so $p$ is even ($p = 2k$).
|
||||
4. Substitute $p = 2k$: $2q^2 = (2k)^2 = 4k^2$, so $q^2 = 2k^2$.
|
||||
5. $q^2$ is even, so $q$ is even.
|
||||
6. Contradiction: $p$ and $q$ cannot both be even since $\frac{p}{q}$ is in lowest terms.
|
||||
7. Conclude $\sqrt{2}$ is irrational.
|
||||
|
||||
---
|
||||
|
||||
## Mathematical Induction
|
||||
[^2]
|
||||
|
||||

|
||||
|
||||
To prove a statement of the form $\forall n \geq n_0, P(n)$:
|
||||
|
||||
1. *Base Case*:
|
||||
Prove $P(n_0)$ is true.
|
||||
|
||||
2. *Inductive Hypothesis* - $IH$:
|
||||
Assume $P(k)$ is true for some $k \geq n_0$.
|
||||
|
||||
3. *Inductive Step*:
|
||||
Prove $P(k + 1)$ is true using $P(k)$.
|
||||
|
||||
**Example**:
|
||||
- $1 + 2 + \dots + n = \frac{n(n + 1)}{2}$ for all $n \geq 1$.
|
||||
- ***Proof***:
|
||||
1. Base Case: For $n = 1$, LHS = $1$, RHS = $\frac{1(1 + 1)}{2} = 1$. Holds true.
|
||||
2. $IH$: Assume $1 + 2 + \dots + k = \frac{k(k + 1)}{2}$.
|
||||
3. Inductive Step: Show $1 + 2 + \dots + (k + 1) = \frac{(k + 1)(k + 2)}{2}$.
|
||||
$$
|
||||
\text{LHS} = (1 + 2 + \dots + k) + (k + 1) = \frac{k(k + 1)}{2} + (k + 1).
|
||||
$$
|
||||
Simplify:
|
||||
$$
|
||||
\frac{k(k + 1)}{2} + (k + 1) = \frac{k(k + 1) + 2(k + 1)}{2} = \frac{(k + 1)(k + 2)}{2}.
|
||||
$$
|
||||
Matches RHS.
|
||||
|
||||
---
|
||||
|
||||
## Strong[^9] Mathematical Induction
|
||||
|
||||
To prove $\forall n \geq n_0, P(n)$:
|
||||
|
||||
1. *Base Cases*:
|
||||
Prove $P(n_0), P(n_0 + 1), \ldots, P(n_0 + m)$ are true.
|
||||
|
||||
2. *Inductive Hypothesis*:
|
||||
Assume $P(i)$ is true for all $n_0 \leq i \leq k$.
|
||||
|
||||
3. *Inductive Step*:
|
||||
Prove $P(k + 1)$ is true using the assumption $P(i)$ for all $i \leq k$.
|
||||
|
||||
**Example**:
|
||||
- Every $n \geq 2$ can be factored into primes.
|
||||
- **Proof**:
|
||||
1. *Base Case*: $n = 2$ is a prime.
|
||||
2. $IH$: Assume every $n \leq k$ can be factored into primes.
|
||||
3. *Inductive Step*: For $n = k + 1$:
|
||||
- If $k + 1$ is prime, done.
|
||||
- If composite, $k + 1 = a \cdot b$, where $2 \leq a, b \leq k$.
|
||||
- By hypothesis, $a$ and $b$ can be factored into primes.
|
||||
- Combine the prime factors of $a$ and $b$ to get $k + 1$'s factorization.
|
||||
|
||||
|
||||
|
||||
|
||||
[^1]: Breaking a complex problem into smaller, simpler parts to solve each one step by step
|
||||
[^2]: Proof that works by showing it works for the smallest case, then assuming it works for one number and proving it works for the next
|
||||
[^3]: Instead of directly proving "If A, then B," you prove "If not B, then not A," which means the same thing logically.
|
||||
[^4]: A way of proving something is true by assuming it is false and showing this leads to a logical impossibility, which, as we know, really messes with everything.
|
||||
[^5]: Checking every possible case individually to prove something is true for all of them.
|
||||
[^6]: Showing something is true for all cases by proving it for an arbitrary or random example. Similar to formal proof for introducing the $\forall$ quantifier
|
||||
[^7]: Directly finding an example to show something exists or is true.
|
||||
[^8]: Proving something exists or is true without giving a specific example, usually by ruling out the possibility of it not being true.
|
||||
[^9]: Like induction, but you assume everything is true up to a certain point to prove the next case
|
||||
[^10]: A statement where both directions are true, like "A if and only if B," meaning A leads to B, and B leads to A.
|
115
Discrete Structures/Recurrence relations.md
Normal file
115
Discrete Structures/Recurrence relations.md
Normal file
@ -0,0 +1,115 @@
|
||||
---
|
||||
type: theoretical
|
||||
---
|
||||
|
||||
|
||||
|
||||
A recurrence relation is an equation that defines a sequence based on its earlier terms, along with initial values.
|
||||
|
||||
- The recurrence relation $a_n = a_{n-1} + 4$ with initial condition $a_1 = 3$ defines the sequence: $3, 7, 11, 15, \ldots$.
|
||||
|
||||
### Techniques for Finding Explicit Formulas
|
||||
|
||||
1. ***Backtracking*** involves repeatedly substituting the recurrence relation into itself until a pattern emerges.
|
||||
|
||||
- For the recurrence relation $a_n = a_{n-1} + 4$, we repeatedly substitute:
|
||||
- $a_n = a_{n-1} + 4$
|
||||
- $a_n = (a_{n-2} + 4) + 4 = a_{n-2} + 2 \cdot 4$
|
||||
- $a_n = ((a_{n-3} + 4) + 4) + 4 = a_{n-3} + 3 \cdot 4$
|
||||
- $\ldots$
|
||||
- $a_n = a_{n-(n-1)} + (n-1) \cdot 4 = a_1 + (n-1) \cdot 4 = 3 + (n-1) \cdot 4$
|
||||
|
||||
- So, the explicit formula for the sequence is:
|
||||
$$
|
||||
a_n = 3 + (n-1) \cdot 4
|
||||
$$
|
||||
|
||||
2. ***Characteristic Equation*** applies to linear homogeneous recurrence relations.
|
||||
|
||||
- A **LHR** relation of degree $k$ is of the form:
|
||||
$$
|
||||
s_n = a_1 s_{n-1} + a_2 s_{n-2} + \ldots + a_k s_{n-k},
|
||||
$$
|
||||
where $a_i \in \mathbb{R}$ are constants. [^1]
|
||||
|
||||
- The ***characteristic equation*** is:
|
||||
$$
|
||||
x^k - a_1 x^{k-1} - a_2 x^{k-2} - \ldots - a_k = 0
|
||||
$$
|
||||
|
||||
- The roots of the characteristic equation determine the explicit formula for the sequence. The sources focus on degree-2 relations, but the method generalizes to any degree.
|
||||
|
||||
---
|
||||
|
||||
### Solving Linear Homogeneous Recurrence Relations of Degree 2
|
||||
|
||||
For $s_n = a s_{n-1} + b s_{n-2}$, the characteristic equation is $x^2 - ax - b = 0$. Let $r_1$ and $r_2$ be the roots:
|
||||
|
||||
1. **In case of distinct roots** ($r_1 \neq r_2$):
|
||||
- The general solution is:
|
||||
$$
|
||||
s_n = c_1 r_1^n + c_2 r_2^n,
|
||||
$$
|
||||
where $c_1$ and $c_2$ are constants determined by initial conditions.
|
||||
|
||||
2. **In case of repeated roots** ($r_1 = r_2 = r$):
|
||||
- The general solution is:
|
||||
$$
|
||||
s_n = r^n (c_1 + c_2 n),
|
||||
$$
|
||||
where $c_1$ and $c_2$ are constants determined by initial conditions. [^2]
|
||||
|
||||
---
|
||||
|
||||
## Example - Fibonacci Sequence
|
||||
|
||||
The Fibonacci sequence is defined as:
|
||||
$$
|
||||
f_n =
|
||||
\begin{cases}
|
||||
0, & \text{if } n = 0, \\
|
||||
1, & \text{if } n = 1, \\
|
||||
f_{n-1} + f_{n-2}, & \text{if } n \geq 2.
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
- The characteristic equation is:
|
||||
$$
|
||||
x^2 - x - 1 = 0
|
||||
$$
|
||||
|
||||
- The roots are:
|
||||
$$
|
||||
r_1 = \frac{1 + \sqrt{5}}{2}, \quad r_2 = \frac{1 - \sqrt{5}}{2}.
|
||||
$$
|
||||
|
||||
- Since $r_1 \neq r_2$, the explicit formula is:
|
||||
$$
|
||||
f_n = c_1 r_1^n + c_2 r_2^n.
|
||||
$$
|
||||
|
||||
- Using the initial conditions:
|
||||
- $f_0 = 0 = c_1 + c_2$
|
||||
- $f_1 = 1 = c_1 \left(\frac{1 + \sqrt{5}}{2}\right) + c_2 \left(\frac{1 - \sqrt{5}}{2}\right)$
|
||||
|
||||
- Solving this system, we get:
|
||||
$$
|
||||
c_1 = \frac{1}{\sqrt{5}}, \quad c_2 = -\frac{1}{\sqrt{5}}.
|
||||
$$
|
||||
|
||||
- Therefore, the explicit formula for the Fibonacci sequence is:
|
||||
$$
|
||||
f_n = \frac{1}{\sqrt{5}} \left(\frac{1 + \sqrt{5}}{2}\right)^n - \frac{1}{\sqrt{5}} \left(\frac{1 - \sqrt{5}}{2}\right)^n.
|
||||
$$
|
||||
|
||||
---
|
||||
|
||||
## Verifying Explicit Formulas
|
||||
|
||||
The correctness of an explicit formula for a recurrence relation can be proven using ***strong mathematical induction***. For example, the explicit Fibonacci formula is verified by [Induction](Mathematical%20Proofs%20(Induction).md).
|
||||
|
||||
|
||||
## Footnotes
|
||||
|
||||
[^1]: Linear homogeneous recurrence relations are equations where each term is a combination of earlier terms, with no added constants.
|
||||
[^2]: Repeated roots in a characteristic equation require modifying the solution to include a term that grows linearly with $n$.
|
184
Discrete Structures/Relations and Digraphs.md
Normal file
184
Discrete Structures/Relations and Digraphs.md
Normal file
@ -0,0 +1,184 @@
|
||||
---
|
||||
type: theoretical
|
||||
---
|
||||
|
||||
## Partitions and Cartesian Products
|
||||
|
||||
### Cartesian Product
|
||||
|
||||
The *Cartesian product* of two sets $A$ and $B$ is the set of all ordered pairs where the first element is from $A$ and the second is from $B$:
|
||||
|
||||
$$
|
||||
A \times B = \{ (a, b) \mid a \in A, \, b \in B \}
|
||||
$$
|
||||
|
||||
- If $A = \{1, 2\}$ and $B = \{x, y\}$, then:
|
||||
|
||||
$$
|
||||
A \times B = \{ (1, x), (1, y), (2, x), (2, y) \}
|
||||
$$
|
||||
|
||||
[^1]: The Cartesian product creates pairs from all possible combinations of elements from two sets.
|
||||
|
||||
### Partitions
|
||||
|
||||
A partition of a set $S$ is a collection of non-empty, disjoint subsets $\{S_1, S_2, \dots, S_n\}$ such that:
|
||||
|
||||
- $S = S_1 \cup S_2 \cup \dots \cup S_n$
|
||||
- $S_i \neq \emptyset$ for all $i$
|
||||
- $S_i \cap S_j = \emptyset$ for all $i \neq j$
|
||||
|
||||
[^2]: Partitions divide a set into disjoint subsets that cover the entire set.
|
||||
|
||||
- A partition of $S = \{1, 2, 3, 4\}$ could be $\{\{1, 2\}, \{3, 4\}\}$.
|
||||
|
||||
---
|
||||
|
||||
## Binary Relations
|
||||
|
||||
A binary relation $R$ from set $A$ to set $B$ is a subset of the Cartesian product $A \times B$:
|
||||
|
||||
$$
|
||||
R \subseteq A \times B
|
||||
$$
|
||||
|
||||
- When $A = B$, $R$ is a relation on $A$.
|
||||
|
||||
### Representations of Relations
|
||||
|
||||
#### As [Sets](Mathematical%20Data%20Structures.md)
|
||||
|
||||
A relation can be represented as a set of ordered pairs.
|
||||
|
||||
- $R = \{ (1, 2), (2, 3), (3, 1) \}$
|
||||
|
||||
#### As [Matrices](Matrices.md)
|
||||
|
||||
For a finite set $A = \{a_1, a_2, \dots, a_n\}$, the relation matrix $M_R$ is an $n \times n$ matrix where:
|
||||
|
||||
$$
|
||||
(M_R)_{ij} =
|
||||
\begin{cases}
|
||||
1, & \text{if } (a_i, a_j) \in R \\
|
||||
0, & \text{otherwise}
|
||||
\end{cases}
|
||||
$$
|
||||
|
||||
#### As [Graphs](Graphs.md)
|
||||
|
||||
A digraph (directed graph) represents elements as vertices and relations as directed edges.
|
||||
|
||||
- For $R = \{ (1, 2), (2, 3) \}$, draw vertices for 1, 2, 3, with edges from 1 to 2 and 2 to 3.
|
||||
|
||||
---
|
||||
|
||||
## Properties of Relations
|
||||
|
||||
### Reflexive
|
||||
|
||||
A relation $R$ on set $A$ is *reflexive* if every element is related to itself:
|
||||
|
||||
$$
|
||||
\forall a \in A, \, (a, a) \in R
|
||||
$$
|
||||
|
||||
### Symmetric
|
||||
|
||||
$R$ is *symmetric* if:
|
||||
|
||||
$$
|
||||
\forall a, b \in A, \, (a, b) \in R \implies (b, a) \in R
|
||||
$$
|
||||
|
||||
### Antisymmetric
|
||||
|
||||
$R$ is *antisymmetric* if:
|
||||
|
||||
$$
|
||||
\forall a, b \in A, \, (a, b) \in R \land (b, a) \in R \implies a = b
|
||||
$$
|
||||
|
||||
### Transitive
|
||||
|
||||
$R$ is *transitive* if:
|
||||
|
||||
$$
|
||||
\forall a, b, c \in A, \, (a, b) \in R \land (b, c) \in R \implies (a, c) \in R
|
||||
$$
|
||||
|
||||
### Equivalence Relations
|
||||
|
||||
A relation that is *reflexive*, *symmetric*, and *transitive* is an ***equivalence*** relation.
|
||||
|
||||
- An equivalence relation partitions the set into equivalence classes.
|
||||
|
||||
[^3]: Equivalence relations naturally partition a set into equivalence classes, grouping related elements.
|
||||
|
||||
- For $a \in A$, **the equivalence class** $[a]$ is:
|
||||
|
||||
$$
|
||||
[a] = \{ x \in A \mid (a, x) \in R \}
|
||||
$$
|
||||
|
||||
- The set of all equivalence classes forms a partition of $A$.
|
||||
|
||||
---
|
||||
|
||||
## Operations on Relations
|
||||
|
||||
### Union
|
||||
|
||||
The union of two relations $R$ and $S$ on $A$:
|
||||
|
||||
$$
|
||||
R \cup S = \{ (a, b) \mid (a, b) \in R \text{ or } (a, b) \in S \}
|
||||
$$
|
||||
Unions are used in [Kruskall Algorithm's Union-Find](Graph%20Algorithms.md)
|
||||
### Intersection
|
||||
|
||||
The intersection of $R$ and $S$:
|
||||
|
||||
$$
|
||||
R \cap S = \{ (a, b) \mid (a, b) \in R \text{ and } (a, b) \in S \}
|
||||
$$
|
||||
|
||||
### Composition
|
||||
|
||||
The composition of relations $R$ and $S$ is:
|
||||
|
||||
$$
|
||||
R \circ S = \{ (a, c) \mid \exists b \in A, \, (a, b) \in R \text{ and } (b, c) \in S \}
|
||||
$$
|
||||
|
||||
---
|
||||
|
||||
## Algorithms
|
||||
|
||||
### Warshall's Algorithm
|
||||
|
||||
computes the transitive closure of a relation on a finite set.
|
||||
|
||||
- The smallest transitive relation $R^+$ that contains $R$ is called a **Transitive Closure**.
|
||||
- Determines reachability in graphs; whether there is a path from one vertex to another.
|
||||
|
||||
#### Steps of Warshall's Algorithm
|
||||
|
||||
Given the adjacency matrix $M$ of a relation $R$ on set $A = \{a_1, a_2, \dots, a_n\}$:
|
||||
|
||||
1. Initialize $T^{(0)} = M$.
|
||||
2. For $k = 1$ to $n$:
|
||||
- For $i = 1$ to $n$:
|
||||
- For $j = 1$ to $n$:
|
||||
$$
|
||||
T_{ij}^{(k)} = T_{ij}^{(k-1)} \lor (T_{ik}^{(k-1)} \land T_{kj}^{(k-1)})
|
||||
$$
|
||||
3. After $n$ iterations, $T^{(n)}$ is the transitive closure matrix.
|
||||
|
||||
---
|
||||
|
||||
[^1]: The Cartesian product creates pairs from all possible combinations of elements from two sets.
|
||||
|
||||
[^2]: Partitions divide a set into disjoint subsets that cover the entire set.
|
||||
|
||||
[^3]: Equivalence relations naturally partition a set into equivalence classes, grouping related elements.
|
||||
|
BIN
Discrete Structures/img/induction.png
Normal file
BIN
Discrete Structures/img/induction.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user