Papadimitriou's 2SAT Algorithm: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 9: Line 9:


=Overview=
=Overview=
Generally, local search heuristics are not guaranteed to run in polynomial time. The randomized local search algorithm for the 2SAT problem is one of the rare cases when we can prove it is guaranteed to converge with the correct answer quickly.
The algorithm performs a randomized [[Local Search|local search]]. Generally, local search heuristics are not guaranteed to run in polynomial time. The randomized local search algorithm for the 2SAT problem is one of the rare cases when we can prove it is guaranteed to converge with the correct answer quickly.
 
=Algorithm=
=Algorithm=
<font size=-1>
<font size=-1>
Line 16: Line 17:
   Repeat 2n<sup>2</sup> times:
   Repeat 2n<sup>2</sup> times:
       If current assignment satisfies all clauses, halt and report.
       If current assignment satisfies all clauses, halt and report.
       Else pick arbitrary unsatisfied clause and flip the value of one of its variables <font color=teal># choose between the tow uniformly at random.</font>
       Else pick arbitrary unsatisfied clause and flip the value of one of its variables <font color=teal># choose between the two uniformly at random.</font>
  Report "unsatisfiable".
  Report "unsatisfiable".
</font>
</font>
==Playground Implementation==
==Playground Implementation==
{{External|https://github.com/ovidiuf/playground/blob/master/learning/stanford-algorithms-specialization/19-2SAT/src/main/java/playground/stanford/twosat/TwoSATInstance.java}}


=Running Time=
=Running Time=
Runs in polynomial time.
Runs in polynomial time.

Latest revision as of 15:11, 30 November 2021

External

Internal

Overview

The algorithm performs a randomized local search. Generally, local search heuristics are not guaranteed to run in polynomial time. The randomized local search algorithm for the 2SAT problem is one of the rare cases when we can prove it is guaranteed to converge with the correct answer quickly.

Algorithm

Repeat log2n times:
  Choose random initial assignment
  Repeat 2n2 times:
     If current assignment satisfies all clauses, halt and report.
     Else pick arbitrary unsatisfied clause and flip the value of one of its variables # choose between the two uniformly at random.
Report "unsatisfiable".

Playground Implementation

https://github.com/ovidiuf/playground/blob/master/learning/stanford-algorithms-specialization/19-2SAT/src/main/java/playground/stanford/twosat/TwoSATInstance.java

Running Time

Runs in polynomial time.