The Theory of NP-Completeness

Slides:



Advertisements
Similar presentations
Algorithms Chapter 15 Dynamic Programming - Rod
Advertisements

The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
© The McGraw-Hill Companies, Inc., Chapter 8 The Theory of NP-Completeness.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
自由進入及離開. 定義  長期 ─ 是指生產者能夠改變所有生產因素的情況。  自由進入及離開 ─ 是指公司能夠自由進入及離開市場而不受限 制。
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
Lecture Note of 9/29 jinnjy. Outline Remark of “Central Concepts of Automata Theory” (Page 1 of handout) The properties of DFA, NFA,  -NFA.
基礎物理總論 基礎物理總論 熱力學與統計力學(三) Statistical Mechanics 東海大學物理系 施奇廷.
Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.
2009fallStat_samplec.i.1 Chap10 Sampling distribution (review) 樣本必須是隨機樣本 (random sample) ,才能代表母體 Sample mean 是一隨機變數,隨著每一次抽出來的 樣本值不同,它的值也不同,但會有規律性 為了要知道估計的精確性,必需要知道樣本平均數.
Chapter 13 塑模靜態觀點:物件圖 Static View : Object Diagram.
Greedy Algorithms. 2 Greedy Methods ( 描述 1) * 解最佳化問題的演算法, 其解題過程可看成是由一 連串的決策步驟所組成, 而每一步驟都有一組選擇 要選定. * 一個 greedy method 在每一決策步驟總是選定那目 前看來最好 的選擇. *Greedy.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
自動機 (Automata) Time: 1:10~2:00 Monday: practice exercise, quiz 2:10~4:00 Wednesday: lecture Textbook: (new!) An Introduction to Formal Languages and Automata,
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
公司加入市場的決定. 定義  平均成本 = 總成本 ÷ 生產數量 = 每一單位產量所耗的成本  平均固定成本 = 總固定成本 ÷ 生產數量  平均變動成本 = 總變動成本 ÷ 生產數量.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
Lecture 7 Sorting in Linear Time. Sorting in Linear Time2 7.1 Lower bounds for sorting 本節探討排序所耗用的時間複雜度下限。 任何一個以比較為基礎排序的演算法,排序 n 個元 素時至少耗用 Ω(nlogn) 次比較。
88- 1 Chapter 8 The Theory of NP-Completeness P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class.
公用品.  該物品的數量不會因一人的消費而受到 影響,它可以同時地被多人享用。 角色分配  兩位同學當我的助手,負責:  其餘各人是投資者,每人擁有 $100 , 可以投資在兩種資產上。  記錄  計算  協助同學討論.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/25 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH 2.4~CH 2.6 &
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
: Expect the Expected ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11427: Expect the Expected 解題者:李重儀 解題日期: 2008 年 9 月 21 日 題意:玩一種遊戲 (a game.
逆向選擇和市場失調. 定義  資料不對稱 在交易其中,其中一方較對方有多些資料。  逆向選擇 出現在這個情況下,就是當買賣雙方隨意在 市場上交易,與比較主動交易者作交易為佳 。
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 10 m-way 搜尋樹與B-Tree
演算法課程 (Algorithms) 國立聯合大學 資訊管理學系 陳士杰老師 Course 7 貪婪法則 Greedy Approach.
34.NP Completeness Hsu, Lih-Hsing. Computer Theory Lab. Chapter 34P.2 為何學 NP-Complete 50 年前的電腦 ( 一間房間大 ) 可解的問題的極限 與現在電腦 ( 個人電腦 ) 可解的極限理論上是相 同的, 除非電腦的製程有重大突破.
Chapter 7 Sampling Distribution
Course 9 NP Theory序論 An Introduction to the Theory of NP
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
第 6 章 迴圈結構 6-1 計數迴圈 6-1 計數迴圈 6-2 條件迴圈 6-2 條件迴圈 6-3 巢狀迴圈 6-3 巢狀迴圈 6-4 While/End While 迴圈 6-4 While/End While 迴圈 6-5 跳出迴圈 6-5 跳出迴圈 6-6 VB.NET 的錯誤處理 6-6 VB.NET.
: Wine trading in Gergovia ★★☆☆☆ 題組: Contest Volumes with Online Judge 題號: 11054: Wine trading in Gergovia 解題者:劉洙愷 解題日期: 2008 年 2 月 29 日 題意:在 Gergovia.
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
:Count the Trees ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10007:Count the Trees 解題者:楊家豪 解題日期: 2006 年 3 月 題意: 給 n 個點, 每一個點有自己的 Label,
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
幼兒行為觀察與記錄 第八章 事件取樣法.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
1 The Theory of NP-Completeness 2 NP P NPC NP: Non-deterministic Polynomial P: Polynomial NPC: Non-deterministic Polynomial Complete P=NP? X = P.
1 柱體與錐體 1. 找出柱體與錐體的規則 2. 柱體的命名與特性 3. 柱體的展開圖 4. 錐體的命名與特性 5. 錐體的展開圖
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
The Theory of NP-Completeness 1. What is NP-completeness? Consider the circuit satisfiability problem Difficult to answer the decision problem in polynomial.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Graph Theory Chapter 7 Eulerian Graphs 大葉大學 (Da-Yeh Univ.) 資訊工程系 (Dept. CSIE) 黃鈴玲 (Lingling Huang)
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
1 How to prove that a problem is NPC. 2 Cook Cook showed the first NPC problem: SAT Cook received Turing Award in 1982.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
1 The Theory of NP-Completeness 2 Review: Finding lower bound by problem transformation Problem X reduces to problem Y (X  Y ) iff X can be solved by.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
Chapter 10 NP-Complete Problems.
Hard Problems Introduction to NP
ICS 353: Design and Analysis of Algorithms
The Theory of NP-Completeness
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
CS 3343: Analysis of Algorithms
The Theory of NP-Completeness
Presentation transcript:

The Theory of NP-Completeness Chapter 8 The Theory of NP-Completeness

8-1 Concepts Two categories of problems: Polynomial time algorithm: searching O(log n)、polynomial evaluation O(n)、sorting O(n log n)、string editing O(mn) Exponential time algorithm: TSP O(n2 2n) 與 0/1 knapsack O(2n/2) 第二類的問題其實也無法證明它們一定沒有 polynomial time algorithm,但是就是找不出來。 NP-complete 的理論就是要討論哪些問題是屬於前面所說的第二類?這些問題有什麼樣的特性等等。 在討論這些沒有 polynomial time algorithm 的問題時,我們再將這些問題分成兩類,一是 NP-complete、另一個是 NP-hard。 一個 NP-complete 的問題有 polynomial time 的演算法  所有 NP-complete 的問題都有 polynomial time algorithm。兩個互為充份必要條件。 一個 NP-hard 的問題如果有 polynomial time algorithm 則所有 NP-complete 的問題也都有 polynomial time algorithm。

8-1 Concepts 目前所講的演算法都有一個前提假設,就是它的每個運算(operation)的結果都是獨一(確定)的。這種性質的演算法可以在實際的電腦上執行,稱為 deterministic algorithms. 在討論計算理論時,可以將這種限制拿掉,也就是可以假設一個運算的結果不唯一,可能是某 n 個結果中的一個,而且一定會是正確的那一個。這樣子的演算法稱為 non-deterministic algorithm。這種演算法無法在實際的電腦上執行。

8-1 Concepts A non-deterministic algorithm terminates unsuccessfully if and only if there exists no set of choices leading to a success signal。只有在不可能有正確答案的情形下, non-deterministic algorithm 才無法成功地完成工作。 一個可以執行 non-deterministic algorithm 的機器稱為 non-deterministic machine. (That machine does not exit in the world) 我們定義下列三個函數來說明這種演算法。 Choice(S): 從 S 中選一個正確的元素出來。 Failure(): 沒有成功地完成工作。 Success(): 成功地完成工作 這三個函數的執行時間都是 O(1)。

8-1 Concepts 要如何來看待 non-deterministic algorithm 呢? 可以用平行處理的角度來看,也就是當作同時有很多很多機器(依據所有可能資料集合)一起作同一個問題,每個機器用不同的 choice 的結果來作,如果有一個成功的話,其他的就不用再作;如果有一個失敗、就自己停下來即可。 另外,也可以當作實際上可能有一種方法可以選擇一個正確的答案出來,只是我們還不曉得而已(上帝知道),所以答案可能會存在。

8-1 Concepts NP : the class of decision problems which can be solved by a non-deterministic polynomial algorithm. P: the class of decision problems which can be solved by a deterministic polynomial algorithm. NP-complete: The problems which belong to NP. Until now, no deterministic polynomial algorithm can solve it. Such as, the satisfiability problem (the first NPC problem) NP-hard: the class of problems to which every NP problem reduces. An optimization problem if its corresponding decision problem is NP-complete.

8-1 Concept of reduction Def : Problem A reduces to problem B (A  B) iff A can be solved by a deterministic polynomial time algorithm using a deterministic algorithm that solves B in polynomial time.

8-1 Some concepts Up to now, none of the NPC problems can be solved by a deterministic polynomial time algorithm in the worst case. It does not seem to have any polynomial time algorithm to solve the NPC problems. The lower bound of any NPC problem seems to be in the order of an exponential function. The theory of NP-completeness always considers the worst case.

8-1 Some concepts Not all NP problems are difficult. (e.g. the MST problem is an NP problem.) If A, B  NPC, then A  B and B  A. Theory of NP-completeness If any NPC problem can be solved in polynomial time, then all NP problems can be solved in polynomial time. (NP = P)

8-2 Decision problems Any problem for which the answer is either zero or one is called a decision problem. An algorithm for a decision problem is termed a decision algorithm. Any problem that involves the identification of an optimal (either minimum or maximum) value of a given cost function is known as an optimization problem. An optimization algorithm is used to solve an optimization problem. The solution is simply “Yes” or “No”. Optimization problem : more difficult than Decision problem E.g. the traveling salesperson problem Optimization version: Find the shortest tour Decision version: Is there a tour whose total length is less than or equal to a constant C ?

8-2 0/1 Knapsack Problem 共有 n 個東西,每個東西的價值為 p1, p2, …, pn, 每個東西的重量為 w1, w2, …, wn, 一個袋子的重量限制為 m,重量與價值都至少為 0。 其 optimization 的版本是:所能夠裝的東西之最大價值是多少? decision 的版本為:是否能裝超過某個價值 r? decision 版本的問題若沒有 polynomial time algorithm,則 optimization 版本的問題也沒有 polynomial time 演算法。

8-2 Solving an optimization problem by a decision algorithm : Solving TSP optimization problem by decision algorithm : Give c1 and test Give c2 and test  Give cn and test Decide ci’s by binary search the range 1~K, where K may be selected as the sum of all edges or by some heuristics (approximation algorithm to be described in Chap.9)

8-3 The satisfiability problem The logical formula : x1 v x2 v x3 & - x1 & - x2 the assignment : x1 ← F , x2 ← F , x3 ← T will make the above formula true (-x1, -x2 , x3) represents

8-3 The satisfiability problem If there is at least one assignment which satisfies a formula, then we say that this formula is satisfiable; otherwise, it is unsatisfiable. An unsatisfiable formula : x1 v x2 & x1 v -x2 & -x1 v x2 & -x1 v -x2

8-3 The satisfiability problem Def : Given a Boolean formula, determine whether this formula is satisfiable or not.   A literal : xi or -xi A clause : x1 v x2 v -x3  ci A formula : conjunctive normal form (CNF) c1& c2 & … & cm

The resolution principle C1 : x1 v x2 C2 : -x1 v x3  C3 : x2 v x3 From C1 & C2, we can obtain C3, and C3 can be added into the formula. The formula becomes: C1 & C2 & C3 x1 x2 x3 C1 & C2 C3 1

8-3 The satisfiability problem Resolution principle c1 : -x1 v -x2 v x3 c2 : x1 v x4  c3 : -x2 v x3 v x4 (resolvent) If no new clauses can be deduced  satisfiable -x1 v -x2 v x3 (1) x1 (2) x2 (3) (1) & (2) -x2 v x3 (4) (4) & (3) x3 (5) (1) & (3) -x1 v x3 (6)

8-3 The satisfiability problem If an empty clause is deduced  unsatisfiable - x1 v -x2 v x3 (1) x1 v -x2 (2) x2 (3) - x3 (4)    deduce   (1) & (2) -x2 v x3 (5) (4) & (5) -x2 (6) (6) & (3) □ (7)

8-3 Semantic tree In a semantic tree, each path from the root to a leaf node represents a class of assignments. If each leaf node is attached with a clause unsatisfiable.

8-4 Nondeterministic algorithms Guessing Checking If the checking stage of a nondeterministic algorithm is of polynomial time-complexity, then this algorithm is called an NP (nondeterministic polynomial) algorithm. NP problems : (must be decision problems) E.g. searching, MST (Final examination, NP algorithm) sorting satisfiability problem (SAT) traveling salesperson problem (TSP)

8-4 Decision version of sorting Given a1, a2,…, an and c, is there a permutation of ais ( a1, a2 , … ,an ) such that∣a2–a1∣+∣a3–a2∣+ … +∣an–an-1∣< C ? Not all decision problems are NP problems E.g. halting problem : Given a program with a certain input data, will the program terminate or not? NP-hard Undecidable Because it can’t be solved by three functions: Choice, failure, success

8-4 Nondeterministic algorithms Choice(S) : arbitrarily chooses one of the elements in set S Failure : an unsuccessful completion Success : a successful completion

8-4 Nondeterministic searching : j ← choice(1 : n) /* guess if A(j) = x then success /* check else failure A nondeterministic algorithm terminates unsuccessfully iff there exist no set of choices leading to a success signal. The time required for choice(1 : n) is O(1). A deterministic interpretation of a non-deterministic algorithm can be made by allowing unbounded parallelism in computation.

8-4 Nondeterministic sorting B ← 0 for i = 1 to n do Guessing j ← choice(1 : n) if B[j] ≠ 0 then failure B[j] = A[i] for i = 1 to n-1 do Checking if B[i] > B[i+1] then failure success Note: Nondeterministic algorithm: O(n) Deterministic algorithm: O(nlogn) Generating a list Testing the list

Nondeterministic SAT Guessing for i = 1 to n do xi ← choice( true, false ) if E(x1, x2, … ,xn) is true Checking then success else failure

Transforming searching to SAT 8-5 Cook’s theorem NP = P iff the satisfiability problem is a P problem. SAT is NP-complete. It is the first NP-complete problem. Every NP problem reduces to SAT. Stephen Arthur Cook Transforming searching to SAT

8-5 Transforming searching to SAT Does there exist a number in { x(1), x(2), … x(n) }, which is equal to 7? Assume n = 2, x(1)=7, x(2)≠7

8-5 Transforming searching to SAT i=1 v i=2 & i=1 → i≠2 & i=2 → i≠1 & x(1)=7 & i=1 → SUCCESS & x(2)=7 & i=2 → SUCCESS & x(1)≠7 & i=1 → FAILURE & x(2)≠7 & i=2 → FAILURE & FAILURE → -SUCCESS & SUCCESS (Guarantees a successful termination) & x(1)=7 (Input Data) & x(2)≠7

8-5 Transforming searching to SAT CNF (conjunctive normal form) : i=1 v i=2 (1) i≠1 v i≠2 (2) x(1)≠7 v i≠1 v SUCCESS (3) x(2)≠7 v i≠2 v SUCCESS (4) x(1)=7 v i≠1 v FAILURE (5) x(2)=7 v i≠2 v FAILURE (6) -FAILURE v -SUCCESS (7) SUCCESS (8) x(1)=7 (9) x(2)≠7 (10)

8-5 Transforming searching to SAT Satisfiable at the following assignment : i=1 satisfying (1) i≠2 satisfying (2), (4) and (6) SUCCESS satisfying (3), (4) and (8) -FAILURE satisfying (7) x(1)=7 satisfying (5) and (9) x(2)≠7 satisfying (4) and (10) Note: ex. i=1 is a literal and i≠1 is its negative

8-5 The semantic tree

8-5 Searching in CNF with inputs Searching for 7, but x(1)7, x(2)7 CNF :

8-5 Searching in CNF with inputs Apply resolution principle :

8-5 Searching in CNF with inputs

8-5 The semantic tree It implies that both assignments (i=1, i=2) satisfy the clauses.

8-6 NP-Complete Def : Problem A reduces to problem B (A  B) iff A can be solved by a deterministic polynomial time algorithm using a deterministic algorithm that solves B in polynomial time.

8-6 SAT is NP-complete Every NP problem can be solved by an NP algorithm Every NP algorithm can be transformed in polynomial time to an SAT problem [Horowitz and Shani 1998] Such that the SAT problem is satisfiable iff the answer for the original NP problem is “yes” That is, every NP problem  SAT SAT is NP-complete

8-6 NP-Complete A problem L is NP-hard if and only if satisfiability reduces to L ( SAT problemL). A problem L is NP-complete if and only if L is NP-hard and L  NP. To show that a problem L2 is NP-hard, it is adequate to show L1L2, where L1 is some problem already known to be NP-hard. To show that an NP-hard decision problem is NP-complete, we have just to exhibit a polynomial time non-deterministic algorithm for it.

8-7 Proof of NP-Completeness To show that A is NP-complete (I) Prove that A is an NP problem (Find a non-deterministic polynomial algorithm to solve it, such as sorting or searching) (See Sections 3-4 ~ 3-5, Sorting and searching problems) (II) Prove that  B  NPC, B  A  A  NPC Two problems L1 and L2 are said to be polynomially equivalent iff L1L2 and L2L1.

8-7 3-satisfiability problem (3-SAT) Each clause contains exactly three literals. (I)  3-SAT is an NP problem (obviously See 3-24 slide) (II) SAT  3-SAT (Transformation rules, Prove its correctness) One literal L1 in a clause in SAT : in 3-SAT : L1 v y1 v y2 L1 v -y1 v y2 L1 v y1 v -y2 L1 v -y1 v -y2

8-7 3-satisfiability problem (3-SAT) Two literals L1, L2 in a clause in SAT : in 3-SAT : L1 v L2 v y1 L1 v L2 v -y1 Three literals in a clause : remain unchanged

8-7 3-satisfiability problem (3-SAT) More than 3 literals L1, L2, …, Lk in a clause : in 3-SAT : L1 v L2 v y1 L3 v -y1 v y2  Lk-2 v -yk-4 v yk-3 Lk-1 v Lk v -yk-3

8-7 3-satisfiability problem (3-SAT) E.g. an instance in SAT : x1 v x2 -x3 x1 v -x2 v x3 v -x4 v x5 Transform to an instance in 3-SAT : x1 v x2 v y1 x1 v x2 v -y1 -x3 v y2 v y3 -x3 v -y2 v y3 -x3 v y2 v -y3 -x3 v -y2 v -y3 x1 v -x2 v y4 x3 v -y4 v y5 -x4 v x5 v -y5 SAT transform 3-SA S S

8-7 3-satisfiability problem (3-SAT) Proof : S is satisfiable  S is satisfiable “”  3 literals in S (trivial) consider  4 literals S : L1 v L2 v … v Lk S: L1 v L2 v y1 L3 v -y1 v y2 L4 v -y2 v y3  Lk-2 v -yk-4 v yk-3 Lk-1 v Lk v -yk-3

8-7 3-satisfiability problem (3-SAT) S is satisfiable  at least Li = T in this clause of S Assume : Lj = F  j  i assign : yi-1 = F yj = T  j  i-1 yj = F  j  i-1 ( Li v -yi-2 v yi-1 )  S is satisfiable.

8-7 3-satisfiability problem (3-SAT) “” If S is satisfiable, then assignment satisfying S can not contain yi’s only  at least Li must be true. (We can also apply the resolution principle).  3-SAT is NP-complete 

8-7 Caution ! If a problem is NP-complete, its special cases may or may not be NP-complete. The 0/1 knapsack problem is NP-complete The knapsack problem is not NP-complete

8-7 The knapsack problem The greedy algorithm: Step 1: Sort pi/wi into non-increasing order. Step 2: Put the objects into the knapsack according to the sorted sequence as possible as we can.

8-7 The knapsack problem E.g. n = 3, M = 20, (p1, p2, p3) = (25, 24, 15) (w1, w2, w3) = (18, 15, 10) Sol: p1/w1 = 25/18 = 1.32 p2/w2 = 24/15 = 1.6 p3/w3 = 15/10 = 1.5 Optimal solution: x1 = 0, x2 = 1, x3 = 1/2

Note: NP-Complete problem [0/1 Knapsack]. Consider the knapsack problem discussed in the previous section. We add the requirement that xi = 1 or xi = 0, 1≦i ≦n; i.e., an object is either included or not included into the knapsack. We wish to solve the problem One greedy strategy is to consider the objects in order of nonincreasing density pi/wi and add the object into the knapsack if it fits.

8-7 Chromatic number decision problem A coloring of a graph G=(V, E) is a function f : V  { 1, 2, 3,…, k }  if (u, v)  E, then f(u)f(v).

8-7 Chromatic number decision problem (CN) Determine if G has a coloring for k. E.g. <Theorem> Satisfiability with at most 3 literals per clause (SATY)  CN. 3-colorable f(a)=1, f(b)=2, f(c)=1 f(d)=2, f(e)=3

8-7 SATY (Special 3-SAT)  CN

8-7 SATY  CN (Satisfiable  n+1 colorable) E.g. x1 v x2 v x3 (1) -x3 v -x4 v x2 (2)  No connection for each variable in Ci For given each literal a color

8-7 SATY  CN Satisfiable  n+1 colorable “” (1) f(yi) = i (color i) (2) if xi = T, then f(xi) = i, f(-xi) = n+1 else f(xi) = n+1, f(-xi) = i (3)if xi in cj and xi = T, then f(cj) = f(xi) if -xi in cj and -xi = T, then f(cj) = f(-xi) ( at least one such xi )

8-7 SATY  CN “” (1) yi must be assigned with color i. (2) f(xi)  f(-xi) either f(xi) = i and f(-xi) = n+1 or f(xi) = n+1 and f(-xi) = i (3) at most 3 literals in cj and n  4  at least one xi,  xi and -xi are not in cj  f(cj)  n+1 (4) if f(cj) = i = f(xi), assign xi to T if f(cj) = i = f(-xi), assign -xi to T (5) if f(cj) = i = f(xi)  (cj, xi)  E  xi in cj  cj is true if f(cj) = i = f(-xi)  similarly #

Overview of NP-Complete problem reduction SAT  3-SAT 3-SAT  CN (Chromatic number decision) CN  Exact cover Exact cover  Sum of subsets Sum of subsets  Partition Partition  Bin packing Bin packing  VLSI discrete layout -------------------------------------------------------- SAT  Clique decision problem Clique decision problem  Node cover decision problem SAT  Directed Hamiltonian cycle Directed Hamiltonian cycle  TSP Refer to Sec. 11.3, Sec. 11.4 and its exercise of [Horowitz and Shani 1998] for the proofs of more NP-complete problems.

8-7 CN  exact cover Set cover decision problem F = {Si} = { S1, S2, …, Sk } Si = { u1, u2, …, un } T is a set cover of F if T  F and The set cover decision problem is to determine if F has a cover T containing no more than C sets. E.g. F = {(a1, a3), (a2, a4), (a2, a3), (a4)} s1 s2 s3 s4 T = { s1, s3, s4 } set cover T = { s1, s2 } set cover, exact cover

8-7 CN  exact cover Exact cover problem Notations same as those in set cover. To determine if F has an exact cover T, which is a cover of F and the sets in T are pairwise disjoint. <Theorem> CN  exact cover

8-7 Exact cover  sum of subsets Sum of subsets problem A set of positive numbers A = { a1, a2, …, an } a constant C Determine if  A  A  E.g. A = { 7, 5, 19, 1, 12, 8, 14 } C = 21, A = { 7, 14 } C = 11, no solution <Theorem> Exact cover  sum of subsets

8-7 sum of subsets  partition Partition problem Given a set of positive numbers A = { a1,a2,…,an }, determine if  a partition P,  ai = ai ip ip E.g. A = {1, 3, 8, 4, 10} partition : {1, 8, 4} and {3, 10} <Theorem> sum of subsets  partition

8-7 partition  bin packing Bin packing problem n items, each of size ci , ci > 0 bin capacity : C Determine if we can assign the items into k bins,  ci  C , 1jk. ibinj E.g. {c1,c2,c3,c4}={1, 3, 7, 4}, B=2, C=8 Solution: first bin {1,7} and second bin {3, 4} <Theorem> partition  bin packing.

8-7 VLSI discrete layout problem n rectangles, each with height hi (integer), width wi , an area A Determine if there is a placement of the n rectangles within the area A according to the rules : Boundaries of rectangles parallel to x axis or y axis. Corners of rectangles lie on integer points. No two rectangles overlap. Two rectangles are separated by at least a unit distance.

8-7 VLSI discrete layout problem A Successful Placement <Theorem> bin packing  VLSI discrete layout.

8-7 Max clique problem A maximal complete sub-graph of a graph G=(V,E) is a clique (Party, DPP). The max (maximum) clique problem is to determine the size of a largest clique in G. E.g. (Note that the definition of “Complete graph”) <Theorem> SAT  clique decision problem. maximal cliques : {a, b}, {a, c, d} {c, d, e, f} maximum clique : (largest)

8-7 Node cover decision problem A set S  V is a node cover for a graph G = (V, E) iff all edges in E are incident to at least one vertex in S.  S,  S  K ? E.g. S={2,4}, |S|=2, S={1,3,5}, |S|=3 <Theorem> clique decision problem  node cover decision problem.

8-7 SAT  directed Hamiltonian cycle ( in a directed graph ) A Hamiltonian cycle is a round trip path along n edges of G=(V,E) which visits every vertex once and returns to its starting vertex. E.g. Hamiltonian cycle : 1, 2, 8, 7, 6, 5, 4, 3, 1. length = |V| <Theorem> SAT  directed Hamiltonian cycle ( in a directed graph )

8-7 Directed Hamiltonian cycle  traveling salesperson decision problem. A tour of a directed graph G=(V, E) is a directed cycle that includes every vertex in V. The problem is to find a tour of minimum cost. <Theorem> Directed Hamiltonian cycle  traveling salesperson decision problem.