Exercise 7.1-1

Using figure 7.1 as a model, illustrate the operation of PARTITION on the array \(A = \{13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11\}\).

7.1-1 Partition Operation

Mathjax was not up to the challenge for building this table. I used https://www.tablesgenerator.com/ to build the foundation of this table and then expanded upon it with various techniques in order to get the look just right. Here is the final LaTeX code in all its awkward glory:

\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{multirow,hhline}
\newcolumntype{?}{!{\vrule width 1.5pt}}
\begin{document}

\begin{table}[]
\begin{tabular}{llllllllllllll}
\multicolumn{1}{c}{\multirow{2}{*}{a.}} & i & p, j & & & & & & & & & & & r \\ \hhline{~~------------~} 

\multicolumn{1}{c}{} & \multicolumn{1}{l?}{} & \multicolumn{1}{l|}{13} & \multicolumn{1}{l|}{19} & \multicolumn{1}{l|}{9} & \multicolumn{1}{l|}{5} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{b.}} & i & p & j & & & & & & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l?}{} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{19} & \multicolumn{1}{l|}{9} & \multicolumn{1}{l|}{5} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{c.}} & i & p & & j & & & & & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l?}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{9} & \multicolumn{1}{l|}{5} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{d.}} & & p, i & & & j & & & & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{5} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{e.}} & & p & i & & & j & & & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{f.}} & & p & i & & & & j & & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 12} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{g.}} & & p & & i & & & & j & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 12} & \multicolumn{1}{l|}{7} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{h.}} & & p & & & i & & & & j & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 7} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 12} & \multicolumn{1}{l|}{4} & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{i.}} & & p & & & & i & & & & j & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 7} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 4} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 12}  & \multicolumn{1}{l|}{21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{j.}} & & p & & & & i & & & & & j & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 7} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 4} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 12}  & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 21} & \multicolumn{1}{l|}{2} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{k.}} & & p & & & & & i & & & & & j & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 7} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 4} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 2} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 12}  & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 21} & \multicolumn{1}{l?}{6} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{l.}} & & p & & & & & & i & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 7} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 4} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 2} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 6}  & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 12}  & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 21} & \multicolumn{1}{l|}{11} \\ \cline{3-14} 
\rule{0pt}{4ex}  

\multicolumn{1}{c}{\multirow{2}{*}{m.}} & & p & & & & & & i & & & & & r \\ \hhline{~~------------~} 
\multicolumn{1}{c}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 9} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 5} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 8} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 7} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 4} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0} 2} & \multicolumn{1}{l?}{\cellcolor[HTML]{C0C0C0} 6} & \multicolumn{1}{l?}{11}  & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 13} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 19} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B} 12}  & \multicolumn{1}{l?}{\cellcolor[HTML]{9B9B9B} 21} \\ \cline{3-14} 
\rule{0pt}{4ex}  
\end{tabular}
\end{table}
\end{document}