diff --git a/chapter6/sections/4/1.tex b/chapter6/sections/4/1.tex index a0deb8f..0f71820 100644 --- a/chapter6/sections/4/1.tex +++ b/chapter6/sections/4/1.tex @@ -1 +1,24 @@ -\workinprogress % TODO +See \refFigure{6.4-1}. +\begin{figure}[htb] + \hspace*{-1.5cm} + \begin{minipage}{\textwidth + 1.5cm} + \captionsetup[subfigure]{} + \subcaptionbox{\label{fig:6.4-1a}}[0.33\textwidth]{\input{1a.tikz}} + \subcaptionbox{\label{fig:6.4-1b}}[0.33\textwidth]{\input{1b.tikz}} + \subcaptionbox{\label{fig:6.4-1c}}[0.33\textwidth]{\input{1c.tikz}} + \par\vspace{3ex} + \subcaptionbox{\label{fig:6.4-1d}}[0.33\textwidth]{\input{1d.tikz}} + \subcaptionbox{\label{fig:6.4-1e}}[0.33\textwidth]{\input{1e.tikz}} + \subcaptionbox{\label{fig:6.4-1f}}[0.33\textwidth]{\input{1f.tikz}} + \par\vspace{3ex} + \subcaptionbox{\label{fig:6.4-1g}}[0.33\textwidth]{\input{1g.tikz}} + \subcaptionbox{\label{fig:6.4-1h}}[0.33\textwidth]{\input{1h.tikz}} + \subcaptionbox{\label{fig:6.4-1i}}[0.33\textwidth]{\input{1i.tikz}} + \par\vspace{3ex} + \subcaptionbox{\label{fig:6.4-1j}}[0.33\textwidth]{\input{1j.tikz}} + \end{minipage} + \caption{The operation of \proc{Heapsort} on the array $A=\langle$5, 13, 2, 25, 7, 17, 20, 8, 4$\rangle$.\, + \textbf{(a)}\, The max-heap built by \proc{Build-Max-Heap} in line 1.\, + \textbf{(b)--(i)}\, The max-heap and the nodes removed from it after each call to \proc{Max-Heapify} in line 5.\, + \textbf{(j)}\, The resulting sorted array $A$.} \label{fig:6.4-1} +\end{figure} diff --git a/chapter6/sections/4/1.tikz b/chapter6/sections/4/1.tikz new file mode 100644 index 0000000..774c2d5 --- /dev/null +++ b/chapter6/sections/4/1.tikz @@ -0,0 +1,7 @@ +\setlength{\vertexsize}{1.1em} +\tikzset{ + every node/.style = {light blue vertex}, + discarded/.style = {tan vertex}, + every label/.style = {index}, + level/.append style = {sibling distance=5\vertexsize/#1}, +} diff --git a/chapter6/sections/4/1a.tikz b/chapter6/sections/4/1a.tikz new file mode 100644 index 0000000..304eca6 --- /dev/null +++ b/chapter6/sections/4/1a.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {25} + child {node {13} + child {node {8} + child {node {5}} + child {node {4}} + } + child {node {7}} + } + child {node {20} + child {node {17}} + child {node {2} + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1b.tikz b/chapter6/sections/4/1b.tikz new file mode 100644 index 0000000..ce9bb30 --- /dev/null +++ b/chapter6/sections/4/1b.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {20} + child {node {13} + child {node {8} + child {node {5}} + child {node[discarded, label=right:{$i$}] {25} edge from parent[draw=none]} + } + child {node {7}} + } + child {node {17} + child {node {4}} + child {node {2} + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1c.tikz b/chapter6/sections/4/1c.tikz new file mode 100644 index 0000000..0ebb750 --- /dev/null +++ b/chapter6/sections/4/1c.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {17} + child {node {13} + child {node {8} + child {node[discarded, label=left:{$i$}] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node {7}} + } + child {node {5} + child {node {4}} + child {node {2} + child[missing] + child {node[draw=none, fill=none, label=right:{}] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1d.tikz b/chapter6/sections/4/1d.tikz new file mode 100644 index 0000000..33f2f77 --- /dev/null +++ b/chapter6/sections/4/1d.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {13} + child {node {8} + child {node {2} + child {node[discarded] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node {7}} + } + child {node {5} + child {node {4}} + child {node[discarded, label=left:{$i$}] {17} edge from parent[draw=none] + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1e.tikz b/chapter6/sections/4/1e.tikz new file mode 100644 index 0000000..7be7bcf --- /dev/null +++ b/chapter6/sections/4/1e.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {8} + child {node {7} + child {node {2} + child {node[discarded] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node {4}} + } + child {node {5} + child {node[discarded, label=left:{$i$}] {13} edge from parent[draw=none]} + child {node[discarded] {17} edge from parent[draw=none] + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1f.tikz b/chapter6/sections/4/1f.tikz new file mode 100644 index 0000000..45607b1 --- /dev/null +++ b/chapter6/sections/4/1f.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {7} + child {node {4} + child {node {2} + child {node[discarded] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node[discarded, label=left:{$i$}] {8} edge from parent[draw=none]} + } + child {node {5} + child {node[discarded] {13} edge from parent[draw=none]} + child {node[discarded] {17} edge from parent[draw=none] + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1g.tikz b/chapter6/sections/4/1g.tikz new file mode 100644 index 0000000..5f11893 --- /dev/null +++ b/chapter6/sections/4/1g.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {5} + child {node {4} + child {node[discarded, label=left:{$i$}] {7} edge from parent[draw=none] + child {node[discarded] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node[discarded] {8} edge from parent[draw=none]} + } + child {node {2} + child {node[discarded] {13} edge from parent[draw=none]} + child {node[discarded] {17} edge from parent[draw=none] + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1h.tikz b/chapter6/sections/4/1h.tikz new file mode 100644 index 0000000..ecca8ce --- /dev/null +++ b/chapter6/sections/4/1h.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {4} + child {node {2} + child {node[discarded] {7} edge from parent[draw=none] + child {node[discarded] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node[discarded] {8} edge from parent[draw=none]} + } + child {node[discarded, label=left:{$i$}] {5} edge from parent[draw=none] + child {node[discarded] {13} edge from parent[draw=none]} + child {node[discarded] {17} edge from parent[draw=none] + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1i.tikz b/chapter6/sections/4/1i.tikz new file mode 100644 index 0000000..29d2e8c --- /dev/null +++ b/chapter6/sections/4/1i.tikz @@ -0,0 +1,18 @@ +\input{1.tikz} +\begin{tikzpicture} + \node {2} + child {node[discarded, label=left:{$i$}] {4} edge from parent[draw=none] + child {node[discarded] {7} edge from parent[draw=none] + child {node[discarded] {20} edge from parent[draw=none]} + child {node[discarded] {25} edge from parent[draw=none]} + } + child {node[discarded] {8} edge from parent[draw=none]} + } + child {node[discarded] {5} edge from parent[draw=none] + child {node[discarded] {13} edge from parent[draw=none]} + child {node[discarded] {17} edge from parent[draw=none] + child[missing] + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/4/1j.tikz b/chapter6/sections/4/1j.tikz new file mode 100644 index 0000000..9cb3f72 --- /dev/null +++ b/chapter6/sections/4/1j.tikz @@ -0,0 +1,7 @@ +\input{1.tikz} +\begin{tikzpicture}[ + every node/.style = {}, +] + \matrix[array, row 1/.append style={nodes={fill=tan}}, label=left:{$A$}] { + 2 & 4 & 5 & 7 & 8 & 13 & 17 & 20 & 25 \\}; +\end{tikzpicture}