Solutions for Test #2
Shimi Zhang
November 19, 2014
Problem 1
Problem 2
In order to show CNF-SAT p 4-CNF-SAT, we can use the fact that CNF-SAT p 3-CNF-SAT
and the transitivity of polynomial-time reducibility.
Then we want to show 3-CNF-SAT p 4-CNF-SAT, in
Solutions for Assignment #3
Shimi Zhang
November 4, 2014
Problem 1
Follow the algorithm described in the CLRS, we can immediately get the result. (But you should
show your calculation procedures.)
3
1
6
d0
2
d1
5
d2
d5
4
d3
7
d6
d7
d4
c = 1 0.12 + 2 (0.14
Solutions to Homework 1
Debasish Das
EECS Department, Northwestern University
[email protected]
1
Problem 1
The algorithm will print GCD and LCM of X and Y.
To prove: GCD(X,Y) is given by x+y while LCM(X,Y) is given by u+v
2
2
Proof: Invariant for GCD
Homework 5
by yunhan hu
Problem 1.
a) Since the instructions INSERT and EXTRACT-MIN take O(lg n) worst-case time, there must be a k,
which satised to the cost of INSERT and EXTRACT-MIN 6k lg n.
The potential function can be (Di) = knilg ni, where ni is th
Homework 7
by yunhan hu
Problem 1.
For a DNF-SAT problem, the input is n boolean variables and m clauses formed by the n boolean variables and
their literals. The DNF-SAT problem is satised i any clauses is satised.
For each clause, we judge whether it is
Homework 4
by yunhan hu
Problem 1.
This algorithm is wrong. I use a very similiar example with the one on the article to show this. I just delete
an element from the tail of set Y. So, X=ABCBDABE and Y=BDCAB. According to the algorithm, steps are
below.
1
Homework 6
by yunhan hu
Problem 1.
Case 1 for binary encoding:
The running time of the algorithm is (n W ), where n is the number of items and W is the capability of the
knapsack. The instance includes the price and weight of each item and the capability
Homework 8
by yunhan hu
Problem 1.
The randomized algorithm is that independently sets each variable to 1 with probability
1
probability 2 , which is a randomized 2 algorithm.
1
2
and to 0 with
Proof.
Since variables are independant on each other, and sin
Northwestern
EECS 336
1
EECS 336
Yue Zhao
Homework 8
Problem 1:
For the randomized algorithm, the independent set where the variable to one with the
probability of , and the variable to zero with the probability of , and in this way, we can se
Northwestern
EECS 336
1
EECS 336
Yue Zhao
Homework 3
Problem 1:
Algorithm:
We denote the table of L(i, j) where each letter has 3 components that are w , l , f which
represent the weight, length, frequency of s1 of the shortest max-weight common subsequen
EECS 336
Homework 1
Shengjie Xue
Problem 1
Modify Problem 3-3 in the textbook by squaring every function in columns 2, 4, and 6. Solve this problem for the functions in
the fourth row. Justify your answers.
(1) All 6 functions: F 1(n) = 2lgn = n, F 2(n) =
EECS 336
Homework 2
Shengjie Xue
Problem 1
(a)
Algorithm of nding the secondary majority element Find(X[n])
Assumption:
(1) n is a power of 2
(2) elements of X[n] cannot be ordered or sorted, but can be compared for equality.
Input:
An array X[n] of objec
N ORTHWESTERN U NIVERSITY,EECS DEPARTMENT EECS336
Assignment One
Qichang Zheng
October 19, 2016
1 P ROBLEM TITLE
(25 points) Modify Problem 3-3 in the textbook by squaring every function in columns 2, 4,
and 6. Solve this problem for the functions in the
EECS 336 Homework One
Yingnan Ma
October 3, 2016
(25 points) Modify Problem 3-3 in the textbook by squaring every function in columns 2, 4,
and 6. Solve this problem for the functions in the fourth row. Justify your answers.
1. The base of a logrithm is a
N ORTHWESTERN U NIVERSITY,EECS DEPARTMENT EECS336
Assignment Fiver
Qichang Zheng
November 7, 2016
1 P ROBLEM TITLE
(a) We denote n i as the number of elements in D i after the i t h operation. As for Binomial
heap, we can suppose that each INSERT or EXTRA
N ORTHWESTERN U NIVERSITY,EECS DEPARTMENT EECS336
Assignment Two
Qichang Zheng
October 10, 2016
1 P ROBLEM TITLE
(25 points) You are given an array X[1.n] of n elements. A majority element of X is defined to be
an element occurring in more than n/2 positi
EECS336 Homework Two
Yingnan Ma
October 10, 2016
1 P ROBLEM TITLE
(25 points) You are given an array X[1.n] of n elements. A majority element of X is defined to be
an element occurring in more than n/2 positions (e.g., if n = 6 or n = 7, a majority elemen
N ORTHWESTERN U NIVERSITY,EECS DEPARTMENT EECS336
Assignment Four
Qichang Zheng
October 31, 2016
1 P ROBLEM TITLE
This greedy approach doesnt seem always producing the best answer.
Consider two pair of strings X="abcccde" and Y="decccab", solving with the
N ORTHWESTERN U NIVERSITY,EECS DEPARTMENT EECS336
Assignment Seven
Qichang Zheng
November 21, 2016
1 P ROBLEM TITLE
DNF is known as a boolean logic formula which is a disjunction of clauses, where the clause is
a conjunction of literals. Therefore, the bo
EECS 336
Homework 6
Shengjie Xue
Problem 1
(a) Dynamic Algorithm for 0-1 Knapsack Problem :
Consider a new table a[i, w], while i means the rst i items, and w is a capacity for those i items. Because
weight of each item is integer, w is also an integer. 0
EECS 336
Homework 7
Shengjie Xue
Problem 1
(a) 2-Approximation Algorithm :
For each Boolean variable xi in formula, assign true to xi with probability 1/2, assign false to xi with probability
1/2. Then calculate the number of clauses satised by this assig
EECS 336
Homework 4
Shengjie Xue
Problem 1
(a) The greedy algorithm in the paper is incorrect.
(b) P roof :
Counter example :
Let X="ABCDBDAAA"; Y="BDAAABD"; If we solve the problem using the greedy algorithm, we would get
a longest common sub-sequence L=
EECS 336
Homework 5
Shengjie Xue
Problem 1
(a) Assume that ni = the number of elements in the min-heap after the i-th operation
Pi
(Di ) = j=1 lg nj .
INSERT:
ni ni1 = 1
(Di ) (Di1 ) = lg(ni )
k=
n
X
n
ci
i=1
1 X
1
=
(ci + (Di ) (Di1 )
n
n i=1
n
1 X
(lg
Northwestern
EECS 336
1
EECS 336
Yue Zhao
Homework 1
Problem 1:
Modify Problem 3-3 in the textbook by squaring every function in columns 2, 4, and 6. Solve this
problem for the functions in the fourth row. Justify your answers.
Actually, I dont understand
Northwestern
EECS 336
1
EECS 336
Yue Zhao
Homework 1
Problem 1:
Part B:
(g1 ( x ) )(g 1 ( x ) represent the upper bound and lower bound respectively of the function
g1 ( x ) .
So f(x) should neither be the upper bound nor the lower bound of
will meet the
Northwestern
EECS 336
1
EECS 336
Yue Zhao
Homework 4
Problem 1:
This algorithm is incorrect.
For example, delete the last A in Y showed in the example of the 2008 paper.
Counter example:
X= ABCBDABE
Y= BDCAB
According to the greedy algorithm in the paper:
Northwestern
EECS 336
1
EECS 336
Yue Zhao
Homework 7
Problem 1:
Correctness, Time Complexity and Proof:
From the definition of the DNF-SAT problem, the input of which is n boolean variables and m
clauses which are formed by the n boolean variables and the
Northwestern
EECS 336
EECS 336
Yue Zhao
Homework 2
Problem 1:
Algorithm:
1: Procedure SECOND-MAJORITY-ELEMENT-(X [1, n])
2:
n=length of X
3:
if n=1 then
4:
return None
else
if n=2 then
return element [1,3] = cfw_X [1], X [2], None
else
n
5: i= ,
2
element