Find the best path between two strings
This is technically not in scope for this site, but we're friendly people here :), and your question is relatively well-formed. 

It sounds like what you have is a directed graph where the strings are your vertices, and your two tables are storing the "forward edges" (a -> b) and the backward edges (a &lt;- b). The question you're asking is whether there's a way to go from one vertex in this graph to another. 

The answer is to do a graph traversal (breadth-first or depth-first) on this graph. Any basic textbook on algorithms (like this one) should help.