\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 4104}
\setyear{2021}
\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 September 23, 2021. \\Submit PDF solutions on Canvas\\ by 11:59pm on September 30, 2021; extended to 11:59pm on October 5, 2021.}
\maketitle

\input{instructions}

% Replace the blanks below with your team-mate's name.
\noindent My team-mate is \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

\begin{description}

\item[Problem 1] (20 points) Solve exercise 5 in Chapter 4 (pages 190--191) of ``Algorithm Design'' by Kleinberg and Tardos. Let's consider a long, quiet country road with house scattered very sparsely along it. (We can picture the road as a long line segment, with an eastern endpoint and a western endpoint.) Further, let's suppose that despite the bucolic setting, the residents of all these houses are avid cell phone users. You want to place cell phone base stations at certain points along the road, so that every house is within four miles of one of the base stations. 

  Give an efficient algorithm that achieves this goal, using as few base stations as possible. Just in case the problem statement is not completely clear, you can assume that the road is the $x$-axis, that each house lies directly on the road, and that the position of each house can be specified by its $x$-coordinate.

  \emph{Hint:} Sort the houses in increasing order of $x$-coordinate. Develop your algorithm now. To design your proof of correctness, follow one of the proof strategies we discussed in class (and present in the textbook) for greedy scheduling problems.

  % \solution{

  % }

\item[Problem 2]  (30 points) Solve exercise 13 in Chapter 4 (pages 194--195) of your textbook. A small business---say, a photocopying service with a single large machine---faces the following scheduling problem. Each morning, they get a set of jobs from customers. They want to do the jobs on their single machine in an order that keeps the customers happiest. Customer $i$'s job will take $t_i$ time to complete. Given a schedule, i.e., an ordering of jobs, let $C_i$ denote the finishing time of job $i$. For example, if job $j$ is the first to be done, we would have $C_j = t_j$, and if job $j$ is done right after job $i$, then $C_j = C_i + t_j$. Each customer $i$ also has a given weight $w_i$ that represents his or her importance to the business. The happiness of customer $i$ is expected to be dependent on the finishing time of $i$'s job. So the company decides to order the jobs to minimize the weighted sum of completion times, $\sum_{i=1}^n w_iC_i$.

    Design an efficient algorithm to solve this problem, i.e., you are given a set of $n$ jobs with a processing time $t_i$ and weight $w_i$ for each job. You want to order the jobs so as to minimize the weighted sum of completion times, $\sum_{i=1}^n w_iC_i$. 

    \emph{Hint:} Try to use one of the techniques we have seen for proving the correctness of greedy algorithms. Working ``backwards'' from what you need to prove might help you to discover the algorithm. Note that the completion times are not part of the input. The algorithm has to compute them. So you cannot sort the jobs by completion time.


  % \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] (30 points) Gasp! Your best friend Will Byers is trapped in \emph{The Upside Down} yet again!! You have to rescue him from the Demogorgon!!! Fortunately, due to his repeated forays into \emph{The Upside Down} in previous years, you have a very good map of this dimension. Will has figured out several hiding spots where the Demogorgon cannot see him; he is currently secreted in one of these spots. Moreover, due to Eleven's %(Yes, she is alive!)
deep sensory perception, you have very good estimates of how safe it is to travel from one hiding spot to another without being devoured by the Demogorgon. Finally, you also know the locations of several interdimensional portals between our world and The Upside Down.

  Using the algo-fu you have gained in CS 4104, you represent \emph{The Upside Down} as an undirected graph $G = (V,E)$, where each node in $V$ is either a hiding place or an interdimensional portal. Every edge $(u,v)$ connects two nodes in $V$. The weight $w(u,v)$ of this edge is the probability that as you go from $u$ to $v$ (or $v$ to $u$, since the edge is undirected), the Demogorgon will not devour you. Clearly, this weight is between $0$ and $1$ since it is a probability. The weight of a path in $G$ is the product of the weights of its edges. This weight denotes the probability that the Demogorgon will not eat you as you traverse this path. With this set up, you formulate the \texttt{OperationSaveWillByers} problem:

  \begin{quote}
    Given an undirected graph $G=(V,E)$, where every edge $(u,v)$ is associated with a weight $w_{u,v}$ that lies between $0$ and $1$, a subset $S \subset V$ of nodes, a node $t$, and a parameter $r$ that also lies between $0$ and $1$, is there any node in $S$ such that the weight of the path from this node to $t$ is at least $r$?
  \end{quote}

  In this dimension (alas, we are back to the real world), your task is to find a problem $X$ that we have discussed in class and use an algorithm $A$ that we developed for $X$ to solve \texttt{OperationSaveWillByers}. You are not allowed to change $A$. However, you can modify $G$ to your heart's content and pass this modified version to $A$. Moreover, you can further manipulate the output to $A$ to obtain a solution for \texttt{OperationSaveWillByers}. In other words, you use $A$ purely as a subroutine without changing its internal steps. \emph{Note:} The Demogorgon will devour all your points if you deviate from these instructions. \emph{Hint:} I set this problem before describing any algorithm for the minimum spanning tree problem.
  


\end{description}

\end{document}

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