\documentclass[tikz,11pt]{article}

\usepackage{amsmath} % Math Symbols
\usepackage{latexsym} % Other Symbols
\usepackage{times,mathptm} % Math Times Font
\usepackage{enumitem} % Enumeration
\usepackage{mathpazo} % Math Pazo Font
\usepackage{forest} % Trees
\usepackage{adjustbox} % Align Items

\textwidth 6.5truein          
\textheight 9.1truein
\oddsidemargin 0.0in
\topmargin -0.9in
\thispagestyle{empty} 

\parindent 0pt          
\parskip 0pt

\begin{document}

\begin{large}
\centerline {\bf Computer Science 303}
\centerline {\bf Algorithms}
\centerline {\bf Summer 2026}
\centerline {\bf Assignment 5}
\centerline{\bf Name: } % Your name here
\vskip .5cm

\bf Due: beginning of class, Thursday, 6/18/26
\vskip .5cm
\end{large}
Answer the following questions and submit typeset solutions by the due date.  As stated in the Honor Code on the syllabus, any outside sources must be listed under the corresponding problem.  Further, your final submission must be completely your own work.

\begin{enumerate}
\item {[20 points]}  Hashing\\
Consider a hashing scheme in which the hash table is size 10 with hash function $x$ \% $10$.  Insert the following items, showing the final hash table for each hash method listed below after inserting the following: 44, 74, 33, 13, 2, 63, 64, 36, 14, 53, and 84.  For each, note any elements that cannot be inserted, but continue inserting subsequent elements.

\begin{enumerate}[label=\alph*.]
    \item {[5 points]} separate chaining
    \item {[5 points]} linear probing
    \item {[5 points]} quadratic probing ($i \leq 5$)
    \item {[5 points]} double hashing with secondary hash function: $h(x) = 7 - (x$ \% $7)$
\end{enumerate}

\vskip 0.7cm
\item {[15 points]}  Hashing with Separate Chaining using Binary Search Trees\\
Consider a hash table similar to separate chaining, but instead of defining the head of a linked list at each location, we have a link to the root of a binary search tree.
\begin{enumerate}[label=\alph*.]
    \item {[10 points]} Show the result of inserting 44, 74, 33, 13, 2, 63, 64, 36, 14, 53, 84, and 4, one at a time, into the hash table.  Show the hash table with binary trees after each inserted item.  Assume a hash table of size 10 with has function $x$ \% $10$.
    \item {[4 points]} Assuming an even distribution of $N$ keys across $M$ entries in the hash table, as in the course slides, what is the cost of a search in the worst case?  In the average case?
\end{enumerate}

\item {[10 points]}  Cuckoo Hashing\\
Use cuckoo hasing to insert the following items, in alphabetical order, into two hash tables with six elements each:

\begin{table}[h]
    \centering
    \begin{tabular}{|c|c|c|} \hline 
         A&  1& 4\\ \hline 
         B&  1& 2\\ \hline 
         C&  2& 0\\ \hline 
         D&  2& 2\\ \hline 
         E&  3& 4\\ \hline 
         F&  3& 5\\ \hline 
         G&  5& 0\\ \hline 
         H&  5& 5\\ \hline
    \end{tabular}
\end{table}

\vskip 6cm
\item {[15 points]}  Binary Heaps
\begin{enumerate}[label=\alph*.]
    \item {[10 points]} Show the result of inserting 47, 99, 25, 21, 6, 81, 19, 37, 20, and 2, one at a time, into an initially empty minimum binary heap.  Show the tree after each inserted item.
    \item {[5 points]} Show the layout of the heap elements represented by an array.
\begin{table}[h]
    \centering
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|l|}\hline
 0& 1& 2& 3& 4& 5& 6& 7& 8& 9&10\\\hline
 & & & & & & & & & &\\\hline 
    \end{tabular}
\end{table}
\end{enumerate}

\vskip 0.7cm
\item {[10 points]}  Binary Heaps\\
Delete the minimum in the heap below five times.\\

\begin{forest}
  where level=1{%
    s sep=5em
  }{%
    l sep=0em,
    s sep=5em,
  },
[$12$,circle,draw
[$18$,circle,draw
[$25$,circle,draw [$43$,circle,draw ] [$86$,circle,draw ] ]
[$39$,circle,draw [$57$,circle,draw ] [$60$,circle,draw ] ] ] 
[$15$,circle,draw 
[$44$,circle,draw [$67$,circle,draw ] [,phantom ] ]
[$19$,circle,draw ] ] ]
\end{forest}

\vskip 0.7cm
\item {[20 points]}  Leftist and Skew Heaps\\
\\
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$2$,circle,draw
[$11$,circle,draw
[$12$,circle,draw [,phantom] ]
[$17$,circle,draw [$18$,circle,draw ] [,phantom ] ] ] 
[$5$,circle,draw 
[$8$,circle,draw [$15$,circle,draw ] [,phantom ] ] [,phantom ] ] ]
\end{forest}
\end{adjustbox}\qquad
\hspace{1.5cm}
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$4$,circle,draw
[$9$,circle,draw
[$18$,circle,draw [$31$,circle,draw ] [,phantom ] ]
[$10$,circle,draw ] ] 
[$6$,circle,draw
[$11$,circle,draw [$21$,draw,circle ] [,phantom ] ] [,phantom ] ] ]
\end{forest}
\end{adjustbox}
\\
\begin{enumerate}[label=\alph*.]
    \item {[10 points]} Merge the two leftist heaps in the diagram.
    \item {[10 points]} Merge the two skew heaps in the diagram.
\end{enumerate}

\newpage
\item {[10 points]}  Binomial Queues
Merge the two binomial queues in the figure below.\\
\\
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$13$,circle,draw ]
\end{forest}
\end{adjustbox}\qquad
\hspace{.5cm}
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$23$,circle,draw [,phantom ] [,phantom ] [,phantom ]
[$51$,circle,draw ] [$24$,circle,draw [,phantom ] [$31$,circle,draw ] ] ]
\end{forest}
\end{adjustbox}
\hspace{.5cm}
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$12$,circle,draw [,phantom] [,phantom] [,phantom] [,phantom] [,phantom] [,phantom] [$21$,circle,draw ]
[$24$,circle,draw [,phantom ] [$65$,circle,draw ] ]
[$14$,circle,draw [,phantom ] [,phantom ] [$26$,circle,draw ]
[$16$,circle,draw [,phantom ] [$18$,draw,circle ] ] ] ]
\end{forest}
\end{adjustbox}
\\
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$4$,circle,draw ]
\end{forest}
\end{adjustbox}\qquad
\hspace{.5cm}
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$15$,circle,draw [,phantom ] [,phantom ] [$18$,circle,draw ] ]
\end{forest}
\end{adjustbox}\qquad
\hspace{.5cm}
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$2$,circle,draw [,phantom ] [,phantom ] [,phantom ]
[$11$,circle,draw ] [$29$,circle,draw [,phantom ] [$55$,circle,draw ] ] ]
\end{forest}
\end{adjustbox}
\end{enumerate}
\end{document}
