Notes/Discrete Structures/Relations and Digraphs.md
2024-12-07 21:07:38 +01:00

4.2 KiB

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) \}

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
  • 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

A relation can be represented as a set of ordered pairs.

  • R = \{ (1, 2), (2, 3), (3, 1) \}

As Matrices

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

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.
  • 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

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.