(tree searching technique) (Boolean formulas) satisfying assignment: (X 1, X 2 )

Similar documents
maxz = 3x 1 +4x 2 2x 1 +x 2 6 2x 1 +3x 2 9 x 1,x 2

min3x 1 + 4x 2 + 5x 3 2x 1 + 2x 2 + x 3 6 x 1 + 2x 2 + 3x 3 5 x 1, x 2, x 3 0.

Algorithm Design Strategies V

Multi-objective branch-and-cut algorithm and multi-modal traveling salesman problem

Unit 1A: Computational Complexity

where X is the feasible region, i.e., the set of the feasible solutions.

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

CS Analysis of Recursive Algorithms and Brute Force

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

Computational Complexity and Intractability: An Introduction to the Theory of NP. Chapter 9

CS Algorithms and Complexity

Question Paper Code :

Introduction to Mathematical Programming IE406. Lecture 21. Dr. Ted Ralphs

Integer Linear Programming

8.5 Sequencing Problems

MVE165/MMG630, Applied Optimization Lecture 6 Integer linear programming: models and applications; complexity. Ann-Brith Strömberg

More on NP and Reductions

Optimisation and Operations Research

NP-Completeness. NP-Completeness 1

CS325: Analysis of Algorithms, Fall Final Exam

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

CS6901: review of Theory of Computation and Algorithms

Chapter 8 Dynamic Programming

Design and Analysis of Algorithms

This observation leads to the following algorithm.

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Lecture 23 Branch-and-Bound Algorithm. November 3, 2009

3.4 Relaxations and bounds

Chapter 8 Dynamic Programming

Intractable Problems Part Two

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

Dynamic Programming. Cormen et. al. IV 15

Advanced Analysis of Algorithms - Midterm (Solutions)

Note that M i,j depends on two entries in row (i 1). If we proceed in a row major order, these two entries will be available when we are ready to comp

CS 350 Algorithms and Complexity

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

0-1 Knapsack Problem in parallel Progetto del corso di Calcolo Parallelo AA

CS 350 Algorithms and Complexity

Decision Trees. Lewis Fishgold. (Material in these slides adapted from Ray Mooney's slides on Decision Trees)

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Limitations of Algorithm Power

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502)

Network Flows. 6. Lagrangian Relaxation. Programming. Fall 2010 Instructor: Dr. Masoud Yaghini

Combinatorial optimization problems

This means that we can assume each list ) is

VIII. NP-completeness

D1 Discrete Mathematics The Travelling Salesperson problem. The Nearest Neighbour Algorithm The Lower Bound Algorithm The Tour Improvement Algorithm

CPS 616 DIVIDE-AND-CONQUER 6-1

the tree till a class assignment is reached

ECS122A Handout on NP-Completeness March 12, 2018

Optimisation and Operations Research

NP and Computational Intractability

Introduction to integer programming II

1. Introduction Recap

Column Generation. i = 1,, 255;

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Quiz 3 Reminder and Midterm Results

EXACT ALGORITHMS FOR THE ATSP

Introduction. An Introduction to Algorithms and Data Structures

Part III: Traveling salesman problems

Synthesis of 2-level Logic Exact and Heuristic Methods. Two Approaches

CS3719 Theory of Computation and Algorithms

P,NP, NP-Hard and NP-Complete

Mat 3770 Bin Packing or

Fundamentals of optimization problems

The P versus NP Problem. Ker-I Ko. Stony Brook, New York

Examination paper for TDT4120 Algorithms and Data Structures

Decision Tree Learning

CSE 202 Homework 4 Matthias Springer, A

Data Structures and Algorithms

Introduction to Bin Packing Problems

with Binary Decision Diagrams Integer Programming J. N. Hooker Tarik Hadzic IT University of Copenhagen Carnegie Mellon University ICS 2007, January

Complexity, P and NP

Lecture 3: Decision Trees

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

0-1 Knapsack Problem

DAA Unit- II Greedy and Dynamic Programming. By Mrs. B.A. Khivsara Asst. Professor Department of Computer Engineering SNJB s KBJ COE, Chandwad

Section Notes 9. Midterm 2 Review. Applied Math / Engineering Sciences 121. Week of December 3, 2018

Travelling Salesman Problem

What is an integer program? Modelling with Integer Variables. Mixed Integer Program. Let us start with a linear program: max cx s.t.

1. (a) Explain the asymptotic notations used in algorithm analysis. (b) Prove that f(n)=0(h(n)) where f(n)=0(g(n)) and g(n)=0(h(n)).

6. DYNAMIC PROGRAMMING I

Greedy vs Dynamic Programming Approach

Introduction to optimization and operations research

4 Sequencing problem with heads and tails

CS360 Homework 12 Solution

Answer the following questions: Q1: ( 15 points) : A) Choose the correct answer of the following questions: نموذج اإلجابة

4. How to prove a problem is NPC

BBM402-Lecture 11: The Class NP

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

1 The Knapsack Problem

Data Structures and Algorithms (CSCI 340)

Cutting Planes in SCIP

NP-Completeness Theory

Analysis of Algorithms - Midterm (Solutions)

Knapsack. Bag/knapsack of integer capacity B n items item i has size s i and profit/weight w i

Greedy Algorithms My T. UF

AI Programming CS S-06 Heuristic Search

CS320 The knapsack problem

Multivalued Decision Diagrams. Postoptimality Analysis Using. J. N. Hooker. Tarik Hadzic. Cork Constraint Computation Centre

Transcription:

Algorithms Chapter 5: The Tree Searching Strategy - Examples 1 / 11 Chapter 5: The Tree Searching Strategy 1. Ex 5.1Determine the satisfiability of the following Boolean formulas by depth-first search tree searching technique. (depth-first search) (tree searching technique) (Boolean formulas) (satisfiability) (a) ( X1 X 2 X ) ( X1 X ) ( X 2 ) (b) ( X1 X 2 X ) ( X1 X 2 ) ( X 2 X ) ( X ) (c) ( X1 X 2 X ) ( X1 X 2 X ) (d) ( X1 X 2 ) ( X 2 X ) ( X ) We apply the depth-first search. (a) satisfiable (b) unsatisfiable satisfying assignment: (X 1, X 2 ) X 1 =T X 1 =F X 2 =T X 2 =F X 2 =T X 2 =F X =T X =F X =T X =F X =T X =F X =T X =F (4) (c) satisfiable () (4) (1) (4) () (4) (2)

Algorithms Chapter 5: The Tree Searching Strategy - Examples 2 / 11 satisfying assignment: (X 1, X 2, -X ) (d) satisfiable satisfying assignment: (X 1, -X 2, -X ) 2. Ex 5.2Consider the following graph. Find a Hamiltonian cycle by some kind of tree searching technique. (tree searching technique) (Hamiltonian cycle) 7 5 2 6 4 1 The searching tree with respect to the graph, starting from node 1 is as follows. It can be seen from the searching tree that there are two Hamiltonian cycles for this graph. One is 1--2-7-5-4-6-1 and the other is 1-6-4-5-7-2--1. They are exactly the same.

Algorithms Chapter 5: The Tree Searching Strategy - Examples / 11. Ex 5.Solve the following sum of subset problem. S = {7, 1, 4, 6, 14, 25, 5, 8} and M = 18. Find a sum whose elements add up to M by using the depth-first search strategy. We adopt the depth-first search in the branch-and-bound strategy. The searching tree is as follows. A branch is valid only when the accumulated sum of the selected elements is less than or equal to 18. This accumulated sum is annotated inside each node. We find a subset of S, that is, {7, 1, 4, 6}, whose sum is exactly 18 so that the searching stops. 4. Ex 5.4 Solve the 8-puzzle problem which tests with the following initial state.

Algorithms Chapter 5: The Tree Searching Strategy - Examples 4 / 11 2 8 1 7 5 4 6 Note that our final goal is 1 2 8 7 6 4 5 Note that (1) the evaluation function f(n) be defined as f(n) = w(n), where w(n) is the number of misplaced tiles in node n, and (2) you must expand at least 4 levels. Let the evaluation function f(n) be defined as f(n) = w(n), where w(n) is the number of misplaced tiles in node n. We apply the hill climbing method to expand the searching tree. The partially expanded searching tree is shown in the following. Note that the value of f(n) is annotated beside node n. 2 8 1 4 (5) 2 8 1 4 2 4 (4) 8 1 (6) 2 8 1 4 2 1 () 8 4 (4) 8 2 1 4 (4)

Algorithms Chapter 5: The Tree Searching Strategy - Examples 5 / 11 5. Ex 5.5Find the shortest path from v 0 to v 8 in the following graph by the branch-and-bound strategy. (branch-and-bound strategy) v 0 v 8 (shortest path) v 0 1 5 7 4 v 1 v 2 v 10 2 2 1 v 5 v 6 9 2 5 v 8 v 4 v 7 We apply the depth-first search in the branch-and-bound strategy and we illustrate the searching tree as follows. We indicate the branching sequence of each node at its left side. It is seen that at the th branching node we obtain a path from v 0 to v 8 with weight 6 based upon which branching nodes 4, 6, 7, 8, and 10 can be bounded. Since all branches have been expanded or bounded we have a shortest path from v 0 to v 8 with weight 6. 10 2 2 >6 bound 2 4 6 7 10 v 5 v 6 v 5 v 7 v 7 2 v 8 goal weight=6 v 0 v 1 v 2 v >6 bound 1 >6 bound 0 5 7 1 5 8 9 >6 bound 4 v 4 >6 bound 6. Ex 5.6Given the following distance (cost) matrix, please solve the traveling salesperson problem on it by the branch-and-bound strategy. (You must expand at least 2 levels) a b c d a 9 7

Algorithms Chapter 5: The Tree Searching Strategy - Examples 6 / 11 b 6 5 c 5 6 6 d 9 7 4 The represented directed graph: 9 a 7 d 7 9 5 5 6 4 b 6 c 6 The reduced cost matrix: (cost matrix 1 0) a b c d a 9 7 b 6 5 c 5 6 6 5 d 9 7 4 4 1 a b c d a 0 6 b 0 1 c 0 1 0 d 5 0 lower bound = (++5+4)+1 = 16 ( cost, i.e., solution 16) 1st row C 12 or -1: C 12 reduced cost matrix cost matrix: a b c d a 6 b 0 1 c 0 1 0

Algorithms Chapter 5: The Tree Searching Strategy - Examples 7 / 11 d 5 0 1 a b c d a 0 b 0 1 c 0 0 0 d 5 2 0 lower bound = 16+(+1) = 20 ( cost, i.e., solution 20) -2: C 12 edge (2, 1) Hamiltonian cycle C 21 = 1 2 reduced cost matrix cost matrix: a c d b 1 1 c 0 0 d 5 0 a c d b 2 0 c 0 0 d 5 0 lower bound = 16+(1) = 17 ( cost, i.e., solution 17) binary decision tree(branch-and-bound strategy) (OPT) binary decision tree:

Algorithms Chapter 5: The Tree Searching Strategy - Examples 8 / 11 solutions LB = 17 C 12 LB = 20 C 12 LB = 17 C 24 C 24 LB = 19 LB = 17 C 4 C 4 No solution LB = 17 C 1 No solution C 1 (1) Branch = LB nodeexpanding (2) An upper bound 17 is obtained. (optimal solution ) () nodelb (17) expand( optimal) (4) optimal solution = 17: a b d c a 7. Ex 5.7The following is an instance of 0/1 Knapsack problem, where p i is the profit when putting object i into knapsack, w i is the weight of object i, and M = 15 is the capacity of knapsack for 1 i 4. Please use the branch-and-bound strategy to solve this problem. i 1 2 4 p i 10 10 12 18 w i 2 4 6 9 We first transfer the original problem to the following: minimize 1 i 4 p i x i, subject to 1 i 4 w i x i M for x i = 0 or 1. Initially, a lower bound and an upper bound are found. -1: lower bound (LB, optimal solution ) use the greedy strategy to find it (see Sec..7) i 1 2 4 p i /w i 5 2.5 2 2 x i 1 1 1 /9 A lower bound = (p 1 +p 2 +p +/9*p 4 ) = (2+6) = 8-2: upper bound (UB, solution> optimal) use the greedy strategy to find it s = 0; for i = 1 to 4 do if s+w i M = 15 then

Algorithms Chapter 5: The Tree Searching Strategy - Examples 9 / 11 s = s+w i ; x i = 1; else x i = 0; By the above procedure, we obtain a feasible solution (x 1, x 2, x, x 4 ) = (1, 1, 1, 0). Then, an upper bound (p 1 +p 2 +p ) = (10+10+12) = 2 is obtained. Branch-and-bound strategy: Branch strategy: the best LB ( ) and then the lowest UB ( ) of node is expanded. UB = 2 LB = 8 UB = 2 0 LB = 8 x 1 =1 x 1 =0 UB = 2 UB: (x 1 2 1, x 2, x, x 4 ) = (0, 1, 1, 0) = 22 LB = 8 LB: (x 1, x 2, x, x 4 ) = (0, 1, 1, 5/9) = 2 x 2 =1 x 2 =0 LB > node 7 UB = 2 UB: (x 1, x 2, x, x 4 ) = (1, 0, 1, 0) = 2 4 UB, LB = 8 LB: (x 1, x 2, x, x 4 ) = (1, 0, 1, 7/9) = 6 x =1 x =0 expand UB: (x 1, x 2, x, x 4 ) = (1, 1, 0, 1) = 8 5 6 LB: (x 1, x 2, x, x 4 ) = (1, 1, 0, 1) = 8 x 4 =1 x 4 =0 UB = 8 UB: (x 1, x 2, x, x 4 ) = (1, 1, 0, 0) = 20 LB = 8 7 8 LB: (x 1, x 2, x, x 4 ) = (1, 1, 0, 0) = 20 The optimal solution is 8, where (x 1, x 2, x, x 4 ) = (1, 1, 0, 1). Then, the original solution is 8.

Algorithms Chapter 5: The Tree Searching Strategy - Examples 10 / 11 Chapter 6: The Prune-and-Search Strategy 1. Ex 6.1Given a set S of n elements and an integer k, the selection problem is to find the k-th smallest element of S. Please design an O(n) time algorithm to solve the selection problem. Note that you must design an algorithm and then analyze its time complexity. (a) The algorithm Prune-and-Search Algorithm Input: A set S of n elements. Output: The k-th smallest element of S. Method. Step 1: Divide S into n/5 subsets. Each subset contains five elements. Add some dummy elements to the last subset if n is not a net multiple of S. Step 2: Sort each subset of elements. Step : Find the element p which is the median of the medians of the n/5 subsets. Step 4: Partition S into S 1, S 2 and S, which contain the elements less than, equal to, and greater than p, respectively. Step 5: If S 1 k, then discard S 2 and S and solve the problem that selects the k-th smallest element from S 1 during the next iteration; else if S 1 + S 2 k, then p is the k-th smallest element of S; otherwise, let k = k S 1 S 2, solve the problem that selects the k -th smallest element from S during the next iteration. (b) The analysis of the algorithm We first show that S 1 n/4 and S n/4 by the following figure: At least 1/4 of S known to be less than or equal to p. Each 5-element subset is sorted in non-decreasing sequence. p M At least 1/4 of S known to be greater than or equal to p. Then, at least n/4 elements are pruned away during each iteration. The problem remaining in Step 5 contains at most n/4 elements. Let T(n) be the time complexity of the algorithm. Then, Step takes T(n/5) time, Step 5 takes T(n/4), and the remaining

Algorithms Chapter 5: The Tree Searching Strategy - Examples 11 / 11 steps take O(n) time. Thus, we obtain the following recurrence. T(n) = T(n/4) + T(n/5) + O(n) (1) To solve the above recurrence, we set T(n) = a 0 + a 1 n + a 2 n 2 +..., where a 1 0. Then, T(n/4) = a 0 + (/4)a 1 n + (9/16)a 2 n 2 +... (2) T(n/5) = a 0 + (1/5)a 1 n + (1/25)a 2 n 2 +... () T((n/4)+(n/5)) = T(19n/20) = a 0 + (19/20)a 1 n + (61/400) a 2 n +... (4) By Equations (2) (4), we obtain T(n/4)+T(n/5) a 0 + T(19n/20) and hence, T(n) = T(n/4) + T(n/5) + O(n) T(19n/20) +cn cn + (19/20)cn + T((19/20) 2 n)... cn + (19/20)cn + (19/20) 2 cn +...+ (19/20) p cn + T((19/20) p+1 n) (note: (19/20) p+1 n 1 (19/20) p n) 19 p+ 1 1 ( ) 20 = cn + b 20cn + b 19 1 20 = O(n).