From 1fb6398fb71d987a82c18867140f9a56c392bd7a Mon Sep 17 00:00:00 2001 From: Krzysztof Wojtas Date: Sun, 22 Sep 2024 03:17:27 +0200 Subject: [PATCH] #225 migrate 6.2-1 --- chapter6/sections/2/1.tex | 14 +++++++++++++- chapter6/sections/2/1.tikz | 5 +++++ chapter6/sections/2/1a.tikz | 24 ++++++++++++++++++++++++ chapter6/sections/2/1b.tikz | 24 ++++++++++++++++++++++++ chapter6/sections/2/1c.tikz | 24 ++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 chapter6/sections/2/1.tikz create mode 100644 chapter6/sections/2/1a.tikz create mode 100644 chapter6/sections/2/1b.tikz create mode 100644 chapter6/sections/2/1c.tikz diff --git a/chapter6/sections/2/1.tex b/chapter6/sections/2/1.tex index a0deb8f..a65abf3 100644 --- a/chapter6/sections/2/1.tex +++ b/chapter6/sections/2/1.tex @@ -1 +1,13 @@ -\workinprogress % TODO +See \refFigure{6.1-2}. +\begin{figure}[htb] + \captionsetup[subfigure]{} + \subcaptionbox{\label{fig:6.1-2a}}[0.5\textwidth]{\input{1a.tikz}} + \subcaptionbox{\label{fig:6.1-2b}}[0.5\textwidth]{\input{1b.tikz}} + \par\vspace{5mm} + \subcaptionbox{\label{fig:6.1-2c}}[0.5\textwidth]{\input{1c.tikz}} + \caption{The operation of $\proc{Max-Heapify}(A,3)$ on the array $A=\langle$27, 17, 3, 16, 13, 10, 1, 5, 7, 12, 4, 8, 9, 0$\rangle$, where $\attrib{A}{heap-size}=14$.\, + \textbf{(a)}\, The element $A[3]$ at node $i=3$ violates the max-heap property, since it is not larger than its left child $A[6]$. + \textbf{(b)}\, After exchanging $A[3]$ with $A[6]$ the max-heap property is restored for node 3, but is destroyed for node 6, because now $A[6]$ is not larger than both children. + In the recursive call $\proc{Max-Heapify}(A,6)$ the elements $A[6]$ and $A[13]$ are swapped, as shown in \textbf{(c)}. + The next recursive call $\proc{Max-Heapify}(A,13)$ just returns without making any further changes to the heap.} \label{fig:6.1-2} +\end{figure} diff --git a/chapter6/sections/2/1.tikz b/chapter6/sections/2/1.tikz new file mode 100644 index 0000000..1ac0d33 --- /dev/null +++ b/chapter6/sections/2/1.tikz @@ -0,0 +1,5 @@ +\tikzset{ + every node/.style = {tan vertex}, + active/.style = {light blue vertex}, + every label/.style = {index}, +} diff --git a/chapter6/sections/2/1a.tikz b/chapter6/sections/2/1a.tikz new file mode 100644 index 0000000..d5e4a87 --- /dev/null +++ b/chapter6/sections/2/1a.tikz @@ -0,0 +1,24 @@ +\input{1.tikz} +\begin{tikzpicture} + \node[label=1] {27} + child {node[label=2] {17} + child {node[label=4] {16} + child {node[label=8] {5}} + child {node[label=9] {7}} + } + child {node[label=5] {13} + child {node[label=10] {12}} + child {node[label=11] {4}} + } + } + child {node[active, label=3, label=right:{$i$}] {3} + child {node[label=6] {10} + child {node[label=12] {8}} + child {node[label=13] {9}} + } + child {node[label=7] {1} + child {node[label=14] {0}} + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/2/1b.tikz b/chapter6/sections/2/1b.tikz new file mode 100644 index 0000000..84977d1 --- /dev/null +++ b/chapter6/sections/2/1b.tikz @@ -0,0 +1,24 @@ +\input{1.tikz} +\begin{tikzpicture} + \node[label=1] {27} + child {node[label=2] {17} + child {node[label=4] {16} + child {node[label=8] {5}} + child {node[label=9] {7}} + } + child {node[label=5] {13} + child {node[label=10] {12}} + child {node[label=11] {4}} + } + } + child {node[label=3] {10} + child {node[active, label=6, label=right:{$i$}] {3} + child {node[label=12] {8}} + child {node[label=13] {9}} + } + child {node[label=7] {1} + child {node[label=14] {0}} + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture} diff --git a/chapter6/sections/2/1c.tikz b/chapter6/sections/2/1c.tikz new file mode 100644 index 0000000..7974aeb --- /dev/null +++ b/chapter6/sections/2/1c.tikz @@ -0,0 +1,24 @@ +\input{1.tikz} +\begin{tikzpicture} + \node[label=1] {27} + child {node[label=2] {17} + child {node[label=4] {16} + child {node[label=8] {5}} + child {node[label=9] {7}} + } + child {node[label=5] {13} + child {node[label=10] {12}} + child {node[label=11] {4}} + } + } + child {node[label=3] {10} + child {node[label=6] {9} + child {node[label=12] {8}} + child {node[active, label=13, label=20:{$i$}] {3}} + } + child {node[label=7] {1} + child {node[label=14] {0}} + child {node[draw=none, fill=none] {} edge from parent[draw=none]} + } + }; +\end{tikzpicture}