Algorithm Design and Analysis Homework #6 Due: 1pm, Monday, January 9, === Homework submission instructions ===

Similar documents
Lecture 7: NP-Complete Problems

Page 1. CSCE 310J Data Structures & Algorithms. CSCE 310J Data Structures & Algorithms. P, NP, and NP-Complete. Polynomial-Time Algorithms

Reductions & NP-completeness as part of Foundations of Computer Science undergraduate course

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

Why? A central concept in Computer Science. Algorithms are ubiquitous.

CMPSCI611: Approximating MAX-CUT Lecture 20

Midterm Practice Problems

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Problem Set 7 Solutions

Exponential time algorithms for graph coloring

CSC 373: Algorithm Design and Analysis Lecture 16

Chapter. NP-Completeness. Contents

Bicolored Shortest Paths in Graphs with Applications to Network Overlay Design

Complexity Theory. IE 661: Scheduling Theory Fall 2003 Satyaki Ghosh Dastidar

AI: A Modern Approach, Chpts. 3-4 Russell and Norvig

Introduction to Logic in Computer Science: Autumn 2006

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA === Homework submission instructions ===

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

An Introduction to The A* Algorithm

Tutorial 8. NP-Complete Problems

Approximation Algorithms

Discrete Mathematics Problems

NP-complete? NP-hard? Some Foundations of Complexity. Prof. Sven Hartmann Clausthal University of Technology Department of Informatics

One last point: we started off this book by introducing another famously hard search problem:

OHJ-2306 Introduction to Theoretical Computer Science, Fall

Guessing Game: NP-Complete?

P versus NP, and More

CAD Algorithms. P and NP

NP-Completeness and Cook s Theorem

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Scheduling Shop Scheduling. Tim Nieberg

International Journal of Advanced Research in Computer Science and Software Engineering

Near Optimal Solutions

Heuristic Methods. Part #1. João Luiz Kohl Moreira. Observatório Nacional - MCT COAA. Observatório Nacional - MCT 1 / 14

Cycle transversals in bounded degree graphs

SIMS 255 Foundations of Software Design. Complexity and NP-completeness

Introduction to NP-Completeness Written and copyright c by Jie Wang 1

Universality in the theory of algorithms and computer science

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

5.1 Bipartite Matching

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

Lecture 1: Course overview, circuits, and formulas

1 Definitions. Supplementary Material for: Digraphs. Concept graphs

Nan Kong, Andrew J. Schaefer. Department of Industrial Engineering, Univeristy of Pittsburgh, PA 15261, USA

Definition Given a graph G on n vertices, we define the following quantities:

Introduction to Algorithms. Part 3: P, NP Hard Problems

Weighted Sum Coloring in Batch Scheduling of Conflicting Jobs

Small Maximal Independent Sets and Faster Exact Graph Coloring

Introduction to Graph Theory

Algorithm Design and Analysis

3. The Junction Tree Algorithms

On the Unique Games Conjecture

Random Map Generator v1.0 User s Guide

! X is a set of strings. ! Instance: string s. ! Algorithm A solves problem X: A(s) = yes iff s! X.

Theoretical Computer Science (Bridging Course) Complexity

Notes on NP Completeness

The chromatic spectrum of mixed hypergraphs

ARTICLE IN PRESS. European Journal of Operational Research xxx (2004) xxx xxx. Discrete Optimization. Nan Kong, Andrew J.

Reading 13 : Finite State Automata and Regular Expressions

Arithmetic Coding: Introduction

THE PROBLEM WORMS (1) WORMS (2) THE PROBLEM OF WORM PROPAGATION/PREVENTION THE MINIMUM VERTEX COVER PROBLEM

On the independence number of graphs with maximum degree 3

Consistent Query Answering in Databases Under Cardinality-Based Repair Semantics

Solutions to Homework 6

Labeling outerplanar graphs with maximum degree three

On the Relationship between Classes P and NP

Weighted Sum Coloring in Batch Scheduling of Conflicting Jobs

Analysis of Algorithms, I

Graph Theory Problems and Solutions

GRAPH THEORY LECTURE 4: TREES

Institut für Informatik Lehrstuhl Theoretische Informatik I / Komplexitätstheorie. An Iterative Compression Algorithm for Vertex Cover

Data Structures and Algorithms Written Examination

CHOOSING THE BEST HEURISTIC FOR A NP-PROBLEM

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Connected Identifying Codes for Sensor Network Monitoring

A Working Knowledge of Computational Complexity for an Optimizer

2048 is NP-Complete. Ahmed Abdelkader Aditya Acharya Philip Dasler. Theorem GAME is NP-Complete.

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Boulder Dash is NP hard

Exact Polynomial-time Algorithm for the Clique Problem and P = NP for Clique Problem

Ph.D. Thesis. Judit Nagy-György. Supervisor: Péter Hajnal Associate Professor

Generating models of a matched formula with a polynomial delay

Approximated Distributed Minimum Vertex Cover Algorithms for Bounded Degree Graphs

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

The Classes P and NP

Cpt S 223. School of EECS, WSU

Regular Expressions and Automata using Haskell

Chapter 6: Graph Theory

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

CSE 4351/5351 Notes 7: Task Scheduling & Load Balancing

Diversity Coloring for Distributed Data Storage in Networks 1

Sample Questions Csci 1112 A. Bellaachia

A Fast Algorithm For Finding Hamilton Cycles

Web Data Extraction: 1 o Semestre 2007/2008


Outline 2.1 Graph Isomorphism 2.2 Automorphisms and Symmetry 2.3 Subgraphs, part 1

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

Satisfiability and Resiliency in Workflow Systems

Outline Introduction Circuits PRGs Uniform Derandomization Refs. Derandomization. A Basic Introduction. Antonis Antonopoulos.

Lecture 16 : Relations and Functions DRAFT

Transcription:

Algorithm Design and Analysis Homework #6 Due: 1pm, Monday, January 9, 2012 === Homework submission instructions === Submit the answers for writing problems (including your programming report) through the CEIBA system (electronic copy) or to the TA in R432 (hard copy). Please write down your name and school ID in the header of your documents. You also need to submit your programming assignment (problem 1) to the Judgegirl System(http://katrina.csie.ntu.edu.tw/judgegirl/). Each student may only choose to submit the homework in one way; either all as hard copies or all through CEIBA except the programming assignment. If you submit your homework partially in one way and partially in the other way, you might only get the score of the part submitted as hard copies or the part submitted through CEIBA (the part that the TA chooses). If you choose to submit the answers of the writing problems through CEIBA, please combine the answers of all writing problems into only one file in the doc/docx or pdf format, with the file name in the format of hw6 [student ID].{pdf,docx,doc} (e.g. hw6 b99902010.pdf ); otherwise, you might only get the score of one of the files (the one that the TA chooses). For each problem, please list your references (they can be the names of the classmates you discussed the problem with, the URL of the information you found on the Internet, or the names of the books you read). The TA can deduct up to 100% of the score assigned to the problems where you don t list your references. Problem 1. (40%) The n-puzzle problem. The n-puzzle is a sliding puzzle which consists of a frame of numbered square tiles in random order with one tile missing. If the size is 3x3, then the puzzle is called the 9-puzzle and if 4x4, the puzzle is called the 16-puzzle. The goal of the puzzle is to place the tiles in order by making sliding moves (horizontally or vertically, but not diagonally) that use the empty space. 1

The following example shows a sequence of legal moves from an initial board configuration to the desired board configuration for a 9-puzzle. 1 3 1 3 1 2 3 1 2 3 1 2 3 4 2 5 4 2 5 4 5 4 5 4 5 6 7 8 6 7 8 6 7 8 6 7 8 6 7 8 Finding one solution is relatively easy. However, it has been shown that finding the shortest solution (the solution with the minimum number of moves) is NP-hard. In this programming assignment, we ask you to write a program to solve this NP-hard problem. We will now describe a classic solution to the problem, which illustrates a general artificial intelligence methodology known as the A* algorithm. In the A* algorithm, we always pick the one board configuration which seems most likely to be the one that leads to the shortest solution to evaluate. For the n-puzzle, it works as follows. First, insert the starting board configuration into a priority queue. Then, delete the board configuration with the minimum priority from the queue. It will turn into several new board configuration after moving a tile into the empty space; we put all possible new board configurations after one move back to the priority queue. Repeat this procedure until the board configuration dequeued represents desired board configuration. The key question is how we determine the likelihood of one board configuration being the one that leads to the shortest solution. A heuristic based on the Manhattan distance between the current board configuration and the desired board configuration can be used for this purpose, and can be calculated for a particular board configuration c as the following: n 1 h(c) = ( x i x i + ȳ i y i ) (1) i=1 where x i and ȳ i are the x and y coordinates of the i-th tile in the desired board configuration, and x i and y i are the x and y coordinates of the i-th tile in the current board configuration. Note that h(c) is a lower bound of the number of moves from the current board configuration c to the desired board configuration. Then the priority of a board 2

configuration when inserting into the priority queue is given by: p(c) = h(c) + ɛ(c) (2) where ɛ(c) is the actual number of moves (or, cost) used by the program to reach board configuration c from the starting board configuration. One thing to note is that not all problems are solvable, i.e., some initial board configurations cannot be altered to reach the desired board configurations by any number of moves. However, we will make sure that all the input data sets which we use to test your program are solvable. Your program should follow the input and output formats specified below. Input The first line has n. The board is n n in size. 3 2 n 10 2. The next n lines show the initial board configuration. The number are separated by a single space character. The tiles are numbered from 1 to n 1. The empty tile is represented by a single @ character. Output The number m in one line. m = the number of moves in the shortest solution. Sample Input and Output (input) 3 @ 1 3 4 2 5 7 8 6 (output) 4 Please write a program to solve the n-puzzle problem (25%). Please also submit a report (10%) which includes a technical specification of your program, which helps the TA to understand your program. In addition, please answer the following questions in your report. 3

Suppose that we replace the Manhattan distance heuristic with a different one, which is no longer a lower bound of the number of moves from the current board configuration to the desired board configuration. Can we still guarantee that the A* algorithm will generate a shortest solution? Please explain. (5%) (bonus problem) Can you modify your algorithm to make sure that in the case that the input given to your program is not solvable, your program will be able to output -1 (indicating that the problem is not solvable) in polynomial time? Please explain. (bonus 10%) Sol: To be announced later. Problem 2. Please spend some time to read the NP-Completeness course material we covered in the class so far (section 34.1 and 34.2 in the textbook). Then solve the following to problems: a. (15%) Show that the class P, viewed as a set of languages, is closed under union, intersection, concatenation, complement, and Kleene star. That is, if L 1, L 2 P, then L 1 L 2 P, L 1 L 2 P, L 1 L 2 P, L 1 P, and L 1 P (Problem 34.1-6 in the textbook). Sol: (1) L 1 L 2 P Since L 1 and L 2 are both in P, there exists machines M 1 and M 2 which decides L 1 and L 2, respectively. Design a machine M 3 which takes w as input as the following: M 3 (w) : 1 Run M 1 with input w. If M 1 accepts w, then accept. 2 Run M 2 with input w. If M 2 accepts w, then accept. It is clear that M 3 accepts w if and only if M 1 or M 2 accepts w and M 3 runs in polynomial time. 4

(2) L 1 L 2 P Since L 1 and L 2 are both in P, there exists machines M 1 and M 2 which decides L 1 and L 2, respectively. Design a machine M 3 which takes w as input as the following: M 3 (w) : 1 Run M 1 with input w. If M 1 accepts w, then run M 2 on w, else reject. 2 If M 2 also accepts w, then accept, else reject. It is clear that M 3 accepts w if and only if both M 1 and M 2 accepts w and M 3 runs in polynomial time. (3) L 1 L 2 P Since L 1 and L 2 are both in P, there exists machines M 1 and M 2 which decides L 1 and L 2, respectively. Design a machine M 3, which takes w = a 1 a 2 a n with each a i Σ as input, as the following: M 3 (w) : 1 For i = 0, 1, 2,..., n 2 Run M 1 with input w 1 = a 1 a 2...a i and run M 1 with input w 2 = a i+1 a i+2...a n. If both M 1 and M 2 accepts w, then accept. 3 If none of the iterations in Stage 2 accept, then reject. It is clear that M 3 accepts w if and only if w = w 1 w 2, where M 1 accepts w 1 and M 2 accepts w 2. Also, M 3 runs in polynomial time. (4) L 1 P Since L 1 is in P, there exists machines M 1 that decides L 1. Design a machine M 2 which takes w as input as the following: 5

M 2 (w) : 1 Run M 1 with input w. If M 1 accepts w, then reject, else accept. It is clear that M 2 accepts w if and only if M 1 rejects w, and M 2 runs in polynomial time. (5) L 1 P Since L 1 is in P, there exists machines M 1 that decides L 1. By using dynamic programming, a machine M 2 that decides L 1 in polynomial time, which takes w = w 1 w 2...w n as input, can be constructed as follows: M 2 (w) : 1 if w = ɛ, then accept 2 for i = 1 to n 3 for j = 1 to n 4 A[i, j] = 0 5 for i = 1 to n 6 set A[i, j] = 1 if w i L 1 7 for l = 2 to n 8 for i = 1 to n l + 1 9 j = i + l 1 10 set A[i, j] = 1 if w i...w j L 1 11 for k = i to j 1 12 set A[i, j] = 1 if A[i, k] = 1 and A[k, j] = 1 13 if A[1, n] = 1 then accept 14 else reject Since each step takes polynomial time and there are O(n 3 ) steps in it, it takes polynomial time for M 2 to decide L 1. b. (9%) Prove that P co-np (Problem 34.2-9 in the textbook). co-np is the set of 6

languages L such that L NP. Sol: Let M 1 be the machine which decides L, where L P. For any x / L, design a machine M 2 which accepts x in polynomial time as follows: M 2 (x) : 1 Run M 1 with input x. If M 1 rejects x, then accept. Therefore, L NP, and thus L co-np. Problem 3. (24%) Solve problem 34.3 on p.1103 in the textbook. The description for you to understand problem c and d is illustrated in Figure 1. Sol: a. First, we randomly choose a vertex in r V and color it with 0, then we can do a BFS starting from r to color on graphs so that every child of a node v V is colored differently than the color of v itself. By checking whether every adjacent pair of nodes has exactly two different colors, we can decide on whether the graph is 2-colorable or not. b. Given an undirected graph G and an integer k, the decision version of the graphcoloring problem is to determine whether there exists a function c : V {1, 2,..., k} such that c(u) c(v) for every edge (u, v) E. Suppose the decision problem is solvable in polynomial time. Run the decision algorithm for at most V times to ask whether G is r-colorable, starting from r = 1 to V. Once the algorithm returns TRUE at the i-th iteration, then the minimum number of colors needed to color G must be i. On the other direction, suppose that the graph-coloring problem is solvable in polynomial time. Run the algorithm to find the minimum number r such that G is r- colorable. Then given any k N, we can determine whether G is k-colorable by examining whether k is larger or equal than r. 7

c. Let k = 3 and run our algorithm for solving the decision problem in part b. Then given any undirected graph G = (V, E), G is 3-colorable if and only if G is k-colorable. Since 3-COLOR is NP-complete, the decision problem must be NP-complete as well. d. Since each literal and its negation must be colored distinctly by colors other than c(red), they must be colored by c(true) and c(false), one for each. We can also see that there exists a 3-coloring of the graph containing just the literal edges by coloring it in this way. e. Here we label the nodes in the widget as follows: x7 y7 z7 a7 d7 b 7 e7 f 7 TRUE If each of x, y and z is colored c(true) or c(false), to prove that at least one of x, y and z is colored c(true), it suffices to show that c(x), c(y) and c(z) cannot all be c(false). Suppose on the contrary, we can see from the widget that (1) if c(a) = c(true), then c(b) = c(false) c(d) = c(true) c(e) = c(red); (2) if c(a) = c(red), then c(b) = c(true) c(d) = c(false) c(e) = c(red). In either of the above two cases, there is no way to color the node f appropriately. Hence the widget is not 3-colorable, and vice versa. f. Combining the results in part d and part e to construct the graph for each clause in the given 3-CNF, we can see that the 3-CNF is satisfiable if and only if the corresponding graph is 3-colorable, thus we get a polynomial-time reduction from 3-CNF-SAT to 3-COLOR. Since 3-CNF-SAT is NP-complete, 3-COLOR is also NP-complete. Problem 4. (12%) A graph G 1 = (V 1, E 1 ) is said to be isomorphic to a graph G 2 = (V 2, E 2 ) if there exists a one-to-one correspondence f : V 1 V 2 such that for any two 8

vertices u and v of G 1, (u, v) E 1 if and only if (f(u), f(v)) E 2. That is, u and v are adjacent in G 1 if and only if f(u) and f(v) are adjacent in G 2. The subgraph-isomorphism problem takes two undirected graphs G 1 and G 2, and it asks whether G 1 is isomorphic to a subgraph of G 2. Show that the subgraph-isomorphism problem is NP-complete. Hint: This problem is related to the clique problem (Section 34.5.1 on p.1086-1089 in the textbook). Sol: We can reduce this problem to the clique problem. Given an undirected graphs G 2, let G 1 = K i, which is the complete graph of i vertices, where i G 2. Then G 1 is the subgraph of G 2 if and only if G 2 has a clique of size i. By the above problem reduction, it is clear that if the clique problem can be solved in polynomial time, the the subgraph isomorphism problem can be solved in polynomial time. Since the clique problem is NP-complete, the subgraph isomorphism problem is also NP-complete. 9

Figure 1: Clarification of some descriptions in Problem 3 10