COS 423 Assignment 8: Algorithms - Problem Solutions, Exercises of Algorithms and Programming

Solutions to problems 1-5 from assignment 8 of the theory of algorithms course at princeton university, spring 2005. Topics include hopfield networks, max-cut, and perfect hash functions.

Typology: Exercises

2011/2012

Uploaded on 07/16/2012

santhanakrishnan
santhanakrishnan 🇮🇳

5

(3)

47 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COS 423 Theory of Algorithms Spring 2005
Assignment 8
Answer problems 1–5. Problem 4b is extra credit. This assignment is due Wednesday, May 4 at 12 noon in
CS 207. Collaboration is not permitted. You must work entirely on your own except for the following two
exceptions (i) you are welcome to consult with course staff members and (ii) you may use any of the course
materials. Note that you are not permitted to drop a no-collaboration problem set.
Read Chapter 12 and 13 in Kleinberg-Tardos.
1. Problem 12.1. (Hopfield network and max-cut)
2. A fair coin flip oracle returns heads with probability 1/2 and tails with probability 1/2, and all return
values are independent. Describe how to to generate a random integer uniformly distributed between
0andN1 by a sequence of calls to the fair coin flip oracle. The expected number of oracle calls
should be O(log N).
3. Problem 13.6. (genome mapping)
4. Given a set of elements S, a hash function his perfect if for any uSand vS,wehaveh(u)=h(v)
if and only if u=v. That is, there are no collisions. Perfect hash functions are especially useful if you
know the set Sahead of time, e.g., as an index for a CD version of an enclopedia.
(a) Given a fixed set of melements S, design an algorithm that finds a perfect hash function in O(m2)
expected time.
(b) Given a fixed set of melements S, design an algorithm that finds a perfect hash function in O(m)
expected time and space. Hint: hash into a table of size m, then create msecondary hash tables,
one for each chain in the original hash table.
5. Upon graduation from Princeton, you find yourself working in a research lab. You overhear your
Harvard colleagues making the following dubious statements. Please assert your superior Princeton
education by supplying the appropriate corrections.
(a) Any comparison-based sorting algorithm must make at least O(nlog n) comparisons to sort n
elements.
(b) Composite is a problem in NP, so it is unlikely that there exists a polynomial-time algorithm
for it.
(c) 3Color is an NP-complete problem because 3Color is in NP and 3Color polynomial reduces
to 3Sat.
(d) I just invented a dynamic programming algorithm for the knapsack problem whose running time
is O(nW ), where nis the number of items, and all values and weights are integers between 0 and
W. Since the knapsack problem is NP-complete and my algorithm’s running time is polynomial
in nand W,IveprovenP=NP.
1
docsity.com

Partial preview of the text

Download COS 423 Assignment 8: Algorithms - Problem Solutions and more Exercises Algorithms and Programming in PDF only on Docsity!

COS 423 Theory of Algorithms Spring 2005

Assignment 8

Answer problems 1–5. Problem 4b is extra credit. This assignment is due Wednesday, May 4 at 12 noon in CS 207. Collaboration is not permitted. You must work entirely on your own except for the following two exceptions (i) you are welcome to consult with course staff members and (ii) you may use any of the course materials. Note that you are not permitted to drop a no-collaboration problem set.

Read Chapter 12 and 13 in Kleinberg-Tardos.

  1. Problem 12.1. (Hopfield network and max-cut)
  2. A fair coin flip oracle returns heads with probability 1/2 and tails with probability 1/2, and all return values are independent. Describe how to to generate a random integer uniformly distributed between 0 and N − 1 by a sequence of calls to the fair coin flip oracle. The expected number of oracle calls should be O(log N ).
  3. Problem 13.6. (genome mapping)
  4. Given a set of elements S, a hash function h is perfect if for any u ∈ S and v ∈ S, we have h(u) = h(v) if and only if u = v. That is, there are no collisions. Perfect hash functions are especially useful if you know the set S ahead of time, e.g., as an index for a CD version of an enclopedia.

(a) Given a fixed set of m elements S, design an algorithm that finds a perfect hash function in O(m^2 ) expected time. † (b) Given a fixed set of m elements S, design an algorithm that finds a perfect hash function in O(m) expected time and space. Hint: hash into a table of size m, then create m secondary hash tables, one for each chain in the original hash table.

  1. Upon graduation from Princeton, you find yourself working in a research lab. You overhear your Harvard colleagues making the following dubious statements. Please assert your superior Princeton education by supplying the appropriate corrections.

(a) Any comparison-based sorting algorithm must make at least O(n log n) comparisons to sort n elements. (b) Composite is a problem in NP, so it is unlikely that there exists a polynomial-time algorithm for it. (c) 3Color is an NP-complete problem because 3Color is in NP and 3Color polynomial reduces to 3Sat. (d) I just invented a dynamic programming algorithm for the knapsack problem whose running time is O(nW ), where n is the number of items, and all values and weights are integers between 0 and W. Since the knapsack problem is NP-complete and my algorithm’s running time is polynomial in n and W , I’ve proven P = NP.

docsity.com