• 沒有找到結果。

Assignment 9 solution & commentary

N/A
N/A
Protected

Academic year: 2022

Share "Assignment 9 solution & commentary"

Copied!
4
0
0

加載中.... (立即查看全文)

全文

(1)

Assignment 9 solution & commentary

Prepared by Warren Blanchet for the Winter 2004 session of CMPUT 474, taught by professor Joe Culberson at the University of Alberta, Canada version 1.1

Question 1:

Preamble

Marking:

If you got a 1: You understood the question, and your solution had sufficient detail.

If you got a 0: You didn’t understand the question, your answer was too vague, or the solution was otherwise poor.

Key Point:

When the input is encoded in unary, the most trivial algorithm works.

Discussion:

Note that this question uses a unary encoding for numbers, to illustrate that complexity can be hidden in the encoding. In general, it is not reasonable to use a unary encoding for numbers (see Sipser p237).

Note also that 1n denotes ‘1’n: string concatenation and not numerical exponentiation.

Answer (7.8 p272)

Example Answer:

The following Turing machine decides membership in UNARY–PRIMES!=!{1n|!n!

is!prime}:

Given input x:

1. Ensure that the input consists of a string of ones. Reject otherwise.

2. For each number between 2 and n-1, check if it divides n. If it does, reject.

3. Accept.

Note that this runs in O(n), which in this case is O(x), and thus polynomial.

(2)

Question 2:

Preamble

Marking:

If you got a 1: You understood the question, and your solution had sufficient detail.

If you got a 0: You didn’t understand the question, your answer was too vague, or the solution was otherwise poor.

Key Point:

You can solve this problem using dynamic programming.

Answer (7.13 p272)

Example Answer:

To show that P is closed under the star operation, given a Turing machine A in P for a language L, we shall construct a Turing machine A* in P that accepts L*. The dynamic programming solution to this problem will build up a Boolean matrix S where S[i,j] represents whether the substring wi...wj of the input string

w!=!w1...wn is in L.

The Turing machine A* will proceed as follows:

1. If w = e, accept.

2. For i = 1 to n,

2a. Set S[i,i] = 1 if A accepts wi (the single-character substring).

3. For l = 2 to n,

3a. For i = 1 to n - l + 1 3a1. Set j = i + l - 1

3a2. Set S[i,j] = 1 if A accepts wi...wj. 3a3. For k = i to j - 1

3a3a. Set S[i,j] = 1 if S[i,k] and S[k,j]. (Checks for concatenation of previously accepted strings.)

4. If S[1,n] = 1, accept.

This algorithm is polynomial in the input length, as it runs in O(n3) time.

(3)

Question 3:

Preamble

Marking:

If you got a 1: You understood the question, and your solution had sufficient detail.

If you got a 0: You didn’t understand the question, your answer was too vague, or the solution was otherwise poor.

Key Point:

You can solve this problem using dynamic programming again, but the solution is simpler with non-determinism.

Answer (7.14 p272)

Example Answer:

To show that NP is closed under the star operation, given a non-deterministic Turing machine A for a language L, we shall construct a Turing machine A* that accepts L*.

The Turing machine A* will proceed as follows:

1. If w = e, accept.

2. Non-deterministically choose k, the number of substrings to generate.

Thus 1 ≤ k ≤ n.

3. Non-deterministically split w into k substrings.

4. Simulate A on each substring.

5. If A accepts all the substrings, accept.

This algorithm is polynomial in the input length, as it runs O(n) simulations, each taking non-deterministic polynomial time.

(4)

Question 4:

Preamble

Marking:

If you got a 1: You understood the question, and your solution had sufficient detail.

If you got a 0: You didn’t understand the question, your answer was too vague, or the solution was otherwise poor.

Key Point:

You can solve this problem by composing q using powers of 2.

Answer (7.14 p272)

Example Answer:

First, recall the details of a binary encoding of numbers: each bit represents a power of 2, and the sum of these powers in the encoded number. For example, 3 is represented as 21 + 20, and 10 by 23 + 21.

PERM-POWER is accepted by the following Turing machine:

1. Verify that the input is well-formed, and reject if it is not.

2. Copy q into x.

3. Copy the identity permutation into y. The identity permutation does not alter the order of the elements of the argument.

4. For each bit in t, from least to most significant:

4a. If the bit is 1, update y by composing it with x. (y = x(y)) 4b. Update x by composing it with itself. (x = x(x))

5. If y and p are equal, accept, otherwise reject.

Since composition is assumed to be polynomial with respect to the encoding of a permutation, step 4 performs O(log t) polynomial operations. O(log t)

corresponds to O(n) where n is the length of the input, so the algorithm executes in polynomial time.

參考文獻

相關文件

[r]

Here is

[Hint: You may find the following fact useful.. If d is a metric for the topology of X, show that d|A × A is a metric for

[r]

circuit sat: Given a circuit, is there a truth assignment such that the circuit outputs true?. • circuit sat ∈ NP: Guess a truth assignment and then evaluate the

circuit sat: Given a circuit, is there a truth assignment such that the circuit outputs true?.. • circuit sat ∈ NP: Guess a truth assignment and then evaluate the

circuit sat: Given a circuit, is there a truth assignment such that the circuit outputs true?.. • circuit sat ∈ NP: Guess a truth assignment and then evaluate the

Remark: All the sequences are sequence of real numbers.. Formula that might be useful: Let θ