Correctness of Dijkstra s algorithm

Similar documents
1. Introduction Recap

Summer School on Introduction to Algorithms and Optimization Techniques July 4-12, 2017 Organized by ACMU, ISI and IEEE CEDA.

NP Completeness and Approximation Algorithms

NP Complete Problems. COMP 215 Lecture 20

NP-Complete Reductions 1

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

NP and Computational Intractability

Introduction to Complexity Theory

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

NP-Complete Problems. More reductions

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

Limitations of Algorithm Power

Design and Analysis of Algorithms

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

Polynomial-Time Reductions

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Discrete Optimization 2010 Lecture 10 P, N P, and N PCompleteness

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Essential facts about NP-completeness:

NP-Completeness. Until now we have been designing algorithms for specific problems

P P P NP-Hard: L is NP-hard if for all L NP, L L. Thus, if we could solve L in polynomial. Cook's Theorem and Reductions

Chapter 34: NP-Completeness

CS Fall 2011 P and NP Carola Wenk

Complexity, P and NP

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

Turing Machines and Time Complexity

SAT, Coloring, Hamiltonian Cycle, TSP

Intro to Theory of Computation

Spring Lecture 21 NP-Complete Problems

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

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

SAT, NP, NP-Completeness

Polynomial-time Reductions

NP-Complete Reductions 2

CSE 3500 Algorithms and Complexity Fall 2016 Lecture 25: November 29, 2016

Polynomial-time reductions. We have seen several reductions:

NP and NP Completeness

CS154, Lecture 13: P vs NP

CS21 Decidability and Tractability

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

Introduction. Pvs.NPExample

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

NP and Computational Intractability

NP-Complete problems

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

CS 5114: Theory of Algorithms

NP-completeness. Chapter 34. Sergey Bereg

NP-Completeness. Dr. B. S. Panda Professor, Department of Mathematics IIT Delhi, Hauz Khas, ND-16

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

Computational Intractability 2010/4/15. Lecture 2

VIII. NP-completeness

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

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

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

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

Computational Complexity. IE 496 Lecture 6. Dr. Ted Ralphs

ECS122A Handout on NP-Completeness March 12, 2018

Algorithms Design & Analysis. Approximation Algorithm

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

More on NP and Reductions

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

Computability and Complexity Theory: An Introduction

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

Theory of Computation Time Complexity

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

Computational Complexity

Lecture 4: NP and computational intractability

CS 5114: Theory of Algorithms. Tractable Problems. Tractable Problems (cont) Decision Problems. Clifford A. Shaffer. Spring 2014

NP-Completeness. Subhash Suri. May 15, 2018

NP-Completeness. Algorithmique Fall semester 2011/12

P, NP, NP-Complete, and NPhard

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

CSC 373: Algorithm Design and Analysis Lecture 15

NP-Completeness. NP-Completeness 1

Tractability. Some problems are intractable: as they grow large, we are unable to solve them in reasonable time What constitutes reasonable time?

DAA Unit IV Complexity Theory Overview

Complexity (Pre Lecture)

Agenda. What is a complexity class? What are the important complexity classes? How do you prove an algorithm is in a certain class

CS 6505, Complexity and Algorithms Week 7: NP Completeness

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

P,NP, NP-Hard and NP-Complete

CSE 548: (Design and) Analysis of Algorithms

The Class NP. NP is the problems that can be solved in polynomial time by a nondeterministic machine.

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

1.1 P, NP, and NP-complete

CS154, Lecture 13: P vs NP

Graduate Algorithms CS F-21 NP & Approximation Algorithms

Advanced Topics in Theoretical Computer Science

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

The Cook-Levin Theorem

Lecture Notes 4. Issued 8 March 2018

CSE 135: Introduction to Theory of Computation NP-completeness

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan August 30, Notes for Lecture 1

Instructor N.Sadagopan Scribe: P.Renjith

COMP Analysis of Algorithms & Data Structures

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

Search and Optimization Problems. CSE 548: (Design and) Analysis of Algorithms. Hard Problems: Where you find yourself...

Transcription:

Correctness of Dijkstra s algorithm Invariant: When vertex u is deleted from the priority queue, d[u] is the correct length of the shortest path from the source s to vertex u. Additionally, the value d[u] will never change after that iteration. Proof: It is true for the first iteration. Why? It is true for all subsequent iterations. Why? Because you always pick the vertex with the smallest d[] value. 12/2/08 COT 5407 1

Figure 14.38 Worst-case running times of various graph algorithms Shortest Path between a pair of vertices 12/2/08 COT 5407 2 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss 2002 Addison Wesley

Polynomial-time computations An algorithm has time complexity O(T(n)) if it runs in time at most ct(n) for every input of length n. An algorithm is a polynomial-time algorithm if its time complexity is O(p(n)), where p(n) is polynomial in n. 12/2/08 COT 5407 3

Polynomials If f(n) = polynomial function in n, then f(n) = O(n c ), for some fixed constant c If f(n) = exponential (super-polynomial) function in n, then f(n) = (n c ), for any constant c Composition of polynomial functions are also polynomial, i.e., f(g(n)) = polynomial if f() and g() are polynomial If an algorithm calls another polynomial-time subroutine a polynomial number of times, then the time complexity is polynomial. 12/2/08 COT 5407 4

The class P A problem is in P if there exists a polynomial-time algorithm that solves the problem. Examples of P DFS: Linear-time algorithm exists Sorting: O(n log n)-time algorithm exists Bubble Sort: Quadratic-time algorithm O(n 2 ) APSP: Cubic-time algorithm O(n 3 ) P is therefore a class of problems (not algorithms)! 12/2/08 COT 5407 5

The class NP A problem is in N P if there exists a non-deterministic polynomial-time algorithm that solves the problem. A problem is in N P if there exists a (deterministic) polynomial-time algorithm that verifies a solution to the problem. All problems in P are in N P 12/2/08 COT 5407 6

Input: TSP: Traveling Salesperson Problem Weighted graph, G Length bound, B Output: Is there a traveling salesperson tour in G of length at most B? Is TSP in NP? YES. Easy to verify a given solution. Is TSP in P? OPEN! One of the greatest unsolved problems of this century! Same as asking: Is P = N P? 12/2/08 COT 5407 7

So, what is NP-Complete? NP-Complete problems are the hardest problems in N P. We need to formalize the notion of hardest. 12/2/08 COT 5407 8

Problem: Terminology An abstract problem is a function (relation) from a set I of instances of the problem to a set S of solutions. p: I S An instance of a problem p is obtained by assigning values to the parameters of the abstract problem. Thus, describing the set of all instances (I.e., possible inputs) and the set of corresponding outputs defines a problem. Algorithm: An algorithm that solves problem p must give correct solutions to all instances of the problem. Polynomial-time algorithm: 12/2/08 COT 5407 9

Input Length: Terminology (Cont d) length of an encoding of an instance of the problem. Time and space complexities are written in terms of it. Worst-case time/space complexity of an algorithm Is the maximum time/space required by the algorithm on any input of length n. Worst-case time/space complexity of a problem UPPER BOUND: worst-case time complexity of best existing algorithm that solves the problem. LOWER BOUND: (provable) worst-case time complexity of best algorithm (need not exist) that could solve the problem. LOWER BOUND UPPER BOUND Complexity Class P : Set of all problems p for which polynomial-time algorithms exist 12/2/08 COT 5407 10

Terminology (Cont d) Decision Problems: These are problems for which the solution set is {yes, no} Example: Does a given graph have an odd cycle? Example: Does a given weighted graph have a TSP tour of length at most B? Complement of a decision problem: These are problems for which the solution is complemented. Example: Does a given graph NOT have an odd cycle? Example: Is every TSP tour of a given weighted graph of length greater than B? Optimization Problems: These are problems where one is maximizing (or minimizing) some objective function. Example: Given a weighted graph, find a MST. Example: Given a weighted graph, find an optimal TSP tour. Verification Algorithms: Given a problem instance i and a certificate s, is s a solution for instance i? 12/2/08 COT 5407 11

Complexity Class P : Terminology (Cont d) Set of all problems p for which polynomial-time algorithms exist. Complexity Class NP : Set of all problems p for which polynomial-time verification algorithms exist. Complexity Class co-np : Set of all problems p for which polynomial-time verification algorithms exist for their complements, i.e., their complements are in NP. 12/2/08 COT 5407 12

Terminology (Cont d) Reductions: p 1 p 2 A problem p 1 is reducible to p 2, if there exists an algorithm R that takes an instance i 1 of p 1 and outputs an instance i 2 of p 2, with the constraint that the solution for i 1 is YES if and only if the solution for i 2 is YES. Thus, R converts YES (NO) instances of p 1 to YES (NO) instances of p 2. Polynomial-time reductions: p p 1 P 2 Reductions that run in polynomial time. If p p 1 P 2, then If p 2 is easy, then so is p 1. p 2 P p 1 P If p 1 is hard, then so is p 2. p 1 P p 2 P 12/2/08 COT 5407 13

What are NP-Complete problems? These are the hardest problems in NP. A problem p is NP-Complete if there is a polynomial-time reduction from every problem in NP to p. p NP How to prove that a problem is NP-Complete? Cook s Theorem: [1972] The SAT problem is NP-Complete. Steve Cook, Richard Karp, Leonid Levin 12/2/08 COT 5407 14

NP-Complete vs NP-Hard A problem p is NP-Complete if there is a polynomial-time reduction from every problem in NP to p. p NP A problem p is NP-Hard if there is a polynomial-time reduction from every problem in NP to p. 12/2/08 COT 5407 15

The SAT Problem: an example Consider the boolean expression: C = (a b c) ( a d e) (a d c) Is C satisfiable? Does there exist a True/False assignments to the boolean variables a, b, c, d, e, such that C is True? Set a = True and d = True. The others can be set arbitrarily, and C will be true. If C has 40,000 variables and 4 million clauses, then it becomes hard to test this. If there are n boolean variables, then there are 2 n different truth value assignments. However, a solution can be quickly verified! 12/2/08 COT 5407 16

The SAT (Satisfiability) Problem Input: Boolean expression C in Conjunctive normal form (CNF) in n variables and m clauses. Question: Is C satisfiable? Let C = C 1 C 2 C m Where each C i = i i i ( y1 y2 L yk ) And each {x y i i 1, x 1, x 2, x 2,, x n, x n } j We want to know if there exists a truth assignment to all the variables in the boolean expression C that makes it true. Steve Cook showed that the problem of deciding whether a nondeterministic Turing machine T accepts an input w or not can be written as a boolean expression C T for a SAT problem. The boolean expression will have length bounded by a polynomial in the size of T and w. How to now prove Cook s theorem? Is SAT in NP? Can every problem in N P be poly. reduced to it? 12/2/08 COT 5407 17

The problem classes and their relationships co-np P N P NP-C 12/2/08 COT 5407 18

3SAT More NP-Complete problems Input: Boolean expression C in Conjunctive normal form (CNF) in n variables and m clauses. Each clause has at most three literals. Question: Is C satisfiable? Let C = C 1 C 2 C m Where each C i = i y j ( i y i y i ) y1 2 3 And each {x 1, x 1, x 2, x 2,, x n, x n } We want to know if there exists a truth assignment to all the variables in the boolean expression C that makes it true. 3SAT is NP-Complete. 12/2/08 COT 5407 19

2SAT More NP-Complete problems? Input: Boolean expression C in Conjunctive normal form (CNF) in n variables and m clauses. Each clause has at most three literals. Question: Is C satisfiable? Let C = C 1 C 2 C m Where each C i = i y j ( i y i ) y 1 2 And each {x 1, x 1, x 2, x 2,, x n, x n } We want to know if there exists a truth assignment to all the variables in the boolean expression C that makes it true. 2SAT is in P. 12/2/08 COT 5407 20

3SAT is in NP. 3SAT is NP-Complete SAT can be reduced in polynomial time to 3SAT. This implies that every problem in N P can be reduced in polynomial time to 3SAT. Therefore, 3SAT is NP-Complete. So, we have to design an algorithm such that: Input: an instance C of SAT Output: an instance C of 3SAT such that satisfiability is retained. In other words, C is satisfiable if and only if C is satisfiable. 12/2/08 COT 5407 21

3SAT is NP-Complete Let C be an instance of SAT with clauses C 1, C 2,, C m Let C i be a disjunction of k > 3 literals. C i = y 1 y 2 y k Rewrite C i as follows: C i = (y 1 y 2 z 1 ) ( z 1 y 3 z 2 ) ( z 2 y 4 z 3 ) ( z k-3 y k-1 y k ) Claim: C i is satisfiable if and only if C i is satisfiable. 12/2/08 COT 5407 22

2SAT is in P If there is only one literal in a clause, it must be set to true. If there are two literals in some clause, and if one of them is set to false, then the other must be set to true. Using these constraints, it is possible to check if there is some inconsistency. How? Homework problem! 12/2/08 COT 5407 23

The CLIQUE Problem A clique is a completely connected subgraph. CLIQUE Input: Graph G(V,E) and integer k Question: Does G have a clique of size k? 12/2/08 COT 5407 24

CLIQUE is NP-Complete CLIQUE is in NP. Reduce 3SAT to CLIQUE in polynomial time. F = (x 1 x 2 x 3 ) ( x 1 x 3 x 4 ) (x 2 x 3 x 4 ) ( x 1 x 2 x 3 ) x 1 x 2 x 3 F is satisfiable if and only if G has a clique of size k where k is the number of clauses in F. x 1 x3 x 4 12/2/08 COT 5407 25

Vertex Cover A vertex cover is a set of vertices that covers all the edges of the graph. Examples 12/2/08 COT 5407 26

Vertex Cover (VC) Input: Graph G, integer k Question: Does G contain a vertex cover of size k? VC is in NP. polynomial-time reduction from CLIQUE to VC. Thus VC is NP-Complete. G G V V Claim: G has a clique of size k if and only if G has a VC of size k = n k 12/2/08 COT 5407 27

Hamiltonian Cycle Problem (HCP) Input: Graph G Question: Does G contain a hamiltonian cycle? HCP is in NP. There exists a polynomial-time reduction from 3SAT to HCP. Thus HCP is NP-Complete. Notes/animations by Yi Ge! 12/2/08 COT 5407 28