Please help me out with an algorithm for the following problem -
Given a collection of facts, we would like to get rid of as much redundancy as possible. The facts involved in this problem are members of a transitive relation between uppercase letters. So each fact is a pair of uppercase letters such as AB meaning that A is related to B. A letter may or may not be related to itself, but transitivity holds: if A is related to B and B is related to C then we can infer that A is related to C. Create a class FactCount that contains a method minFacts that is given a String[] known and that returns the size of the smallest set of facts that will allow us to infer everything (and only those things) that can be inferred from the facts contained in known.
Each element of known will contain 1 or more facts separated by a single space. The smallest set of facts may contain facts that can be inferred from known but that are not contained in it.
For example:
{"AB AC CA AA BC", "AD"}
Returns: 4
AB, CA, BC, and AD allow us to infer both AA (AB, BC, CA gives AA by transitivity) and AC (AB, BC gives AC by transitivity), and there is no smaller subset that allows us to infer all the known facts.
P.S - Its NOT homework. Just a problem I found online and have been unable to solve for hours...