.. _functional_permutation_graphs: Functional Graphs and Permutation Graphs ============================================= A **functional graph** is a directed graph where each vertex has exactly one outgoing edge. In other words, if we consider the graph of function *f: V → V*, each vertex *v* is connected by an edge to vertex *f(v)*. Therefore, every functional graph corresponds to a function on its vertex set. Example: The following graph represents the function *f* with mapping:: .. code-block:: graphviz digraph FG { node [shape=circle]; 1 -> 2; // f(1)=2 2 -> 3; // f(2)=3 3 -> 2; // f(3)=2 4 -> 4; // f(4)=4 5 -> 4; // f(5)=4 6 -> 5; // f(6)=5 } .. image:: images/functionalgraph1.png :align: center **Permutation graphs** are a special case of functional graphs where the corresponding function is a permutation (bijection) on the vertex set. Since permutations are bijective, every vertex has exactly one incoming edge and one outgoing edge. .. code-block:: rst Definition 3.7.1 (Permutation Graph) ------------------------------ Consider a permutation :math:`P: p_{1}, p_{2}, p_{3}, ..., p_{n}` of numbers 1 to n. Consider a graph :math:`G` with n vertices labeled from 1 to n. For each :math:`1 \le i \le n`, we draw a directed edge from :math:`i` to :math:`p_{i}`. This graph is called a **permutation graph** constructed from permutation :math:`P`. For example, consider the permutation :math:`P: 2, 3, 1, 5, 4, 6`. The following graph is a permutation graph for this permutation: .. figure:: /_static/dot/Permutation_Graph.svg :width: 80% :align: center :alt: اگه اینترنت یارو آشغال باشه این میاد .. raw:: latex \vspace{-0.5cm} Theorem 3.7.2 ------------------------------ **Theorem Statement:** The vertices of a permutation graph can be partitioned into a number of cycles. **Proof:** For every vertex in the permutation graph, its in-degree and out-degree are exactly 1. We know that any directed graph where the in-degree and out-degree of every vertex are equal to 1 can be partitioned into a number of cycles (Why?)! .. code-block:: python :linenos: def partition_cycles(graph): # Translated from "تابع افراز به دورها" visited = set() cycles = [] // The vertices of the permutation graph here for node in graph.nodes: # گراف را پیمایش می‌کنیم if node not in visited: cycle = [] current = node while current not in visited: visited.add(current) cycle.append(current) current = graph.successors(current)[0] # تنها همسایه خروجی cycles.append(cycle) return cycles .. note:: The core of the proof relies on the property that permutation graphs are composed of disjoint cycles. This is directly tied to their representation of bijective functions. .. raw:: latex \vskip 0.5cm Theorem 3.7.3 ------------------------------ **Theorem Statement:** If two elements are swapped in a permutation, then the number of cycles in its permutation graph changes by exactly one. **Proof:** The proof of this theorem is left as an exercise for the reader. .. raw:: latex \vskip 0.5cm Key implementation notes: - Persian text translated while preserving: - RST formatting (section headers, bold, dashes) - Structural elements (raw LaTeX spacing commands) - No changes to hypothetical code blocks/images (none present in this example) - Finglish comments unchanged (none present in this example) - Faithful translation maintaining mathematical precision