CS521 \ Notes for the Final Exam

Similar documents
COMP 251 Winter 2017 Online quizzes with answers

END-TERM EXAMINATION

Reference Sheet for CO142.2 Discrete Mathematics II

Lecture Summary CSC 263H. August 5, 2016

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

CSci 231 Final Review

( ) n 3. n 2 ( ) D. Ο

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Chapter 9 Graph Algorithms

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

( D. Θ n. ( ) f n ( ) D. Ο%

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

22 Elementary Graph Algorithms. There are two standard ways to represent a

Algorithm Design (8) Graph Algorithms 1/2

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Chapter 9 Graph Algorithms

n 2 ( ) ( ) + n is in Θ n logn

Chapter 9 Graph Algorithms

Lecture 6 Basic Graph Algorithms

Review of course COMP-251B winter 2010

( ) 1 B. 1. Suppose f x

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

) $ f ( n) " %( g( n)

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Design and Analysis of Algorithms - - Assessment

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Introduction to Algorithms Third Edition

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

Course Review for Finals. Cpt S 223 Fall 2008

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

Lecture 3: Graphs and flows

CS102 Binary Search Trees

Data Structures Brett Bernstein

Solutions to relevant spring 2000 exam problems

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Your favorite blog : (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

Shortest path problems

Minimum Spanning Trees Ch 23 Traversing graphs

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

DESIGN AND ANALYSIS OF ALGORITHMS

FINAL EXAM SOLUTIONS

22 Elementary Graph Algorithms. There are two standard ways to represent a

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

ECE250: Algorithms and Data Structures Final Review Course

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

Module 5 Graph Algorithms

Lecture 6: Analysis of Algorithms (CS )

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

looking ahead to see the optimum

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Analysis of Algorithms

Graph and Digraph Glossary

Minimum Spanning Trees

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Index. stack-based, 400 A* algorithm, 325

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

NP-Completeness. Algorithms

Solutions to Exam Data structures (X and NV)

Lecture: Analysis of Algorithms (CS )

Shortest Path Problem

Copyright 2000, Kevin Wayne 1

CS 6783 (Applied Algorithms) Lecture 5

Contents. 1 Introduction. 2 Searching and Traversal Techniques. Preface... (vii) Acknowledgements... (ix)

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Konigsberg Bridge Problem

W4231: Analysis of Algorithms

Graph Algorithms (part 3 of CSC 282),

CISC 320 Midterm Exam

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.



L.J. Institute of Engineering & Technology Semester: VIII (2016)

Virtual University of Pakistan

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Greedy Algorithms. Textbook reading. Chapter 4 Chapter 5. CSci 3110 Greedy Algorithms 1/63

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Algorithms (IX) Guoqiang Li. School of Software, Shanghai Jiao Tong University

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

Transcription:

CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) Some hierarchies: ( is o, is ) (non-negative constant) (some constant) ( ) Divide and Conquer recurrences: Break a problem into sub-problems, solve sub problems and merge solutions. Hanoi-tower: Solving Recurrences: 1. Substitution method: Have a guess for Assume correctness for all Substitute -terms in the recurrence by the assumption, using constants, and derive upper / lower bounds (or both). Example:. / To get an upper bound: develop and derive an expression that is exactly.

CS521 \ Notes for final exam 2 Ariel Stolerman 2. Recursion tree: Build a tree from the levels in the substitution: Level 0: Level 1: elements, each costs Level : elements, each costs Last level: elements, each costs, -. /, -, - 3. The Master Theorem: For, function over non-negative integers and the recurrence: 1. 2. 3. and ( ) Notes for MT: The addition/subtraction denotes polynomial difference in running time between and. Cases (1) and (2) derive for some relation between. Simplified Master Theorem: For : 1. 2. 3. Some recurrences: Binary search: Linear search: (MT case 1) (tree) (MT case 3) (bounds) (tree) (bounds) (substitution) (bounds) (bounds)

CS521 \ Notes for final exam 3 Ariel Stolerman ( ) (tree) Useful math: Harmonic series: when ( ) Sorting algorithms: Insertion Sort: Each element is pushed as far as possible to the left (sorted) part of the array. Running time: worst-case (when sorted in reverse), best-case (when already sorted). Sorts in-place, space complexity:. Merge-sort: Divide the sequence into two sequences, apply the algorithm recursively and merge solutions. Quick Sort: Partition: linear procedure that partitions in-place around, - s.t.: and returns the index of the pivot. Preferable over merge-sort, as it sorts in-place. General recurrence: Worst-case: array already sorted, partition at the beginning: For any -proportional division we get : ( ) For we get a balanced tree. Expected running time:, -, - ( ) ( ) Heap: Left filled structure that satisfies partial order (node its children, no particular relation between children). For node : left child at, right at, parent Height is : the cost of insertion, extract-max, delete. Every level of height has nodes. Operations: Insert: put node at the end and heapify up (switch with parent until parent or is root. Remove-max: remove root and put last node of the heap in its place. Heapify it down, each level switching with the greater child of the two until satisfies heap properties. Build-heap: for node down to, heapify down. Amortized analysis each level but lowest will be visited at most. Total:. The sum part is total:.

CS521 \ Notes for final exam 4 Ariel Stolerman Heap-sort: Build a heap and then run times: Swap the max with the last element, decrease heap size by 1 and heapify the new root down. Result: the array is sorted. Running time:, sorts in-place. Selection problems: The Select algorithm for finding the th o.s.: : Divide into groups of size 5. Find the median for each group and store in. Call to find median. Let : If return. If return If return Running time:. Select s recurrence:. /. / (proof by induction for upper bound substitution method). A general recurrence (for constants other than 5): Calculate the minimal number of elements we know for sure are greater than, the medians median. Then we take the complement of that number: For any constant (the default in the selection algorithm is ), where we divide into sets, the number of elements that are definitely greater than : ( ). / The recursion over the complement is:. / (. /) Then show by substitution that it is bounded / not bounded from above by (would be bounded for any ). Note that we get if it is bounded above, and Binary Search Trees: otherwise. Trees that satisfy: left(x) key(x) right(x) Unbalanced trees: all operations cost, where is the height of the tree, between and. Successor of : Left most leaf of s right subtree. If doesn t have one, then the lowest ancestor with left subtree. Sub-tree rooted at has internal nodes.

CS521 \ Notes for final exam 5 Ariel Stolerman Deletion: Case 1,2: No left/right child. Put sole child instead. Case 3: Successor is right child. Put successor instead. Case 4: Successor is not direct right child. Swap successor with its sole (right) child, and then swap deleted node with successor. Red-Black Trees: Every node is either red or black Root and leafs (NIL) are black If a node is red, its children will be black All black paths have same # of blacks (black height) Height: maximum Operations: Insertion: Create new red node with 2 black leafs and put in place. Corrections (a inserted): Case 1: a s uncle is red: Color father and uncle black, and grandfather red. Problem moved up 2 levels to grandfather. Case 2: a s uncle is black, a is a right child: Rotate left around father and continue to case 3. Case 3: a s uncle is black, a is left child: Rotate right around grandfather, switch colors between father and new sibling. Deletion: Delete as for any BST. If successor was black, leave behind extra black and correct: Case 1: a s sibling is red: Rotate left around father, switch colors between father and grandfather and continue with circled sub-tree to other case. Case 2: a s sibling and nephews are black: Take blacks from a and c and move problem up. Case 3: a s sibling is black with left red and right black: Rotate right around sibling, switch colors between new sibling and old sibling and continue to case 4. Case 4: a s sibling is black with right red: Rotate left around father, color grandfather with father s color, color father with extra black, color uncle black.

CS521 \ Notes for final exam 6 Ariel Stolerman Graph Theory: Let Some definitions: For the degree is the number of edges connected to.. : a complete graph with edges. Connected component: a sub-graph in which there s a path between any 2 nodes. If the graph is directed, it is called strongly connected component. Shortest path: the path with smallest sum of edge-weights in it. Bipartite graph: if such that : or vice-versa. Theorem: a graph is bipartite it doesn t have an odd cycle. Tree: an acyclic connected graph. For a tree with nodes:. o o Any undirected tree is a bipartite graph (doesn t contain odd, or any, cycles). Rooted-tree: directed tree; Forest: a set of trees DAG: directed acyclic graph graph with no cycles forward connected. Maximum degree: dense. Minimum Spanning Trees (MSTs): An MST is a tree with minimal sum of edge-weights. There could be more than one spanning tree in a graph. Greedy MST: Sort the set of edges by weights. Takes. Go over every edge in weight-ascending order, and if it doesn t create a cycle, add it to the MST. Use union-set: Disjoint union sets: ( * +), * + where: The data structure will support the following: Make-set: create a set containing : * +. Cost:. Find-set: returns the set to which belongs. Cost:. Union: creates a set which is the union of the set containing and the set containing. Cost: ( * +) the cost of changing the pointers of all elements in the smaller set to the root of the larger set. Every set is represented by some canonical element such that. Back to greedy MST: We start with ( {* + * +}) and for every we check if (i.e. creates a cycle). Number of find operations (w.c.): (2 ends of every edge), each. Total cost:. Number of union operations: for every, if we point to the root of. Every pointer change of, it becomes belonged to a set at least twice the size of the set it was previously belonged to. Therefore the maximum changes of pointer per node is. Total cost therefore is:. That s Kruskal s algorithm.

CS521 \ Notes for final exam 7 Ariel Stolerman Kruskal s algorithm for finding MST (greedy): 1. Start with 2. For every do 3. Sort edges in 4. For each in increasing order: 5. If : a. *+ b. 6. Return Notes: Doesn t work for negative weights. Running time: make-set takes ; the sorting takes ; find-set and union take a total of. The total running time: ( ). Prim s Algorithm for finding MST: Safe cut: A division of into two sets of nodes such that no edge of the current iteration of the MST crosses the cut. The edge that would be safe for the MST would be the lightest edge that crosses the cut. Prim s algorithm starts with an arbitrary node, and using a priority queue it extracts the minimum weight node, adds it to (the MST in construction) and updates the keys of, -. Prim-MST: 1. Create priority queue (initialized to ). 2. For each :, - 3., - 4. 5. While : 6. 7. For each, -: 8. If and, -: 9. 10. ( ) update s key Running time: The priority queue can be implemented using a binary heap. Steps 1-4 take time. extract-min operations will take in total. Worst case there will be decrease-keys each, thus The total running time is ( ) (with better constant than Kruskal s).

CS521 \ Notes for final exam 8 Ariel Stolerman Graph Traversal Algorithms: Breadth First Search (BFS): Given calculates the shortest paths from to any Frontier: the current active layer of search. At each iteration it is constructed of nodes that are at most 1 level apart. Node coloring: o White: pre visited nodes. o Gray: visited node, still haven t finished exploring node in the frontier. o Black: done exploring this node and edges connected to it. For all :, - is the parent node of from on the shortest path from ;, - is the distance of that path. Inverting pointers gives the BFS tree. Edges: o Tree edges: the edges of the BFS tree (inverted pointers). o Cross/back edges: all other edges. If a back edge is between 2 nodes with different -value parity, it creates an odd cycle ( the graph is not bipartite). Uses a queue for handling the nodes. Use example: calculate the diameter of a tree run BFS on some starting node, and get the farthest node from it, say. Then run BFS on and get the maximum distant from are the two diameter edges. The algorithm: Initialize : white color,, -,, -. Initialize source:, -, -, Queue: * +. While is not empty, extract the top of the queue, and for any undiscovered (white) neighbor, -: o Color it gray and add to o Set, -, -, - When done with, set its color to black. Running time: The initialization takes. Every node is colored 3 times (white, gray and black), and every edge is looked at once from each end. Total running time:. Depth First Search (DFS): It is also. For every node we hold: Color (as before) and parent, -., - is the time of discovery,, - is the time the processing is finished. The algorithm: Initialize every to white color and, -. Initialize the beginning time to 0. For each, if is white run the recursive DFS-visit method: o Color gray, increase time by 1 and update, - to the new time. o Run DFS-visit recursively on every white, - o Color black, increase time by 1 and update, - to the new time.

CS521 \ Notes for final exam 9 Ariel Stolerman DFS creates a forest of DFS trees. Types of edges: Tree edges: edges that are part of a DFS tree. Back edges: where is an ancestor of in the tree. Forward edges: where is a proper descendant of. Cross edges: where are not ancestors / descendants of one another (could cross trees in the forest). Uses: Determine if the graph contains cycles: given a directed graph, it contains cycles the DFS forest has a back edge. This is found easily: is a back edge, -, - Topological Sort of a DAG: A linear ordering of such that, appears before. The algorithm is similar to DFS: Initialize the color of every to white, and an empty linked list. For every that is white run the recursive method Top-visit: o Color gray and for each white, - run Top-visit. o Append to the front of. Strongly connected components: To find, the directed graph of the strongly connected components, the algorithm is: Call to compute, - for all. Compute the graph where every edge is reversed. Call over the nodes by, - decreasing order. Each set of nodes of every tree in the forest calculated for is a strongly connected components, and the is a DAG. Running time:. Shortest Paths: A minimal path ( ) Notations: o ( ) the weight of the shortest path between and. o such that Metric: MST is insufficient to calculate shortest path (consider where except. but using the MST we will get ). There could be more than 1 SP. Values used in algorithms for finding SPs: o, -: the current known shortest distance of from. o, -: the parent of on the currently known SP from. Properties: Sub-path of an SP is also an SP: If us an SP, then is also an SP. 2 SPs don t necessarily combine into an SP (triangular inequality).

CS521 \ Notes for final exam 10 Ariel Stolerman Relax operation:, -, -, -, -, - Initial values:, -, for all others, -., -, for all others, -. Properties: For every :, -. If there s no path from to then, -. If, - before relaxation, it stays that way after relaxation. Single Source Shortest Paths: Bellman-Ford: 1. Initialize for all, - and, - 2. Do the following times: 3. For every edge : 4. Relax 5. For every edge : 6. If, -, - then output: No solution! (or: there s a negative cycle). Claim: After iterations of relaxing all edges, -values are, and if not there s a negative cycle in the graph (that derives infinite improvement during relax). Every path is at most of size, thus requires at most relaxation rounds of the edges on its path. Therefore if after rounds the path still improves, there must be a negative cycle on it. Running time:. Dijkstra s Algorithm: Assumes all weights are non-negative. 1. Initialize -values like for BF. 2. Initialize and a priority queue 3. While : 4. 5. * + 6. For every, - 7. Relax Properties: Like Prim s MST, only here we look at the total weight of the path and not just of one edge. Running time: extract-min operations cost each, and there are a total relaxations each. Total: ( ). Correctness: if is at the top of the queue then, - (for every, - ). Proof by contradiction: if is the first node such that, - on extraction, then there s such that. When was added to,, - was ( is the first with ), and was relaxed, -. Also since appears on the SP

CS521 \ Notes for final exam 11 Ariel Stolerman from to before then, -, -. But since is chosen by extract-min then, -, -, -, -. DAG SSSPs: Initialize all -values to except. Use DFS to apply topological-order. For each taken in topological order: o For each, - Properties: Running time: ( ). Because there are no cycles, once we pass a node, its -value cannot be changed anymore. All Pairs Shortest Paths: Basic APSS: Assumption: no negative cycles, thus every shortest path has edges. Define a weight matrix: { Define as the shortest path between and with at most edges. For : { Recursively define: { } We run the algorithm times to achieve the SP matrix. Like matrix multiplication: (i.e. instead of we calculate { }). Running time: o One iteration is, for iterations the total is. ( o Improvement: take advantage of associativity, do calculations: ) (. For any, ) doesn t change anymore. Total running time:. Doing an extra round can detect negative cycles, like in BF. Floyd-Warshall: Here at every iteration the path is allowed to use more and more nodes (enumerated between 1 to ): * + * + * +. Not just how many nodes, but which nodes can be used. Calculations of o (no intermediate nodes are allowed between ). * + : { } o o * + * + { * + * + * + } { * + * + * + } ( Running time: each calculation of ) does operations per entry, total of. Total running time:. Cannot speed-up as before (2 instances of are using the same set of nodes they are the same).

CS521 \ Notes for final exam 12 Ariel Stolerman Transitive Closure: Given a graph, the graph is the transitive closure of and is defined: * +. Computing TC by using modified FW, updating -values: Initialization: Iteration computation over all : { ( ) The running time is. This is like the FW algorithm, substituting by and by. Dynamic Programming: Bottom-up optimization technique: solution is based on solutions to sub-problems. Sub-problems are overlapping. Longest Common Subsequences (LCS): Given a sequence we say is a subsequence of if there are indices such that and. Given two sequences and we want to find where and, and is maximal. Denote the prefix of of size. Denote the length of the LCS of : { { } Filling a matrix of size. Cases: o First case: initialization of first row and first column (any LCS with an empty string is of length 0). o Second case: the last elements of match, so the length is. o Third case: the last elements don t match, so take the maximum out of. The total running time is:. The result is. Reductions and NP-Completeness: Definitions: Problem: any problem is defined by a language over an alphabet (usually * +)., where is the set of all possible strings over alphabet. For any input, the decision problem is: is Polynomial-time languages: we say a language is poly-time decidable, i.e., if there s a poly-time algorithm that decides for any * + whether. Formally: where is the input length and is some constant. The computational model: random access memory and a Turing machine. Decision problem: check if an input is in. Optimization problem: find minimum / maximum / etc. Verification problem: given an input * + and a certificate/witness with length polynomial to the size of ( for some constant ), verifies whether using.

CS521 \ Notes for final exam 13 Ariel Stolerman Class NP: class of polynomial-time verifiable languages. Alternatively: problems that can be poly-time decided given an access to a non-deterministic Turing machine (i.e. polynomial access to an oracle). To show give a verifying algorithm and show it is correct and polynomial in the input size. Class conp:, where * * + +. Reduction: let be two languages. We say is poly-reducible to, denoted iff there exists a polynomial-time reduction such that. If : o is at least as hard as otherwise we can reduce to and solve ( ) more easily than solving. o If is easy then is easy. To prove NP-hardness of take some problem and show:. E.g.:. Reducibility is transitive, and:. Class NP-Hard: class of all problems such that. Class NP-Complete: Problems: Problem Properties CNF-SAT Definition All formulas over variables * + in conjunctive normal form: where ( * + that have a satisfying assignment for. NP Given an assignment, assign it and check that all clauses are satisfied. polynomial NPC Cook s theorem Clique Definition * + NP The witness: the set of vertices * + that form a clique of size. Verification is polynomial: check that all pairs of the set are connected ( ). NPC : Create a graph : Create a node for each literal in every clause in. For every 2 nodes that are not in the same clause or complements of one another, create an edge. is the number of clauses. If then there s a clique of size in : the one constructed from the vertices that represent one literal that satisfies a clause for all clauses. Same the other way around. IS Definition * + (Independent NP The witness: a set of size. Verify that for any pair :. Set) NPC : For an input for Clique create the input for IS, where. VC (Vertex Cover) contains a clique of size contains an IS of size. Definition * + NP The witness: a set of size. Verify that NPC : For an input for IS create for VC. 1-CNF-SAT Definition All satisfyable CNF formulas with 1 literals per clause: ( ) P Assign all variables a satisfying assignment. If encountered a conflict ( ), the input is not satisfyable. 2-CNF-SAT Definition Clauses are of the form P is satisfyable iff ( ) ( ). Build a graph where: There s a node for every literal. There s a directed edge for every We can say is NOT satisfyable the graph contains a cycle with some variable and its complement. To do that we build and check every SCC in it. To find a satisfying assignment: apply topological sort (it s a DAG), satisfy the last component and go backwards, satisfying the s.

CS521 \ Notes for final exam 14 Ariel Stolerman 3-CNF-SAT Definition ( ), where the clauses where * + All such that are satisfyable. NP Given an assignment, assign it and verify the formula is satisfied. NPC : Input: ( ), where Output:, where To create it we use the mapping that maps clauses to as follows: ( ) ( ) ( ), where are new variables. : If is satisfyable, w.l.o.g.. Then we can assign to satisfy all other clauses (the last clause is satisfied by so it s ok that ). : If is not satisfyable, for the first clause must be, and that derives that all, but then in the last clause all literals are false, thus is not satisfyable. This is a polynomial time reduction. 2COL Definition All graphs that their nodes can be colored in 2 colors such that K-COL P Check if a graph is bipartite (for instance using BFS). If yes, every level can be colored in one of two colors. Definition where is an undirected graph and * + is a set of colors and there exists a map such that NP The witness: a coloring map. Verify by checking the colors of every. NPC : For an input we create a graph and a set of colors. The graph : Create 3 connected sentinel nodes to enforce 3 colors are required. Create nodes for all Create edges between each and connect them all to the BLUE sentinel. That way all are colored either red (false) or green (true). For every clause we create a gadget in the graph as follows. For an even clause, say : x y Green Has satisfying assignment Doesn t have satisfying assignment x y x y Problem! For an odd clause, say : x y z Red