Drawing Sorting Networks

What is a good way to create sorting networks that look like the bottom of this post? A python package or LaTeX template installation package would be highly appreciated.

Grouped network sorting Simple sorting network

+4
source share
1 answer

It is very possible that there are some more specific LaTeX packages for creating such networks, but you can start by looking at TikZ ( manual ). Here's how I (quickly) reproduced the simpler of the two images in your question using TikZ:

\documentclass[tikz,border=5mm]{standalone}

\begin{document}

\begin{tikzpicture}
%\fill [gray!15] (1.5,1.5) -- (2.5,1.5) -- (2.5,2.5) -- (1.5,2.5) -- cycle;
\foreach \a in {1,...,4}
  \draw[thick] (0,\a) -- ++(5,0);
\foreach \x in {{1,2},{1,4},{2,1},{2,3},{3,1},{3,2},{3,3},{3,4},{4,2},{4,3}}
  \filldraw (\x) circle (1.5pt);
\draw[thick] (1,2) -- (1,4);
\draw[thick] (2,1) -- (2,3);
\draw[thick] (3,1) -- (3,2);
\draw[thick] (3,3) -- (3,4);
\draw[thick] (4,2) -- (4,3);
\end{tikzpicture}

\end{document}

enter image description here

( %) - , .

+4

All Articles