Content deleted Content added
m →Example: {{mathcal}} class="wikitable" |
→Example: Fixed typo Tags: Mobile edit Mobile web edit |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1:
{{Short description|Algorithm for exact cover problem}}
'''Algorithm X''' is an [[algorithm]] for solving the [[exact cover]] problem. It is a straightforward [[Recursion (computer science)|recursive]], [[Nondeterministic algorithm|nondeterministic]], [[depth-first]], [[backtracking]] algorithm used by [[Donald Knuth]] to demonstrate an efficient implementation called DLX, which uses the [[dancing links]] technique.<ref name="knuth">{{cite arXiv | author = Knuth, Donald | author-link = Donald Knuth | title = Dancing links | year = 2000 | eprint = cs/0011047 }}</ref><ref>{{Cite journal |last=Banerjee |first=Bikramjit |last2=Kraemer |first2=Landon |last3=Lyle |first3=Jeremy |date=2010-07-04 |title=Multi-Agent Plan Recognition: Formalization and Algorithms |url=https://ojs.aaai.org/index.php/AAAI/article/view/7746 |journal=Proceedings of the AAAI Conference on Artificial Intelligence |volume=24 |issue=1 |pages=1059–1064 |doi=10.1609/aaai.v24i1.7746 |issn=2374-3468|doi-access=free }}</ref>
==Algorithm==
The exact cover problem is represented in Algorithm X by
Algorithm X
# If the matrix ''A'' has no columns, the current partial solution is a valid solution; terminate successfully.
# Otherwise choose a column ''c'' ([[deterministic algorithm|deterministically]]).
Line 16:
#: delete column ''j'' from matrix ''A''.
# Repeat this algorithm recursively on the reduced matrix ''A''.
}}▼
The nondeterministic choice of ''r'' means that the algorithm recurses over independent subalgorithms; each subalgorithm inherits the current matrix ''A'', but reduces it with respect to a different row ''r''.
Line 302:
:: Step 1—The matrix is not empty, so the algorithm proceeds.
:: Step 2—The lowest number of 1s in any column is one. Column 2 is the first column with one 1 and thus is selected (deterministically)
:::{| class="wikitable"
! !! <span style="color:red">2</span> !! 7
|-
! ''F''
| <span style="color:red;font-weight:bold">1</span> || 1
:: Row ''F'' has a 1 in column 2 and thus is selected (nondeterministically).
Line 328 ⟶ 335:
! <span style="color:blue">''F''</span>
| <span style="color:red;font-weight:bold">1</span> || <span style="color:red;font-weight:bold">1</span>
|}
::: No rows and no columns remain:
::::{| class="wikitable"
!
|}
::: Step 1—The matrix is empty, thus this branch of the algorithm terminates successfully.
::: As rows ''B'', ''D'', and ''F''
::::{| class="wikitable"
Line 360 ⟶ 373:
==Implementations==
==See also==
|