algorithms_exercises
algorithms_exercises copied to clipboard
Solution not optimal for "Bubbles"
I've found a case where the solution to the "Bubbles" exercice is not the smallest possible number of pairs as requested :
List<Contact> contacts = Collections.unmodifiableList(Arrays.asList(
new Contact("C", "D"),
new Contact("A", "B"),
new Contact("B", "C"),
new Contact("D", "E"),
new Contact("E", "F")
));
List<ForbiddenRelation> fr = Bubbles.cleanBubbles(contacts, 1);
assertEquals(fr.size(), 2);
It corresponds to this graph : A-B-C-D-E-F. To ensure they all have a bubble size of 1, the best solution is to remove B-C and D-E, however the solution returns C-D, A-B and D-E.