Algorithm Design and Analysis Homework #5
Due: 14:20 December 20, 2012
Homework submission instructions
• Submit your programming assignment (problem 1) to the Judgegirl System (http://katrina.csie.ntu.edu.tw/judgegirl/). Also, use SVN to commit your report (named “report.pdf”) in the same folder of your code.
• Submit the answer of the writing problems by one of the following ways:
1. Submit an electronic copy to the CEIBA system before the deadline; or 2. Submit a hard copy right before the class on the day of the deadline.
If you submit by both ways, the TA will randomly select only one of them for grading.
• Please make sure that you write down your name and school ID in the header of your documents. Otherwise, the TA will not grade them.
• If you choose to submit the answers of the writing problems via CEIBA, please combine the answers of all writing problems into only one file in the pdf format, with the file name in the format of “hw5 [ID].pdf” (e.g. “hw5 b99902010.pdf”).
Otherwise, the TA will not grade them.
•What should be included in the report:
1. Explain how your program works in detail.
2. Derive the time complexity of your program and briefly explain why. No need for formal proof.
3. The reference of your report.
• If you are stuck with any problem, you are welcome to ask the TAs via e-mails or in person during the office hour. The TA may discuss with you and give you some useful hints. :D
Problem 1 – Puzzle
Description
There are 16 sliding tiles inside a 4 × 4 frame, each with a number from 0 to on it (hexadecimal). Four buttons, , ଵ, ଶ, ଷ, are on the right of the frame. The ( + 1)-th row will rotate right by one tile when is pressed, i.e., every tile in that row will move to the location on its right, except the rightmost tile, which will move to the leftmost location in that row. Another four buttons, , ଵ, ଶ, ଷ, are at the bottom. Similarly, the ( + 1)-th column will rotate down by one tile when is pressed, i.e., every tile in that column will move to the location below it, except the bottommost tile, which will move to the topmost location in that column.
Given an arrangement of the tiles, please find an optimal solution (fewest number of moves) to rearrange the tiles in order by pressing buttons.
Input
Four lines containing four hexadecimal digits in each line, representing the initial configuration of the frame. The neighboring digits are separated by one space character ‘ ‘.
The input is always legal, i.e., each of the digits from 0 to occurs exactly once in the given input data.
Output
Output an integer , the minimum number of steps required to reach the goal, in the first line. Then the next lines should show the sequence of buttons that should be pressed to move the tiles from the initial configuration to the final configuration with all tiles in proper order.
If there are two or more optimal solutions, choose the one with minimum lexicographic order.
Sample Input 1 5 3 0
4 9 6 7 8 E A B D 2 F C
Sample Output
3 C1 R0 R3
Hint
Use an A*/IDA* algorithm to solve this problem. Please look for relevant information on the Internet; this is an algorithm that is commonly taught in an Artificial Intelligence course. Being able to learn an algorithm all by yourself from the information you found is cool, don’t you think? :P
Grade
Judge result (10%) Report & code (10%)
In the report, please also explain/show that your algorithm can indeed produce the optimal solution, i.e., generate a solution with the
minimum number of steps.
Problem 2 – New Policeman’s Confusion
From a police station located on a straight road which is infinite in both directions, a thief has stolen a police car. A while later, a policeman discovers the car is missing and starts to pursue the thief on foot. His maximum running speed equals to two times the maximum speed of the car.
However, he knows neither in which direction the thief has gone nor how long ago the car was stolen.
1) (5%) Design a strategy for the policeman to catch the thief in finite time.
2) (5%) If actually the thief stole the car T seconds ago(but the policeman doesn’t know it). For your strategy, please analyze the running time of the policeman, in terms of T, to catching the thief.
3) (5%) Besides the possibility of the car being stolen by a thief, think of another possibility: the car has disappeared from the world due to some natural miracle power! Due to this possibility, the police now want to know whether there is a thief or not in finite time. Does your previous strategy help? Why?
Problem 3 – NP’s Closure
Let , ∈ be two languages that are in the complexity class .
Show that the following languages still belong to :
1) (5%) ଵ = (Complement operation)
2) (5%) ଶ = = {| ∈ , ∈ } (Concatenation operation)
Now, consider , ∈ be two languages that are in the complexity class . Show that the following languages also belong to :
3) (10%) ଷ = ∪ ∈ (Union operation) 4) (10%) ସ = ∗ = ∪ ∪
ଶ ∪
ଷ ∪ … (Kleene star operation)
Problem 4 – Numerous Purchase Coupons
Let us revisit the problem ‘money’ in HW4 again. The time complexity of your solution is probably () or (). For the following, you can choose either of these two time complexities as the time complexity of your algorithm.
Recall that the input contains:
//The total value of the coupons
//The number of kinds of items
ଵ, ଵ, ଵ; … ; ே, ே, ே //Number of item, price of buying, price for sale Where 0 ≤ , , ≤ for all = 1,2. . . Assume that we can encode
1) (10%) Let be the input length of the ‘money’ problem. Give an asymptotically upper bound of in terms of , , i.e., find a (, ) such that = ((, )). Make your bound as tight as possible.
2) (10%) Is your dynamic-programming algorithm for the ‘money’ problem really a polynomial-time algorithm? Explain your answer.
Problem 5 – Sorry, I am a NPC.
The warrior LostEclipse0721 and the magician ~*MisaCookie*~ visited a NPC’s(non-player character) home and found valuable stuffs. The number
, the values of these stuffs ଵ, ଶ, … ே, and a weapon price are given as the input. Now they are facing two problems:
~*MisaCookie*~:“I wonder that whether these stuffs can be divided into two partitions — one for you and the other for me — such that the total values of each partition are exactly same.(1)”
LostEclipse0721:“I must enhance my weapon before fighting the next boss. So I’d like to take some stuffs whose total values are exactly . The remaining part is yours. However, does such partition really exist?(2)”
1) (5%) Assume we have an algorithm 2 that can solve 2. Please design a reduction algorithm to transform an instance of a 1 problem into an instance of a 2 problem. What is the time complexity of your reduction algorithm?
2) (10%) Conversely, you are given an algorithm 1 for solving 1 . Please design an algorithm to solve 2 by using 1.
3) (Bonus 5%) Please prove that the two problems mentioned above are polynomial-time reducible to the ‘money’ problem in HW4.