Skip to content

Commit bffea67

Browse files
committed
Add a visual explanation of the measure of disorder Exc
1 parent 844bf24 commit bffea67

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

docs/Measures-of-disorder.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ $$
246246

247247
Computes the minimum number of exchanges required to sort $X$, which corresponds to $\lvert X \rvert$ minus the number of cycles in the sequence. A cycle corresponds to a number of elements in a sequence that need to be rotated to be in their sorted position; for example, let $\langle 2, 4, 0, 6, 3, 1, 5 \rangle$ be a sequence, the cycles are $\langle 0, 2 \rangle$ and $\langle 1, 3, 4, 5, 6 \rangle$ so $\mathit{Exc}(X) = \lvert X \rvert - 2 = 5$.
248248

249-
**Warning:** `probe::exc` generally returns a result higher than the minimum number of exchanges required to sort $X$ when it contains *equivalent elements*. This is because extending $\mathit{Exc}$ to *equivalent elements* is a NP-hard problem (see *On the Cost of Interchange Rearrangement in Strings* by Amir et al). The function does handle such elements in some simple cases, but not in the general case.
249+
![Visual representation of the two cycles of exchanges required to sort the aforementioned sequence](images/sorting-exchange-cycles.png)
250+
251+
**Warning:** `probe::exc` generally returns a result greater than the minimum number of exchanges required to sort $X$ when it contains *equivalent elements*. This is because extending $\mathit{Exc}$ to *equivalent elements* is a NP-hard problem (see *On the Cost of Interchange Rearrangement in Strings* by Amir et al). The function does handle such elements in some simple cases, but not in the general case.
250252

251253
| Complexity | Memory | Iterators | Monotonic |
252254
| ----------- | ----------- | ------------- | --------- |
10.8 KB
Loading

tools/sorting-exchange-cycles.tex

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
\documentclass{standalone}
2+
\usepackage{tikz}
3+
\usetikzlibrary {arrows.meta}
4+
\pagestyle{empty}
5+
6+
\begin{document}
7+
\begin{tikzpicture}
8+
9+
\tikzstyle{every node}=[draw,shape=circle,minimum size=0.5cm,inner sep=0pt,anchor=center];
10+
11+
% Draw the splay tree nodes
12+
\node (n0) at (2,0) {0};
13+
\node (n1) at (5,0) {1};
14+
\node (n2) at (0,0) {2};
15+
\node (n3) at (4,0) {3};
16+
\node (n4) at (1,0) {4};
17+
\node (n5) at (6,0) {5};
18+
\node (n6) at (3,0) {6};
19+
20+
21+
\tikzset{every edge/.append style = {-Stealth,dashed,gray}};
22+
23+
% Visitation: normal edition
24+
\path[every node/.style={font=\sffamily\small}]
25+
(n2) edge[out=290,in=240,orange] (n0)
26+
(n0) edge[out=110,in=70,orange] (n2)
27+
(n4) edge[out=290,in=240,teal] (n3)
28+
(n3) edge[out=110,in=70,teal] (n6)
29+
(n6) edge[out=290,in=240,teal] (n5)
30+
(n5) edge[out=110,in=70,teal] (n1)
31+
(n1) edge[out=110,in=70,teal] (n4);
32+
33+
34+
\end{tikzpicture}
35+
\end{document}

0 commit comments

Comments
 (0)