Posts

Showing posts from January 17, 2019

Brute force least adjacent swap anagram transform in Java

Image
0 $begingroup$ In this post, we are given two anagrams, and we wish to compute a shortest sequence of adjacent character swaps. For example, DBAC -> BDAC -> BADC -> ABDC -> ABCD , four adjacent swaps. I tried to split the algorithm into logical parts in order to facilitate better readability and would like to hear comments regarding it. Here is my code: LeastAdjacentSwapAnagramTransformAlgorithm.java package net.coderodde.fun; import java.util.HashMap; import java.util.List; import java.util.Map; /** * This interface defines the API and basic infrastructure for algorithms * returning a shortest list of adjacent swaps required to transform one anagram * into another. * * @author Rodion "rodde" Efremov * @version 1.6 (Jan 5, 2019) */ public interface LeastAdjacentSwapA