\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[linesnumbered,lined]{algorithm2e}
\usepackage{scrextend}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{amsfonts}
\usepackage{float}
\usepackage{amsfonts}
\usepackage{cleveref}
\newlist{steps}{enumerate}{1}
\setlist[steps, 1]{label = Step \arabic*:}
\newcommand{\inlinemaketitle}{{\let\newpage\relax\maketitle}}
\makeatletter
\renewcommand{\@algocf@capt@plain}{above}% formerly {bottom}
\makeatother
\setlist[enumerate]{listparindent=\parindent}
\newcommand{\lxor}{\oplus}
\newcommand{\limplies}{\rightarrow}
\newcommand{\lbicond}{\leftrightarrow}
\newcommand{\universe}{\mathcal{U}}
\newcommand{\implication}{\ensuremath{P \limplies Q}}
\newcommand{\true}{T}
\newcommand{\false}{F}
\usepackage{cleveref}%[nameinlink]
\crefname{lemma}{Lemma}{Lemmas}
\crefname{proposition}{Proposition}{Propositions}
\crefname{definition}{Definition}{Definitions}
\crefname{theorem}{Theorem}{Theorems}
\crefname{conjecture}{Conjecture}{Conjectures}
\crefname{corollary}{Corollary}{Corollaries}
\crefname{section}{Section}{Sections}
\crefname{appendix}{Appendix}{Appendices}
\crefname{figure}{Fig.}{Figs.}
\crefname{equation}{Eq.}{Eqs.}
\crefname{table}{Table}{Tables}
\crefname{algocf}{Algorithm}{Algorithms}
\title{CS302 - Problem Set 5}
\author{}
\date{}
\parindent=.25in
\begin{document}
\maketitle
\vspace{-2cm}
\begin{enumerate}
\item Suppose you are hosting a music festival, and are trying to decide which bands should play in the prime-time slot. You randomly surveyed 100 of the registered attendees to have them rank the bands who will be at the festival. You have an unlimited number of stages, so you can have many different bands play at the same time. You would like to choose a subset of bands to play during the prime time spot such that (1) most attendees will be excited about at least one of the bands playing in the primetime slot, and also (2) most attendees will \textit{not} be excited about \textit{more than one} of the bands playing in the primetime slot (since these people would really be bummed that they have to make a choice and only see one of the bands that they paid to see). For example, suppose some of the attendees like jazz, and some like metal, but not many people like both jazz and metal. Then you could have the most popular jazz band and the most popular metal band play the prime time slot. This would be better than having both of your jazz bands play during the prime time slot, even if they are both more popular overall than any of the metal bands, because then the metal fans would not have anyone to watch in the prime time slot, and the jazz fans would be annoyed that they would have to pick one of the bands to watch and couldn't see both.
\begin{enumerate}
\item Describe a possible reduction from the Music Festival problem to the Max Weight Independent Set (MWIS) problem. The input to the Music Festival problem is a list of bands and the survey data from the 100 attendees, and the output should be a set of bands to play in the prime time slot. (There is more than one way to do the reduction - you should make choices based on what you think will be best for your music festival.)
\item Explain why the reduction you described gives a good solution to the Music Festival problem. Do you have any ethical or societal concerns?
\item Is the Music Festival problem polynomial time reducible to MWIS?
\item Now that you've figured out who should perform in the prime time slot, how would you pick which bands should perform in the second best time slot?
\end{enumerate}
{
}
{}
\item Suppose you are living in a country that has a coin worth 6 cents, a coin worth 4 cents, and a coin worth 1 cent. This society also values having small wallets, so whenever they make change, they want to use as few coins as possible. For example, if they need to make 8 cents worth of change, they would rather return two 4-cent coins (2 total coins), rather than a 6-cent coin, and two 1-cent coins, (3 total coins). You are tasked with creating a program for cash registers that will help make change using the least number of coins.
\begin{itemize}
\item \textbf{Input:} An integer $n$
\item \textbf{Output:} A list $M=(m_6, m_4, m_1)$ of non-negative integers such that $n=6m_6+ 4m_4+ m_1$ and $C(M)=m_6+m_4+m_1$ is minimized. (Here $m_i$ represents the number of $i$-cent coins that should be returned, and $C(M)$ is the number of coins returned; the output should make the correct change for $n$ while using the fewest number of coins.)
\end{itemize}
\begin{enumerate}
\item \textbf{Challenge:} Design a dynamic programming algorithm to solve this problem by following the same process we went through in class for MWIS. (If you would like guidance continue to the next question).
\item To design a dynamic programming algorithm, we divided up the original
problem into a series of subproblems, each slighly smaller than the first, and
picked as our recurrence object the optimal strategy/solution for each
suproblem. (For MWIS on a line, the subproblems were the graphs $G_i$ and the
recurrence object was $S_i$, the MWIS on $G_i$). Next we thought about options
for a ``final choice'' for our recurrence object that allowed us to come up
with a recurrence for subproblems (for MWIS on a line, we considered $v_n\in
S_n$ and $v_n\notin S_n$). What subproblems, recurrence objects, and final
choices should we use for our coin problem?
\item Create a recurrence relation based on each final choice. Write a brief explanation describing why your recurrence relation is correct.
\item What are the base cases of your recurrence relation?
\item Explain why the recurrence relation you determined makes this problem an appropriate candidate for dynamic programming, rather than a usual recursive algorithm.
\item Based on your recurrence relation from the previous part, create a recurrence relation for the optimal objective function value of subproblems rather than the optimal strategy for subproblems.
\item Using your recurrence relations, fill in the pseudocode below:
\begin{figure}[H]
\centering
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{$n\geq 1$}
\Output{$(m_6,m_4,m_1)$, the optimal number of $6$-, $4$- and $1$-cent coins to make $n$ cents.}
\tcp{Fill in array $A$ such that $A[i]$ is the minimum number of coins needed to create $n$ cents}
$A[0]\gets0$\;
\vspace{3cm}
\tcp{Work backwards through $A$ to get values for $(m_6,m_4,m_1)$, the optimal number of $6$-, $4$- and $1$-cent coins to make $n$ cents.}
$m_{6}\gets 0$\;
$m_{4}\gets 0$\;
$m_{1} \gets 0$\;
$k\gets n$\;
\While{$k\geq 1$}{
\vspace{3cm}
}
return $(m_{6},m_{4},m_{1})$\;
\caption{\texttt{CoinCounter}$(n)$}
\end{algorithm}
\end{minipage}
\end{figure}
\item What is the runtime of your algorithm?
\end{enumerate}
{}
{}
\item
\texttt{Selection}$(A,k)$ finds the $k^\textrm{th}$ smallest element of an array $A$. For example, if $A=[3,11,20,6,7,38]$ and $k=3$, then \texttt{Selection}$(A,k)$ returns $7$. Here is pseudocode for a divide and conquer algorithm for \texttt{Selection}.
Note that in the following pseudocode I index $A$ starting at $1$, not $0$. $A[s,f]$ is the subarray of $A$ from index $s$ to $f$ inclusive of both $s$ and $f$.~\\
\begin{figure}[H]
\centering
\begin{minipage}{.9\linewidth}
\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{An array $A$ of $n$ integers indexed starting at $1$ and an integer $k\in\{1,\dots, n\}$}
\Output{The $k\textrm{th}$ smallest element of $A$.}
$piv\gets \texttt{ChoosePivot}(A)$\;
\texttt{Partition}$(A,piv)$\;
Let $p$ be the index of the pivot after \texttt{Partition}\;
\If{$p=k$}
{
return $A[p]$\;
}
\eIf{$p