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 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 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
EECS 336
Design and Analysis of Algorithms
Amortized Analysis
10/28/2014
1
What Is Amortized Analysis?
Amortized analysis is for bounding the performance of a
sequence of n operations rather than that of a single
operation.
Amortized analysis is useful
EECS 336
Design and Analysis of Algorithms
Efficient Reductions
and
Computational Hardness
11/06/2014
1
Key Concepts
1.
2.
3.
4.
Types of Algorithmic Problems
Complexity Classes - P, EXPTIME, NP, co-NP, etc.
Types of Computational Easiness and Hardness
Ef
EECS 336
Design and Analysis of Algorithms
Divide-and-Conquer Recurrences
9/25/2014
1
Divide-and-Conquer + Recursion
Given: an algorithmic problem P.
Given: an input of size n.
Objective: Solve P for this input of size n.
Steps:
If the input is small eno
EECS 336
Design and Analysis of Algorithms
Amortized Analysis
10/23/2014
1
What Is Amortized Analysis?
Amortized analysis is for bounding the performance of a
sequence of n operations rather than that of a single
operation.
Amortized analysis is useful
EECS 336
Design and Analysis of Algorithms
Efficient Reductions
and
Computational Hardness
11/13/2014
1
Polynomial-Time Verification Algorithms
L is a language, i.e., a decision problem.
A polynomial-time verification algorithm V for L is a twoargument al
EECS 336
Design and Analysis of Algorithms
Efficient Reductions
and
Computational Hardness
11/04/2014
1
Key Concepts
1.
2.
3.
4.
Types of Algorithmic Problems
Complexity Classes - P, EXPTIME, NP, co-NP, etc.
Types of Computational Easiness and Hardness
Ef
EECS 336
Design and Analysis of Algorithms
Linear Programming
and
Approximation Algorithms
11/25/2014
1
In-Class Test #3
1.
This test is optional. Its score can be used to replace the score of
one of the first two tests.
2.
Thursday, 12/4/2014.
3.
Closed
EECS 336
Design and Analysis of Algorithms
Greedy Strategies
10/16/2014
1
In-Class Test #1
1. Next Tuesday, 10/21/2014.
2. Closed books, notes, electronic devices, etc.
3. Covers everything that we have assigned for reading,
assigned for problem sets, or
EECS 336
Design and Analysis of Algorithms
Greedy Strategies
10/14/2014
1
In-Class Test #1
1. Next Tuesday, 10/21/2014.
2. Closed books, notes, electronic devices, etc.
3. Covers everything that we have assigned for reading,
assigned for problem sets, or
EECS 336
Design and Analysis of Algorithms
Syllabus and Introduction
9/23/2014
1
Highlights of the Syllabus
Objectives of This Course
We will learn the following skills:
1. how to formulate algorithmic problems
2. how to design algorithms for algorithmic
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) =
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
EECS 336
Design and Analysis of Algorithms
Dynamic Programming
10/9/2014
1
What Is Dynamic Programming?
Dynamic Programming = Table-Based Recursion
Use tables to store results of sub-problems for later re-use
without re-computation.
Tables can be any sh
EECS 336
Design and Analysis of Algorithms
Dynamic Programming
10/7/2014
1
What Is Dynamic Programming?
Dynamic Programming = Table-Based Recursion
Use tables to store results of sub-problems for later re-use
without re-computation.
Tables can be any sh
EECS 336
Design and Analysis of Algorithms
Divide-and-Conquer Strategies
9/30/2014
1
Divide-and-Conquer + Recursion
Given: an algorithmic problem P.
Given: an input of size n.
Objective: Solve P for this input of size n.
Steps:
If the input is small enou
EECS 336
Design and Analysis of Algorithms
Divide-and-Conquer Strategies
10/2/2014
1
Examples of Divide-and-Conquer Strategies
1. order statistics finding the p-th smallest key
(randomized)
2. order statistics finding the p-th smallest key
(deterministic)
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
EECS 336
Homework 7
Shengjie Xue
Problem 1
Show that the problem of determining the satisability of boolean formulas in disjunctive normal form is
polynomial-time solvable.
P roof :
A disjunction is the boolean OR of its clauses, and so it is satisable if
EECS 336
Homework 3
Shengjie Xue
Problem 1
Algorithm of nding a subsequence LCS-WEIGHT(X,Y)
(a)
Input:
(1) a nite alphabet A consisting of k symbols s1, s2 , . , sk
(2)a positive weight wi for each symbol si
(3)two sequences X x1 x2 . xm and Y y1 y2 . yn