Given a list of pairs ((x_{1},y_{1}),(x_{2},y_{2}),…,(x_{n},y_{n})) of non-empty words x_{1},x_{2},…,x_{n},y_{1},y_{2},…,y_{n} find a non-empty list of indices i_{1},i_{2},…,i_{m} so that the concatination of x_{i1}.x_{i2}….x_{im} equals y_{i1}.y_{i2}….y_{im}.

The word pairs (x_{i},y_{i}) of a problem case can well be imagined as dominoes, where on one half x_{i} and on the other half y_{i} are written. There are n types of dominoes and any number of dominoes are available.

The correspondence problem can now be understood as follows: Is there a sequence of dominoes so that the words on the upper half of the dominoes (read from left to right) produce the same word as the words (read from left to right) from the lower half of the merged dominoes?

max. depth:

JavaScript implementation of the PCP algorithm below. In some cases, in particular with big instances and large values for depth, this might crash the site.

Example two illustrates how even for small instances the solution might only be found with a huge amount of indices.

The Algorithm, given a list of pairs (n pairs) and a limit k, finds a list of indices that are a solution to the PVP problem.

```
solutions = {}
(1)FOR i = 1...n:
IF xi = yi:
return (i)
IF length(xi) < length(yi):
IF yi begins with xi:
solutions = solutions + (i)
IF length(yi) < length(xi):
IF xi begins with yi:
solutions = solutions + (i)
(2)FOR i = 1...k:
new_solutions = {}
(2.1) FOR solution in solutions:
(2.2) FOR j = 1...n:
(2.2.1) IF adding pair j would not break the solution:
new_solutions = new_solutions + (solution, j)
(2.3) IF new_solutions = {}:
return {}
(2.4) FOR solution in new_solutions:
IF length of concatination of all xi equals length of concatination of all yi:
return solution
solutions = new_solutions
```

In step (1) a solutions list is created. Solutions are checked for validity in (2.4). There are k iterations (2). For each iteration each solution in the set of possible solutions (2.1) is checked if there can be added one of each of the possible pairs of (x_{j},y_{j}) (2.2). A pair can be added if the concatination of all the x and y in the solution concatinated with x_{j} and y_{j}, like in (1), the bigger concatination begins with the smaller of both concatinations. If no new possible solutions are found the search can be aborted in (2.3).

Inpired by https://webdocs.cs.ualberta.ca/~games/PCP/thesis/pcp.pdf (Chapter 2.2 An example of solving PCP instances).