\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 1}
\centerline{\bf Name: } % Your name here
\vskip .5cm

\bf Due: beginning of class, Tuesday, 6/9/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.  Use the largest left child for any tree operation requiring a choice of a new root.  All key additions/deletions to any tree should build cumulatively (i.e., do not start with the original tree each time), unless otherwise directed.
\begin{enumerate}
\item {[8 points]}  Consider the following expression tree:\\

\hspace{2cm}\begin{forest}
  where level=1{%
    s sep=5em
  }{%
    l sep=0cm,
    s sep=5em,
  },
[$-$,circle,draw
[$-$,circle,draw [$50$,circle,draw ]
[$*$,circle,draw [$3$,circle,draw ] [$13$,circle,draw ] ] ]
[$*$,circle,draw [$2$,circle,draw ]
[$-$,circle,draw
[$\wedge$,circle,draw [$2$,circle,draw ]
[$/$,circle,draw [$28$,circle,draw ] [$7$,circle,draw ] ] ]
[$5$,circle,draw ] ] ] ]
\end{forest}

\begin{enumerate}[label=\alph*.]
    \item List the nodes as they are encountered in a pre-order traversal
    \item List the nodes as they are encountered in an in-order traversal
    \item List the nodes as they are encountered in a post-order traversal
    \item Evaluate the expression tree
\end{enumerate}
\vskip 0.7cm
\item {[8 points]}  Convert the following post-order expression to an expression tree using the algorithm outlined in the course slides:\par
\hspace{5cm} \texttt{\textbf{3 4 7 2 + 3 / - *}}\\

Show the stack during the execution of the algorithm (items that are pushed onto the stack may be combined in one diagram; however, the stack must be redrawn whenever a pop occurs).

\vskip 0.7cm
\item {[8 points]}  Show the result of inserting 10, 5, 12, 2, 9, 7, 0, 11, 15, 8 into an empty binary search tree.  Show the tree after each insertion.

\vskip 0.7cm
\item {[8 points]}  Prove the following statement by induction on the height of a binary tree: A perfect binary search tree of height $h$ has $2^h$ leaves.

\vskip 0.7cm
\item {[8 points]}  Show the results of inserting 12, 10, 8, 15, 14, 13, 9 into an empty AVL tree. Show the tree after every insertion.

\vskip 0.7cm
\item {[16 points]}  Consider the following splay tree:\\

\begin{forest}
  where level=1{%
    s sep=5em
  }{%
    l sep=0em,
    s sep=5em,
  },
[$10$,circle,draw
[$4$,circle,draw
[$2$,circle,draw [$1$,circle,draw ] [$3$,circle,draw ] ]
[$6$,circle,draw [$5$,circle,draw ]
[$8$,circle,draw [$7$,circle,draw ] [$9$,circle,draw ] ] ] ] 
[$11$,circle,draw [,phantom]
[$12$,circle,draw [,phantom] [$13$,circle,draw ] ] ] ]
\end{forest}

\begin{enumerate}[label=\alph*.]
    \item Show the result of accessing keys 12, 5, 7 in order in the splay tree.  Show the tree after each access.
    \item Starting with the original splay tree above, show the result of deleting keys 4, 12, 7.  Show the tree after each deletion.
\end{enumerate}

\vskip 0.7cm
\item {[10 points]}  Show the result of accessing keys 9, 5, 12 in the splay tree in problem 6 using top-down splay tree access.

\vskip 0.7cm
\item {[8 points]}  Find the values of $M$ and $L$ for a B-tree if the disk block size is 4096, a key uses 16 bytes, a link uses 8 bytes, and a data value uses 128 bytes.  For 1,000,000 values, how many levels would need to be accessed in the worst case?  How many levels would need to be accessed in the best case for a binary search tree?

\vskip 0.7cm
\item {[10 points]}  Show the resulting B-tree, starting with the tree on slide 131 of the B-trees slide set, after each of the following insertions: 67, 71, 77, 75, 45, 47, and 33.  You may abrreviate parts of the tree when they are not changed.

\vskip 0.7cm
\item {[8 points]}  Show the red-black tree using top-down insertion of the following keys: 12, 10, 17, 19, 20, 15, 16, 7, and 3.  Start with an empty tree and show the tree after each insertion.

\vskip 0.7cm
\item {[8 points]}  Show the 2-3-4 tree after inserting the following keys: 12, 10, 17, 19, 20, 15, 16, 7, and 3.  Start with an empty tree and show the tree after each insertion.

\vskip 0.7cm
\item {[6 points]}  Covert the following red-black trees into 2-3-4 trees (squares are red):\\


a. \hspace{7cm} b.\\
\begin{adjustbox}{valign=t}
\begin{forest}
  where level=1{%
    s sep=2em
  }{%
    l sep=0em,
    s sep=2em,
  },
[$15$,circle,draw
[$9$,circle,draw
[$2$,circle,draw [$7$,draw,red ] ]
[$10$,circle,draw ] ] 
[$19$,draw,red [$17$,circle,draw ]
[$25$,circle,draw [$20$,draw,red ] [$28$,draw,red ] ] ] ]
\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,
  },
[$20$,circle,draw
[$8$,circle,draw
[$3$,circle,draw [$6$,draw,red ] ]
[$12$,circle,draw [$16$,draw,red ] ] ] 
[$40$,draw,circle
[$32$,draw,red [$24$,draw,circle ]
[$36$,draw,circle [$37$,draw,red ] ] ]
[$51$,draw,circle ] ] ]
\end{forest}
\end{adjustbox}
\end{enumerate}
\end{document}