\documentclass{article}
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{fancyheadings,enumerate,xspace,amssymb,algorithm,algorithmic,amsmath}
\pagestyle{fancy}
%\usepackage{cs5114}
% macros useful for handouts and homeworks.
\newcommand{\setcourse}[1]{\newcommand{\course}{#1\xspace}}
\newcommand{\setsem}[1]{\newcommand{\sem}{#1\xspace}}
\newcommand{\setyear}[1]{\newcommand{\myyear}{#1\xspace}}
\newcommand{\sethwnum}[1]{\newcommand{\hwnum}{#1\xspace}}

\setcourse{CS 5114}
\setyear{2018}
\setsem{Fall}
\sethwnum{3}

\chead{\course (\sem): Homework \hwnum}

\newcommand{\reals}{\ensuremath{\mathbb{R}}}
\newcommand{\solution}[1]{\textbf{Solution:} #1}
\newcommand{\cut}[1]{\ensuremath{\mathnormal{cut}(#1)}}
\newcommand{\calg}{\ensuremath{{\cal G}}\xspace}
\newcommand{\calo}{\ensuremath{{\cal O}}\xspace}

\begin{document}
\title{\vspace{-0.5in}\textbf{Homework \hwnum}}
\author{\course (\sem)}

\date{Assigned on Wednesday, September 19, 2018. \\Submit PDF solutions on Canvas\\ by the
  beginning of class on Wednesday, September 26, 2018.}
\maketitle

\input{instructions}

\newpage

\begin{description}

\item[Problem 1] (15 points) Solve the recurrence $T(n) = T( \lfloor
  \sqrt{n} \rfloor) +
  1$. In words, the $T(n)$ is the running time of an algorithm that
  creates one sub-problem of the size equal to the square root of $n$,
  solves this sub-problem recursively, and spends one more unit of time.
  You can assume that $T(1) = T(2) = 1$ and that $n > 2$ in the
  recurrence relation. Remember to prove your solution by induction,
  even if you use the ``unrolling'' method to guess a solution.

  % \solution{ 

  % }


\item[Problem 2] (30 points) Let $G = (V, E)$ be an undirected connected
  graph and let $c: E \rightarrow \reals^+$ be a function specifying the
  costs of the edges, i.e., every edge has a positive cost. Assume that
  no two edges have the same cost. Given a set $S \subset V$, where $S$
  contains at least one element and is not equal to $V$, let $e_S$
  denote the edge in $E$ defined by applying the cut property to $S$,
  i.e., $$e_S = {\arg \min}_{e \in \cut{S}} c_e.$$ In this
  definition, the function ``$\arg\min$'' is just like ``$\min$'' but returns
  the argument (in this case the edge) that achieves the minimum. Let
  $F$ be set of all such edges, i.e., $F = \{ e_S, S \subset V, S \not=
  \emptyset\}$. In the definition of $F$, $S$ ranges over \emph{all}
  subsets of $V$ other than the empty set and $V$ itself. Answer the following questions, providing proofs for all
  but the first question.

  \begin{enumerate}[(i)]
  \item (5 points) How many distinct cuts does $G$ have? We will use the
    same definition as in class: a cut is a set of edges whose removal
    disconnects $G$ into two or more non-empty connected components. Two cuts
    are distinct if they do not contain exactly the same set of
    edges. For this question, just provide an upper bound.

  \item (8 points) Consider the graph induced by the set of edges in $F$,
    i.e., the graph $G' = (V, F)$. Is $G'$ connected?

  \item (7 points) Does $G'$ contain a cycle?

  \item (5 points) How many edges does $F$ contain?

  \item (5 points) What conclusion can you draw from your answers to the
    previous statements?
  \end{enumerate}


  % \solution{

  % }



\item[Problem 3] (20 points) Consider the version of Dijkstra's
  algorithm shown below written by someone with access to a priority queue data structure that supports
  \emph{only} the \textsc{Insert} and \textsc{ExtractMin}
  operations. Due to this constraint, the difference between this
  version and the one discussed in class is that instead of the
  $\textsc{ChangeKey}(Q, x, d'(x))$ operation in
  Step~\ref{step:change-key}, this version simply inserts the pair
  $(x, d'(x))$ into $Q$. The danger with this algorithm is that a node
  $x$ may occur several times in $Q$ with different values of
  $d'(x)$. Answer the following questions.
  \begin{enumerate}
  \item (6 points) When the algorithm inserts a pair $(x, d_1)$ into
    $Q$, suppose the pair $(x, d_2)$ is already in $Q$. What is the
    relationship between $d_1$ and $d_2$?
  \item (8 points) Using this relationship, how will you fix this
    algorithm? You just have to describe your correction in words, e.g.,
    by saying ``I will add the following command after Step X: \ldots''
    You do not have to prove the correctness of your algorithm.
  \item (6 points) What is the running time of this modified algorithm? Just
    state the bound in terms of the number of nodes $n$ and the number
    of edges $m$ in $G$.
  \end{enumerate}

  
  \begin{algorithm}[H]
    \caption{{\sc Dijkstra's Algorithm($G, l, s$)}}
    \begin{algorithmic}[1]
      % \REQUIRE A set \calg of graphs, $0 \leq \beta,
      % \sigma \leq 1$.
      % \ENSURE All $(\beta, \sigma)$-hyperedges.
      \STATE \textsc{Insert}$(Q, s, 0)$.
      \WHILE{$S \not= V$}
      \STATE $(v, d'(v)) = \textsc{ExtractMin}(Q)$ \label{step:extract-min}
      \STATE Add $v$ to $S$ and set $d(v) = d'(v)$
      \FOR{every node $x \in V - S$ such that $(v, x)$ is an
        edge in $G$} \label{step:outgoing-neighbours}
      \IF{$d(v) + l{(v, x)} < d'(x)$}
      \STATE $d'(x) = d(v) + l{(v, x)}$
      \STATE $\textsc{Insert}(Q, x, d'(x))$ \label{step:change-key}
      \ENDIF
      \ENDFOR
      \ENDWHILE
    \end{algorithmic}
  \end{algorithm}

  % \solution{
  
  % }

\item[Problem 4] (35 points) You return home for the weekend all agog
  with the exciting new ideas you have discovered in the algorithms
  class. You tell your evil twin about the Minimum Spanning Tree
  (MST) problem and the clever algorithms for computing it. Your sibling
  pooh poohs your new-found wisdom and proposes the following simple
  algorithm on to compute the MST of an undirected graph $G$, assuming
  that no two edges have the same cost.
  \begin{enumerate}
  \item Maintain a set $T$ of edges. Initially $T$ is empty.
  \item Process the edges of $E$ in \emph{any} order.
  \item For each edge $e \in E$,
    \begin{enumerate}
    \item Add $e$ to $T$.
    \item If $T$ contains a cycle, delete $e$ from $T$.
    \end{enumerate}
  \end{enumerate}
  Something seems fishy. Could this algorithm really compute the MST?
  Show up your sibling by fixing the algorithm so that $T$ is indeed the MST
  at the end and prove that the modified algorithm computes the MST of
  $G$. \emph{Notes:} (a) The algorithm is not the same as
  Kruskal's algorithm since it processes the edges in \emph{any}
  order. In contrast Kruskal's algorithm processes the edges in
  increasing order of cost. (b) In your fix, you decide not to sort
  the edges by cost or use any data structure such as the priority queue
  to sort the edges by cost. (c) We are interested only in proving the
  correctness of this algorithm. We are not interested in its running
  time. \emph{Most of the points are for a clear and complete proof of correctness.}\\
  \emph{Hint:} I am providing an elaborate hint here. Your proof of correctness should show that at the end of the algorithm, $T$ is an MST. Therefore, you have to prove all three points implied by the phrase ``Minimum Spanning Tree.'' Prove each of these statements:
  \begin{enumerate}[(a)]
  \item \textbf{$T$ does not contain a cycle.} This proof should be easy.
  \item \textbf{$T$ is spanning, i.e., connects all vertices in $G$.} This part can be challenging. Consider an arbitrary subset $S$ of $V$. It is enough to prove that at the end of the algorithm, $T$ contains at least one edge in $\text{cut}(S)$.\footnote{For every subset $S$, if $T$ contains at least one edge in $\text{cut}(S)$, then $T$ is connected. You may assume this fact.}  As the modified algorithm progresses, what can you show about that edges in $\text{cut}(S)$ that are also in $T$? Informally, I am suggesting that you imagine the algorithm is running in the background while you focus your attention on the edges in  $\text{cut}(S)$. The algorithm will process these edges in some order. Think about this order to show that at the end of the algorithm, $T$ contains at least one edge in $\text{cut}(S)$.
  \item \textbf{$T$ is an MST.} If you have proven the first two parts, then you know that $T$ is a spanning tree. How many edges can it contain? If you modified the algorithm correctly, then what can you say about the edges that you did not include in $T$? Remember that the algorithm has processed every edge in $G$. Now combine what know so far with what you proved in part (v) of Problem 2.
  \end{enumerate} 

  % \solution{
  
  % }
  


\end{description}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
