- Friday January 8

- Read the syllabus
- Join the class group https://piazza.com/pitt/spring2016/cs2150/home
- Problem 3-3 part a. You need not provide justifications for your order. If you aren't able to find a group, you can do this individually. While I encourage you to use LaTex, it is not strictly required for this assignment. You may hand write these solutions.
- Wednesday Janaury 13

- Problem 3-4. For conjectures that are untrue, explain which
reasonable class of functions the statement is true for. For
example, you might say "The statement is untrue in general,
and here is an example. But the statement is true if the
functions are strictly increasing, and here is a proof."

- Consider the following definitions for f(n, m) = O(g(n, m)).
State which definitions are logically equivalent. Fully
justify your answers. Argue about which definition you think
is the best one in the context where f and g are run times of
algorithms and the input size is monotonicaly growing in n and
m ( for example n might be the number of vertices in a graph
and m might be the number of edges in a graph).

- there exists positive constants c, n_0, m_0 such that 0<= f(n, m) <= c * g(n, m) for all (n, m) such that n >= n_0 AND m >= m_0
- there exists positive constants c, n_0, m_0 such that 0<= f(n, m) <= c * g(n, m) for all (n, m) such that n >= n_0 OR m >= m_0
- There exists a constant c> 0 such that lim sup_{n ->
infinity} lim sup_{m -> infinity} f(n,m)/g(n, m) < c.
Note that this means that you first take the limit superior
with respect to m. The result will be a function of just n.
You then take the limit superior of this function with
respect to n. If you don't know what limit superior means,
you can just assume that the limit exists, in which case the
limit and limit superior are the same.

- There exists a constant c> 0 such that lim sup_{m -> infinity} lim sup_{n -> infinity} f(n,m)/g(n, m) < c. Note that on the surface that this definition is different than the last on in that the order that you take the limits is switched.
- There exists a constant c> 0 such that for all but finitely many pairs (m, n) it is the case that f(n,m) < c * g(n, m)
- Friday January 15
- 8.1-3 Give an adversarial strategy and prove that it is
correct.

- 8.1-4. Give an adversarial strategy and prove that it is
correct. Explain the last sentence of the problem statement
from the book, that is, explain why its not rigorous/correct
to simply combine the lower bounds for the individual
subsequences.

- Problem 8-6. For part a and b, is essentially asking you to consider the adversarial strategy that answers so as to maximize the number of the original ways of merging two sorted lists that are consistent with the answer. You will likely find Stirling's approximation for n! useful. For parts c and d, come up with a different adversarial strategy. Explain why the bound that you get use the method proposed in parts a and b isn't as good as the bound you get using an adversarial strategy. That is, in what way are you being too generous to the algorithm in parts a and b?
- Wednesday January 20
- Consider the problem of determining whether a collection of
real numbers x_1 ... x_n is
*nice*. A collection of numbers is*nice*iff the difference between consecutive numbers in the sorted order is at most 1. So (1.2, 2.7, 1.8) is nice, but (1.2, 2.9, 1.8) is not nice since the difference between 1.8 and 2.9 is more than 1. We want to show that every comparison based algorithm to determine if a collection of n numbers is nice requires Omega(n log n) comparisons of the form x_i - x_j <= c, where c is some constant that the algorithm can specify. So if c=0, this is a standard comparison.

- Hint: This is similar to the lower bound for element
uniqueness.

- Another Hint: Consider the (n-1)! permutations pi of {1, ... n} where pi(1)=1, and the corresponding points in n dimensional space. Note that all (n-1)! of these points are nice. Show the midpoint of any pair of these nice points is not nice. Then explain how to use this fact to give an adversarial strategy showing the Omega(n log n) lower bound.
- Friday January 22

- Consider a setting where you have two computer networking
routers A and B. Each router has collected a list L_A and L_B
of IP source addresses for the packets that have passed
through the router that day. An IP address is n bits, and thus
there are 2^n possible IP addresses. Now the two routers want
to communicate via a two-way channel to whether there was some
source that sent a packet through one of the routers, but not
the other. So more precisely, at the end of the protocol
each router should commit to a bit specifying the answer to
this question, and the bits for both routers should be
correct. You can assume that a bit sent on the channel is
guaranteed to arrive on the other end in one time unit. We
want
to consider protocols for accomplishing this goal.

- Consider the following protocol: A sends to B the
list of all of the IP source addresses that it has
seen, B compares A's list to its list, and then B
sends A a 0 bit if the lists are identical and a 1 bit
otherwise. Show that uses protocol above uses n2^n +1 bits
in the worst case. This is a trivial warmup problem.

- Give a protocol that uses 2^n +O(1) bits in the worst case. Another trivial warmup problem.
- Show that there is no protocol that can solve this problem without exchanging any bits. Its obvious that this is true. That isn't the point. The point is to understand what arguments you have to make to make this formally correct.
- Show that there is no protocol that can solve this problem
that involves A sending one bit to B. And no more bits are
exchanged. Again its obvious that this is true. Again that
isn't the point. Again the point is to understand what
arguments you have to make to make this formally correct.
Hint: Ask yourself how should the adversarial strategy
should decide whether this first bit is a 0 or a 1?

- Show that there is no protocol that can solve this problem that involves A sending one bit to B and B replying with one bit to A. And no more bits are exchanged. Again its obvious that this is true. Again that isn't the point. Again the point is to understand what arguments you have to make to make this formally correct.
- Prove that every protocol for this problem must sent 2^n bits for its worst case instance. Of course your argument should involve an adversarial argument.
- Assume that you have a computer networking router that sees
a stream of k IP packets, each with a source IP address
consisting of n bits. The router sees a packet, optionally
records some information in memory, and then passes the packet
on, then sees the next packets, optionsal records some
information in memory, and then passes that packet on,
.... The routers's goal is to always know the IP source
address that it has seen most frequently to date. (The most
obvoius way to accomplish this is to keep a count for each IP
source address seen to date. ) Show that if
k < 2^n then every algorithm must use Omega(k) bits
of memory.

- Hint: This is an "easy" consequence of the previous subproblem, provided that you think about it the right way. Assume that you had a method that solved this problem using o(k) bits of memory. Explain how to use this method to get an algorithm for the previous subproblem that uses less than 2^k bits of communication.
- Monday January 25

- 4-3

- Apply the Master Theorem (Theorem 4.1) whenever
applicable.

- For parts d and f use induction; You will need 2 inductive proofs, one for the upper bound and one for the lower bound.
- Otherwise, draw the recursive call tree and sum up the costs level by level
- 8-4. For part b give an adversarial strategy. For part c, use linearity of expectations in your algorithm analysis.
- Wednesday January 27
- McDonalds is running a Monopoly promotion where every time your order a meal, you get a random ticket from one of m possible ticket types (there are essentially infinitely many tickets of each type). Assume (as is not true in the real promotion) that each of the m tickets types is equally likely. Calculate as accurately as possible (at least to within a multiplicative constant) how many McDonald's meals you would have to eat before you have n different ticket types for 1 <=n <= m. In particular, how many meals do you have to eat before you get all m different ticket types? HINT: Find the Bernoulli trials.
- Consider the problem of finding the largest i numbers in
sorted order from a list of n numbers (see problem 9-1) in the
text. Consider the following algorithm: you consider the
numbers one by one, maintaining an auxilary data structure of
the largest i numbers seen to date. We get various algorithms
depending on what the auxillary data structure is and how one
searches and updates it. For each of the following variations
give the worst-case time complexity as a function of n and i.
For each of the following variations give the average-case
time complexity as a function of n and i under the assumption
that each input permutation is eaully likely. Hint: Use
linearity of expectations. These are all similar and easy if
you look at them the right way.

- The auxillary data structure is an ordered list and you
use linear search starting from the end that contains
the largest number

- The auxillary data structure is an ordered list and you
use linear search starting from the end that contains
the smallest number

- The auxillary data structure is a balanced binary search tree and you use standard log time search, insert and delete operations
- The auxillary data structure is a balanced binary search
tree and you use standard log time insert and delete
operations, but you start your search from the smallest item
in the tree

- Consider the following problem. The input is n disjoint line
segments contained in an L by L square S in the Euclidean
plane. The goal is to partition S into convex polygons so that
every polygon intersects at most one line segment. So it is ok
for a line segment to be in multiple polygons, but each
polygon can intersect at most one line segment.

- Consider the following algorithm that starts with
the polygon S. Let pi be a random permutation of the the
line segments.

- While there is a polygon P that contains more than one
line segment,

- let l be the first line segment in the pi order that
intersects P.

- Now cut P into two polygons using the linear extension
of l (so you extend the line segment l into a line and
then use that to cut P).

- Show that the expected number of resulting polygons is O(n log n).
- Hint: Use linearity of expectations. First ask yourself how the number of polygons is related to the number of times that line segments get cut in the process. Consider to line segments u and v. Let C_{u,v} be a 0/1 random variable that is 1 if the linear extension of u cuts v. Let index(u, v) denote the number of line segments that the linear extension of u hits before hitting v. In other words if you starting walking from u on u's linear extension towards v, the index is how many line segments you cross before hitting v. If you don't hit v, then the index is positive infinity. What is the relationship between the probability that C_{u,v}=1 and index(u, v).
- Monday February 1
- Assume you have a source of random bits. So in one time
unit, this source will produce one random bit (that is 1 with
probability 1/2 independent of other bits). Consider the
problem of outputing a random permutation of the integers from
1 to n. So each of the n! permutations should be produced with
probabiltiy
1/n!.**exactly** - Give an algorithm to solve this problem and show that the expected time of the algorithm is O(n log n). This includes both the time that your algorithm takes, plus 1 unit of time for each random bit used.
- Now assume that there is a limited source of at most n^2
random bits. Show that there is no algorithm that can solve
the problem using expected time O(n^2). Hint: Show the
result for n=3. Why can't you produce a random permutation
of 1, 2, 3 using 9 bits? Then generalize to an arbitrary n.

- Assume that you had to solve the hiring problem at a large
academic institution where effectively you couldn't fire
anyone (note that this is a realistic assumption). Thus once
you hire someone, the game is over.

- Consider the following strategy. Consider the applicants in random order. Interview but do not hire the first k candidates. So k is a parameter to the algorithm. After the first k candidates, hire the first one that is better than all of the first k applicants. You can assume that you can determine an underlying linear order among the candidates interviewed so far.
- Find the probability of hiring the best candidate as a
function of n and k.

- Determine the k that maximizes this probability, and what this maximum probability is for large n
- HINT: There are multiple ways to analyze this, some are much easier than others. So unless you are a bit lucky, the first thing you try may not work easily. 1/e is the best you can do in terms of the probability you hire the best person.
- HINT: See the discussion of hiring is section 5.1 in the text
- Wednesday February 3
- 11-1
- 11-2

- Friday February 5

- You have a sorted array A of containing n real numbers each
selected independently and uniformly at random from the
interval [0, 1]. You have an real x in [0, 1]. The problem is
to find a subarray of size sqrt(n) that contains x.

- Show that the following algorithm solves this problem in O(1) average case time. HINT: Find the Bernoulli trials. Figure out how to think about the outcome of this algorithm in terms of the number of successes/failures in some Bernoulli trials. Use a Chernoff tail bound. See appendix C.5 or here. HINT: You can use the result of exercise C.5-6 without proof.
- last= x*n
- if A[last] < x then

- next= last + sqrt(n)
- while A[next] < x do

- last=next
- next= next + sqrt(n)
- else if A[last] > x
- next= last - sqrt(n)
- while A[next] > x d0
- last=next
- next= next - sqrt(n)
- Return x lies between positions next and last
- Explain how to use the above algorithm to obtain an algorithm with O(log log n) average case running time for the searching problem (finding the exact location of x in A).
- Monday February 8

- The purpose of this problem is to develop a version of Yao's technique for Monte Carlo randomized algorithms, within the context of the red and blue jug problem from problem 8-4 in the text. Assume that if you sorted the jugs by volume, that each permutation is equally likely.
- Show that if a deterministic algorithm A always stops in o(n log n) steps, then the probability that A is correct for large n is less than 1 percent.
- Show if there is a distribution of the input on which no deterministic algorithm with running time A(n) is correct with probability > 1 percent, then there is no Monte Carlo algorithm with running time A(n) that can be correct with probability > 1 percent. Hint: Mimic the proof of Yao's technique/lemma for the case of Las Vegas algorithms. Consider a two dimensional table/matrix T, where entry T(A, I) is 1 if algorithm A is correct on input I, and 0 otherwise.
- Conclude that any Monte Carlo algorithm for this jug problem must have time complexity Omega(n log n).
- Wednesday February 10

- Consider the following online problem. You given a sequence
of bits b_1, ... b_n over time. Each bit is in an envelope.
You first see the envelope for b_1, then the envelope for b_2,
.... When you get the i^th envelope, you can either look
inside to see the bit, or destroy the envelope (in which case
you will never know what the bit is). You know a priori
that at least n/2+1 of the bits are 1. You goal is to find an
envelope containing a 1 bit. You want to open as few envelopes
as possible.

- Give a deterministic algorithm that will open at most n/2
+ O(1)envelopes. HINT: This is completely straight-forward.

- Show that every deterministic algorithm must open at least n/2 - O(1) envelopes. HINT: This is completely straight-forward.
- Assume that each of the n! permutations of the inputs is
equally likely. Show that there is a deterministic algorithm
where the expected number of envelopes that is opens is
O(1). HINT: This is a straight-forward consequence of some
facts that we learned about Bernoulli trials.

- Give a Monte Carlo algorithm that opens O(log n) envelopes
and has probability of error < 1/n. You must show
that the probability of error is small. HINT: This is a
straight-forward consequence of some facts that we learned
about Bernoulli trials.

- Show using the version of Yao's technique for Monte Carlo
algorithms that you developed in the last homework
assignment to show that every Monte Carlo algorithm must
open Omega(log n) envelopes if it is to be incorrect with
probability < 1/n. HINT: This is a straight-forward
application of the Yao's technique for Monte Carlo
algorithms that you developed in the previous homework
problem.

- Give a Las Vegas algorithm where the expected number of
opened envelopes is O(n^(1/2)).

- Hint: Take some random guesses for the first half of the envelopes, and then if you don't find a 1 bit, give up and do the most obvious thing.
- Hint: See the discussion of the Birthday paradox in section 5.4.1. You may use facts from the analysis of the Birthday paradox in the CLRS text or from the wikipedia page without proof.
- Show that every Las Vegas algorithm for the previous
envelope problem must open Omega(n^{1/2}) envelopes in
expectation.

- Hint: Use Yao's technique and the following probability distribution.
- With probability half, sqrt(n) uniformly distributed random bits in [1,n/2] are set to 1 and the remaining bits in that interval are 0, bits in the interval [n/2 + 1 , n/ 2 + sqrt(n) ] are all set to 0, and the remaining bits are 1.
- For k = 0 , ..., sqrt(n) − 1, with probability 1/(2 sqrt(n)), bits [1 , ..., n/ 2] contains a uniformly distributed random set of k 0's and the rest are 1's. Then sqrt( n) − k 0's are contained in uniformly distributed random bit positions in [ n/ 2 + 1 , n/ 2 + sqrt(n) ], and the remaining k bits in positions [ n/ 2 + 1 , n/ 2 + sqrt(n) n ] are 1's. The remaining bits in the stream are 0.
- Friday February 12
- Problem 16-4 part a. Hint: https://www.youtube.com/watch?v=z4fo9sxzuWk
- Extra credit: Explain the hint.

- Problem 16-5 part c. The obvious exchange works, but the proof of optimality is a bit subtle.
- Monday February 15
- Problem 16-2. You don't need to give running times, just prove correctness. Hint: For part (a) the most obvious exchange works. For part (b), the most obvious exchange does not work (if you think your first idea works, probably you need to rethink).
- 15-4
- 15-5
- Wednesday February 17
- 15-2
- 15-3
- 15-9
- Friday February 19
- ?