Exercise 6.5-1

Illustrate the operation of HEAP-EXTRACT-MAX on the heap \(A = \{15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1\}\).

a.) 6.5-1 Heap a

b.) 6.5-1 Heap b

c.) 6.5-1 Heap c

d.) 6.5-1 Heap d

e.) 6.5-1 Heap e

The following LaTeX code was used to generate heap a:

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

\begin{document}
\begin{tikzpicture}[
  every node/.style = {minimum width = 2em, draw, circle},
  shade/.style = {fill=black!15},
  level/.style = {sibling distance = 50mm/#1}
  ]
  \node {15}
  child {node {13}
        child {node {5}
          child {node {4}}
          child {node {0}}}
        child {node {12}
          child {node {6}}
          child {node {2}}
        }}
  child {node {9}
        child {node {8}
          child {node {1}}
          child [missing]
        }
        child {node {7}}};
\end{tikzpicture}
\end{document}

The following LaTeX code was used to generate heap b:

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

\begin{document}
\begin{tikzpicture}[
  every node/.style = {minimum width = 2em, draw, circle},
  shade/.style = {fill=black!15},
  level/.style = {sibling distance = 50mm/#1}
  ]
  \node [shade] {1}
  child {node {13}
        child {node {5}
          child {node {4}}
          child {node {0}}}
        child {node {12}
          child {node {6}}
          child {node {2}}
        }}
  child {node {9}
        child {node {8}
        }
        child {node {7}}};
\end{tikzpicture}
\end{document}

The following LaTeX code was used to generate heap c:

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

\begin{document}
\begin{tikzpicture}[
  every node/.style = {minimum width = 2em, draw, circle},
  shade/.style = {fill=black!15},
  level/.style = {sibling distance = 50mm/#1}
  ]
  \node {13}
  child {node [shade] {1}
        child {node {5}
          child {node {4}}
          child {node {0}}}
        child {node {12}
          child {node {6}}
          child {node {2}}
        }}
  child {node {9}
        child {node {8}
        }
        child {node {7}}};
\end{tikzpicture}
\end{document}

The following LaTeX code was used to generate heap d:

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

\begin{document}
\begin{tikzpicture}[
  every node/.style = {minimum width = 2em, draw, circle},
  shade/.style = {fill=black!15},
  level/.style = {sibling distance = 50mm/#1}
  ]
  \node {13}
  child {node {12}
        child {node {5}
          child {node {4}}
          child {node {0}}}
        child {node [shade] {1}
          child {node {6}}
          child {node {2}}
        }}
  child {node {9}
        child {node {8}
        }
        child {node {7}}};
\end{tikzpicture}
\end{document}

The following LaTeX code was used to generate heap e:

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

\begin{document}
\begin{tikzpicture}[
  every node/.style = {minimum width = 2em, draw, circle},
  shade/.style = {fill=black!15},
  level/.style = {sibling distance = 50mm/#1}
  ]
  \node {13}
  child {node {12}
        child {node {5}
          child {node {4}}
          child {node {0}}}
        child {node {6}
          child {node [shade] {1}}
          child {node {2}}
        }}
  child {node {9}
        child {node {8}
        }
        child {node {7}}};
\end{tikzpicture}
\end{document}