Practice Midterm Exam 2 - Algorithm Design | CS 1510, Exams of Computer Science

Material Type: Exam; Professor: Pruhs; Class: ALGORITHM DESIGN; Subject: Computer Science; University: University of Pittsburgh; Term: Fall 2007;

Typology: Exams

Pre 2010

Uploaded on 09/02/2009

koofers-user-hgj
koofers-user-hgj 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 1510 Midterm 2
Fall 2007
1. (20 points) Consider the following problem. The input consists of npositive integers V=
{v1,...,vn}. Let L=Pn
i=1 vi. The problem is to determine if there are three disjoint subsets
S,Pand Tof Vsuch that
X
viS
vi=Y
viP
vi=X
viT
v3
i
That is, no element of Vcan be in more than one of S,Pand T. You want the sum of the
numbers in Sto be equal to the product of the numbers in P, and equal to the sum of the
cubes of the numbers in T. It is okay for a number to be in none of S,Por T. Give an
algorithm for this problem whose running time is polynomial in nand L.
2. (20 points)
(a) Explain how to solve the Parallel Prefix Problem on an EREW machine in time O(log n)
on input of size nwith nprocessors. Start with defining the Parallel Prefix Problem.
(b) What is the efficiency of the algorithm in the previous subproblem? Start with a def-
inition of efficiency. You need not have solved the previous subproblem to answer this
question.
(c) What would the Folding Principle say about the time for the algorithm in the first
subproblem if there were only n1/4processors? Start with a definition of the Folding
Principle. You need not have solved the first subproblem to answer this question.
(d) Explain how to solve the Parallel Prefix Problem on an EREW machine in time O( log n)
on input of size nwith n/ log nprocessors.
3. (20 points)
(a) Explain how to find the maximum of nnumbers in time O(1) on an CRCW-common
machine with n2processors.
(b) Explain how to find the maximum of nnumbers in time O(log l og n) on an CRCW-
common machine with nprocessors.
4. (45 points)
(a) Show that the following CLIQUE problem is NP-hard:
INPUT: A graph Gand an integer k
OUPUT: 1 if Ghas a clique of size k, and 0 otherwise
A clique is a collection of mutually adjacent vertices. Use the fact that the following
INDEPENDENT SET problem is NP-complete.
INPUT: A graph Gand an integer k
OUPUT: 1 if Ghas an independent set of size k, and 0 otherwise
An independent set is a collection of mutually nonadjacent vertices.
pf2

Partial preview of the text

Download Practice Midterm Exam 2 - Algorithm Design | CS 1510 and more Exams Computer Science in PDF only on Docsity!

CS 1510 Midterm 2 Fall 2007

  1. (20 points) Consider the following problem. The input consists of n positive integers V = {v 1 ,... , vn}. Let L =

∑n i=1 vi. The problem is to determine if there are three disjoint subsets S, P and T of V such that (^) ∑

vi ∈S

vi =

∏ vi∈P

vi =

∑ vi ∈T

v i^3

That is, no element of V can be in more than one of S, P and T. You want the sum of the numbers in S to be equal to the product of the numbers in P , and equal to the sum of the cubes of the numbers in T. It is okay for a number to be in none of S, P or T. Give an algorithm for this problem whose running time is polynomial in n and L.

  1. (20 points)

(a) Explain how to solve the Parallel Prefix Problem on an EREW machine in time O(log n) on input of size n with n processors. Start with defining the Parallel Prefix Problem. (b) What is the efficiency of the algorithm in the previous subproblem? Start with a def- inition of efficiency. You need not have solved the previous subproblem to answer this question. (c) What would the Folding Principle say about the time for the algorithm in the first subproblem if there were only n^1 /^4 processors? Start with a definition of the Folding Principle. You need not have solved the first subproblem to answer this question. (d) Explain how to solve the Parallel Prefix Problem on an EREW machine in time O(log n) on input of size n with n/ log n processors.

  1. (20 points)

(a) Explain how to find the maximum of n numbers in time O(1) on an CRCW-common machine with n^2 processors. (b) Explain how to find the maximum of n numbers in time O(log log n) on an CRCW- common machine with n processors.

  1. (45 points)

(a) Show that the following CLIQUE problem is NP-hard:

INPUT: A graph G and an integer k OUPUT: 1 if G has a clique of size k, and 0 otherwise

A clique is a collection of mutually adjacent vertices. Use the fact that the following INDEPENDENT SET problem is NP-complete.

INPUT: A graph G and an integer k OUPUT: 1 if G has an independent set of size k, and 0 otherwise

An independent set is a collection of mutually nonadjacent vertices.

(b) Show that the following problem is NP-hard:

INPUT: A graph G and an integer k OUPUT: 1 if G has a clique of size k and an independent set of size k, and 0 otherwise

Use the fact that both that the CLIQUE and INDEPENDENT SET problems above are NP-complete. This was one of the homework problems. (c) Show that the following problem is NP-hard:

INPUT: A graph G and an integer k OUPUT: 1 if G has a clique of size k or an independent set of size k, and 0 otherwise

Use the fact that both that the CLIQUE and INDEPENDENT SET problems above are NP-complete.